-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
05dcd10
commit d9e68c5
Showing
6 changed files
with
100 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
...rns/submitter_owned_content_guard_spec.rb → ...uard/submitter_owned_publications_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
spec/controllers/concerns/submitter_ownership_guard/submitter_profile_ownership_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe SubmittersController, type: :controller do | ||
let(:submitter) { FactoryBot.create(:submitter) } | ||
let(:another_submitter) { FactoryBot.create(:submitter) } | ||
|
||
before do | ||
submitter | ||
another_submitter | ||
end | ||
|
||
# There are no Submitters index or destroy actions, so we cannot test them. | ||
# The SubmittersController is tested in spec/controllers/submitters_controller_spec.rb. | ||
|
||
describe '#submitter_owned_content_guard' do | ||
context 'when admin is logged in' do | ||
before { login_as_admin } | ||
|
||
it 'allows access to show' do | ||
get :show, params: { id: submitter.id } | ||
expect(response).to have_http_status(:ok) | ||
end | ||
|
||
it 'allows access to edit' do | ||
get :edit, params: { id: submitter.id } | ||
expect(response).to have_http_status(:ok) | ||
end | ||
end | ||
|
||
context 'when submitter owns the resource' do | ||
before { login_as_submitter_of(submitter) } | ||
|
||
it 'allows access to show' do | ||
get :show, params: { id: submitter.id } | ||
expect(response).to have_http_status(:ok) | ||
end | ||
|
||
it 'allows access to edit' do | ||
get :edit, params: { id: submitter.id } | ||
expect(response).to have_http_status(:ok) | ||
end | ||
end | ||
|
||
context 'when another submitter is logged in' do | ||
before { login_as_submitter_of(another_submitter) } | ||
|
||
it 'restricts access to show' do | ||
expect { get :show, params: { id: submitter.id } }.to raise_error(ActiveRecord::RecordNotFound) | ||
end | ||
|
||
it 'restricts access to edit' do | ||
expect { get :edit, params: { id: submitter.id } }.to raise_error(ActiveRecord::RecordNotFound) | ||
end | ||
end | ||
|
||
context 'when no user is logged in' do | ||
# Not tested because this scenario is handled by the UserAuthentication concern. | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters