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.

115 lines
3.1 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. end
  60. permissions :reblog? do
  61. it 'denies access when private' do
  62. viewer = Fabricate(:account)
  63. status.visibility = :private
  64. expect(subject).to_not permit(viewer, status)
  65. end
  66. it 'denies access when direct' do
  67. viewer = Fabricate(:account)
  68. status.visibility = :direct
  69. expect(subject).to_not permit(viewer, status)
  70. end
  71. end
  72. permissions :destroy?, :unreblog? do
  73. it 'grants access when account is deleter' do
  74. expect(subject).to permit(status.account, status)
  75. end
  76. it 'grants access when account is admin' do
  77. expect(subject).to permit(admin.account, status)
  78. end
  79. it 'denies access when account is not deleter' do
  80. expect(subject).to_not permit(bob, status)
  81. end
  82. it 'denies access when no deleter' do
  83. expect(subject).to_not permit(nil, status)
  84. end
  85. end
  86. end