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.

121 lines
3.4 KiB

  1. require 'rails_helper'
  2. require 'pundit/rspec'
  3. RSpec.describe StatusPolicy, type: :model do
  4. subject { described_class }
  5. let(:admin) { Fabricate(:user, admin: true) }
  6. let(:alice) { Fabricate(:account, username: 'alice') }
  7. let(:bob) { Fabricate(:account, username: 'bob') }
  8. let(:status) { Fabricate(:status, account: alice) }
  9. permissions :show?, :reblog? do
  10. it 'grants access when no viewer' do
  11. expect(subject).to permit(nil, status)
  12. end
  13. it 'denies access when viewer is blocked' do
  14. block = Fabricate(:block)
  15. status.visibility = :private
  16. status.account = block.target_account
  17. expect(subject).to_not permit(block.account, status)
  18. end
  19. end
  20. permissions :show? do
  21. it 'grants access when direct and account is viewer' do
  22. status.visibility = :direct
  23. expect(subject).to permit(status.account, status)
  24. end
  25. it 'grants access when direct and viewer is mentioned' do
  26. status.visibility = :direct
  27. status.mentions = [Fabricate(:mention, account: alice)]
  28. expect(subject).to permit(alice, status)
  29. end
  30. it 'denies access when direct and viewer is not mentioned' do
  31. viewer = Fabricate(:account)
  32. status.visibility = :direct
  33. expect(subject).to_not permit(viewer, status)
  34. end
  35. it 'grants access when private and account is viewer' do
  36. status.visibility = :private
  37. expect(subject).to permit(status.account, status)
  38. end
  39. it 'grants access when private and account is following viewer' do
  40. follow = Fabricate(:follow)
  41. status.visibility = :private
  42. status.account = follow.target_account
  43. expect(subject).to permit(follow.account, status)
  44. end
  45. it 'grants access when private and viewer is mentioned' do
  46. status.visibility = :private
  47. status.mentions = [Fabricate(:mention, account: alice)]
  48. expect(subject).to permit(alice, status)
  49. end
  50. it 'denies access when private and viewer is not mentioned or followed' do
  51. viewer = Fabricate(:account)
  52. status.visibility = :private
  53. expect(subject).to_not permit(viewer, status)
  54. end
  55. it 'denies access when local-only and the viewer is not logged in' do
  56. allow(status).to receive(:local_only?) { true }
  57. expect(subject).to_not permit(nil, status)
  58. end
  59. it 'denies access when local-only and the viewer is from another domain' do
  60. viewer = Fabricate(:account, domain: 'remote-domain')
  61. allow(status).to receive(:local_only?) { true }
  62. expect(subject).to_not permit(viewer, status)
  63. end
  64. end
  65. permissions :reblog? do
  66. it 'denies access when private' do
  67. viewer = Fabricate(:account)
  68. status.visibility = :private
  69. expect(subject).to_not permit(viewer, status)
  70. end
  71. it 'denies access when direct' do
  72. viewer = Fabricate(:account)
  73. status.visibility = :direct
  74. expect(subject).to_not permit(viewer, status)
  75. end
  76. end
  77. permissions :destroy?, :unreblog? do
  78. it 'grants access when account is deleter' do
  79. expect(subject).to permit(status.account, status)
  80. end
  81. it 'grants access when account is admin' do
  82. expect(subject).to permit(admin.account, status)
  83. end
  84. it 'denies access when account is not deleter' do
  85. expect(subject).to_not permit(bob, status)
  86. end
  87. it 'denies access when no deleter' do
  88. expect(subject).to_not permit(nil, status)
  89. end
  90. end
  91. end