Fix RSpec/RepeatedExample cop (#24849)

th-downstream
Matt Jankowski 1 year ago committed by GitHub
parent 9f5deb310b
commit e387175fc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -571,10 +571,6 @@ RSpec/PredicateMatcher:
- 'spec/models/user_spec.rb' - 'spec/models/user_spec.rb'
- 'spec/services/post_status_service_spec.rb' - 'spec/services/post_status_service_spec.rb'
RSpec/RepeatedExample:
Exclude:
- 'spec/policies/status_policy_spec.rb'
RSpec/StubbedMock: RSpec/StubbedMock:
Exclude: Exclude:
- 'spec/controllers/api/base_controller_spec.rb' - 'spec/controllers/api/base_controller_spec.rb'

@ -11,127 +11,139 @@ RSpec.describe StatusPolicy, type: :model do
let(:bob) { Fabricate(:account, username: 'bob') } let(:bob) { Fabricate(:account, username: 'bob') }
let(:status) { Fabricate(:status, account: alice) } let(:status) { Fabricate(:status, account: alice) }
permissions :show?, :reblog? do context 'with the permissions of show? and reblog?' do
it 'grants access when no viewer' do permissions :show?, :reblog? do
expect(subject).to permit(nil, status) it 'grants access when no viewer' do
end expect(subject).to permit(nil, status)
end
it 'denies access when viewer is blocked' do it 'denies access when viewer is blocked' do
block = Fabricate(:block) block = Fabricate(:block)
status.visibility = :private status.visibility = :private
status.account = block.target_account status.account = block.target_account
expect(subject).to_not permit(block.account, status) expect(subject).to_not permit(block.account, status)
end
end end
end end
permissions :show? do context 'with the permission of show?' do
it 'grants access when direct and account is viewer' do permissions :show? do
status.visibility = :direct it 'grants access when direct and account is viewer' do
status.visibility = :direct
expect(subject).to permit(status.account, status) expect(subject).to permit(status.account, status)
end end
it 'grants access when direct and viewer is mentioned' do it 'grants access when direct and viewer is mentioned' do
status.visibility = :direct status.visibility = :direct
status.mentions = [Fabricate(:mention, account: alice)] status.mentions = [Fabricate(:mention, account: alice)]
expect(subject).to permit(alice, status) expect(subject).to permit(alice, status)
end end
it 'grants access when direct and non-owner viewer is mentioned and mentions are loaded' do it 'grants access when direct and non-owner viewer is mentioned and mentions are loaded' do
status.visibility = :direct status.visibility = :direct
status.mentions = [Fabricate(:mention, account: bob)] status.mentions = [Fabricate(:mention, account: bob)]
status.mentions.load status.mentions.load
expect(subject).to permit(bob, status) expect(subject).to permit(bob, status)
end end
it 'denies access when direct and viewer is not mentioned' do it 'denies access when direct and viewer is not mentioned' do
viewer = Fabricate(:account) viewer = Fabricate(:account)
status.visibility = :direct status.visibility = :direct
expect(subject).to_not permit(viewer, status) expect(subject).to_not permit(viewer, status)
end end
it 'grants access when private and account is viewer' do it 'grants access when private and account is viewer' do
status.visibility = :private status.visibility = :private
expect(subject).to permit(status.account, status) expect(subject).to permit(status.account, status)
end end
it 'grants access when private and account is following viewer' do it 'grants access when private and account is following viewer' do
follow = Fabricate(:follow) follow = Fabricate(:follow)
status.visibility = :private status.visibility = :private
status.account = follow.target_account status.account = follow.target_account
expect(subject).to permit(follow.account, status) expect(subject).to permit(follow.account, status)
end end
it 'grants access when private and viewer is mentioned' do it 'grants access when private and viewer is mentioned' do
status.visibility = :private status.visibility = :private
status.mentions = [Fabricate(:mention, account: alice)] status.mentions = [Fabricate(:mention, account: alice)]
expect(subject).to permit(alice, status) expect(subject).to permit(alice, status)
end end
it 'denies access when private and viewer is not mentioned or followed' do it 'denies access when private and viewer is not mentioned or followed' do
viewer = Fabricate(:account) viewer = Fabricate(:account)
status.visibility = :private status.visibility = :private
expect(subject).to_not permit(viewer, status) expect(subject).to_not permit(viewer, status)
end
end end
end end
permissions :reblog? do context 'with the permission of reblog?' do
it 'denies access when private' do permissions :reblog? do
viewer = Fabricate(:account) it 'denies access when private' do
status.visibility = :private viewer = Fabricate(:account)
status.visibility = :private
expect(subject).to_not permit(viewer, status) expect(subject).to_not permit(viewer, status)
end end
it 'denies access when direct' do it 'denies access when direct' do
viewer = Fabricate(:account) viewer = Fabricate(:account)
status.visibility = :direct status.visibility = :direct
expect(subject).to_not permit(viewer, status) expect(subject).to_not permit(viewer, status)
end
end end
end end
permissions :destroy?, :unreblog? do context 'with the permissions of destroy? and unreblog?' do
it 'grants access when account is deleter' do permissions :destroy?, :unreblog? do
expect(subject).to permit(status.account, status) it 'grants access when account is deleter' do
end expect(subject).to permit(status.account, status)
end
it 'denies access when account is not deleter' do it 'denies access when account is not deleter' do
expect(subject).to_not permit(bob, status) expect(subject).to_not permit(bob, status)
end end
it 'denies access when no deleter' do it 'denies access when no deleter' do
expect(subject).to_not permit(nil, status) expect(subject).to_not permit(nil, status)
end
end end
end end
permissions :favourite? do context 'with the permission of favourite?' do
it 'grants access when viewer is not blocked' do permissions :favourite? do
follow = Fabricate(:follow) it 'grants access when viewer is not blocked' do
status.account = follow.target_account follow = Fabricate(:follow)
status.account = follow.target_account
expect(subject).to permit(follow.account, status) expect(subject).to permit(follow.account, status)
end end
it 'denies when viewer is blocked' do it 'denies when viewer is blocked' do
block = Fabricate(:block) block = Fabricate(:block)
status.account = block.target_account status.account = block.target_account
expect(subject).to_not permit(block.account, status) expect(subject).to_not permit(block.account, status)
end
end end
end end
permissions :update? do context 'with the permission of update?' do
it 'grants access if owner' do permissions :update? do
expect(subject).to permit(status.account, status) it 'grants access if owner' do
expect(subject).to permit(status.account, status)
end
end end
end end
end end

Loading…
Cancel
Save