Skip to content

Commit

Permalink
Extract specs for devops users in checks to shared example
Browse files Browse the repository at this point in the history
  • Loading branch information
mjankowski committed Mar 27, 2023
1 parent 62d9670 commit f7cae42
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 68 deletions.
18 changes: 1 addition & 17 deletions spec/lib/admin/system_check/database_schema_check_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,7 @@

let(:user) { Fabricate(:user) }

describe 'skip?' do
context 'when user can view devops' do
before { allow(user).to receive(:can?).with(:view_devops).and_return(true) }

it 'returns false' do
expect(check.skip?).to be false
end
end

context 'when user cannot view devops' do
before { allow(user).to receive(:can?).with(:view_devops).and_return(false) }

it 'returns true' do
expect(check.skip?).to be true
end
end
end
it_behaves_like 'a check available to devops users'

describe 'pass?' do
context 'when database needs migration' do
Expand Down
18 changes: 1 addition & 17 deletions spec/lib/admin/system_check/elasticsearch_check_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,7 @@

let(:user) { Fabricate(:user) }

describe 'skip?' do
context 'when user can view devops' do
before { allow(user).to receive(:can?).with(:view_devops).and_return(true) }

it 'returns false' do
expect(check.skip?).to be false
end
end

context 'when user cannot view devops' do
before { allow(user).to receive(:can?).with(:view_devops).and_return(false) }

it 'returns true' do
expect(check.skip?).to be true
end
end
end
it_behaves_like 'a check available to devops users'

describe 'pass?' do
context 'when chewy is enabled' do
Expand Down
18 changes: 1 addition & 17 deletions spec/lib/admin/system_check/media_privacy_check_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,7 @@

let(:user) { Fabricate(:user) }

describe 'skip?' do
context 'when user can view devops' do
before { allow(user).to receive(:can?).with(:view_devops).and_return(true) }

it 'returns false' do
expect(check.skip?).to be false
end
end

context 'when user cannot view devops' do
before { allow(user).to receive(:can?).with(:view_devops).and_return(false) }

it 'returns true' do
expect(check.skip?).to be true
end
end
end
it_behaves_like 'a check available to devops users'

describe 'pass?' do
context 'when the media cannot be listed' do
Expand Down
18 changes: 1 addition & 17 deletions spec/lib/admin/system_check/sidekiq_process_check_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,7 @@

let(:user) { Fabricate(:user) }

describe 'skip?' do
context 'when user can view devops' do
before { allow(user).to receive(:can?).with(:view_devops).and_return(true) }

it 'returns false' do
expect(check.skip?).to be false
end
end

context 'when user cannot view devops' do
before { allow(user).to receive(:can?).with(:view_devops).and_return(false) }

it 'returns true' do
expect(check.skip?).to be true
end
end
end
it_behaves_like 'a check available to devops users'

describe 'pass?' do
context 'when missing queues is empty' do
Expand Down
21 changes: 21 additions & 0 deletions spec/support/examples/lib/admin/checks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

shared_examples 'a check available to devops users' do
describe 'skip?' do
context 'when user can view devops' do
before { allow(user).to receive(:can?).with(:view_devops).and_return(true) }

it 'returns false' do
expect(check.skip?).to be false
end
end

context 'when user cannot view devops' do
before { allow(user).to receive(:can?).with(:view_devops).and_return(false) }

it 'returns true' do
expect(check.skip?).to be true
end
end
end
end

0 comments on commit f7cae42

Please sign in to comment.