闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.2 KiB

  1. require 'rails_helper'
  2. RSpec.describe StatusPin, type: :model do
  3. describe 'validations' do
  4. it 'allows pins of own statuses' do
  5. account = Fabricate(:account)
  6. status = Fabricate(:status, account: account)
  7. expect(StatusPin.new(account: account, status: status).save).to be true
  8. end
  9. it 'does not allow pins of statuses by someone else' do
  10. account = Fabricate(:account)
  11. status = Fabricate(:status)
  12. expect(StatusPin.new(account: account, status: status).save).to be false
  13. end
  14. it 'does not allow pins of reblogs' do
  15. account = Fabricate(:account)
  16. status = Fabricate(:status, account: account)
  17. reblog = Fabricate(:status, reblog: status)
  18. expect(StatusPin.new(account: account, status: reblog).save).to be false
  19. end
  20. it 'does not allow pins of private statuses' do
  21. account = Fabricate(:account)
  22. status = Fabricate(:status, account: account, visibility: :private)
  23. expect(StatusPin.new(account: account, status: status).save).to be false
  24. end
  25. it 'does not allow pins of direct statuses' do
  26. account = Fabricate(:account)
  27. status = Fabricate(:status, account: account, visibility: :direct)
  28. expect(StatusPin.new(account: account, status: status).save).to be false
  29. end
  30. max_pins = 5
  31. it 'does not allow pins above the max' do
  32. account = Fabricate(:account)
  33. status = []
  34. (max_pins + 1).times do |i|
  35. status[i] = Fabricate(:status, account: account)
  36. end
  37. max_pins.times do |i|
  38. expect(StatusPin.new(account: account, status: status[i]).save).to be true
  39. end
  40. expect(StatusPin.new(account: account, status: status[max_pins]).save).to be false
  41. end
  42. it 'allows pins above the max for remote accounts' do
  43. account = Fabricate(:account, domain: 'remote.test', username: 'bob', url: 'https://remote.test/')
  44. status = []
  45. (max_pins + 1).times do |i|
  46. status[i] = Fabricate(:status, account: account)
  47. end
  48. max_pins.times do |i|
  49. expect(StatusPin.new(account: account, status: status[i]).save).to be true
  50. end
  51. expect(StatusPin.new(account: account, status: status[max_pins]).save).to be true
  52. end
  53. end
  54. end