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.

74 lines
2.2 KiB

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