Skip to content
Snippets Groups Projects
Verified Commit a26714ca authored by Pedro Pombeiro's avatar Pedro Pombeiro
Browse files

Address MR review comments

parent 3cc8ae45
No related branches found
No related tags found
1 merge request!82721Extract service to reset runner registration tokens
......@@ -11,7 +11,7 @@ def initialize(scope, user)
end
def execute
return false unless @user.present? && @user.can?(:update_runners_registration_token, scope)
return unless @user.present? && @user.can?(:update_runners_registration_token, scope)
case scope
when ::ApplicationSetting
......@@ -29,5 +29,3 @@ def execute
end
end
end
Ci::Runners::AssignRunnerService.prepend_mod
......@@ -6,26 +6,26 @@
subject { described_class.new(scope, current_user).execute }
let_it_be(:user) { build(:user) }
let_it_be(:admin_user) { create_default(:user, :admin) }
let_it_be(:admin_user) { create(:user, :admin) }
shared_examples 'a registration token reset operation' do
context 'without user' do
let(:current_user) { nil }
it 'does not reset registration token and returns false' do
expect(scope).not_to receive(:reset_runners_token!)
it 'does not reset registration token and returns nil' do
expect(scope).not_to receive(token_reset_method_name)
is_expected.to eq(false)
is_expected.to be_nil
end
end
context 'with unauthorized user' do
let(:current_user) { user }
it 'does not reset registration token and returns false' do
expect(scope).not_to receive(:reset_runners_token!)
it 'does not reset registration token and returns nil' do
expect(scope).not_to receive(token_reset_method_name)
is_expected.to eq(false)
is_expected.to be_nil
end
end
......@@ -33,11 +33,11 @@
let(:current_user) { admin_user }
it 'resets registration token and returns value unchanged' do
expect(scope).to receive(:reset_runners_token!).once do
expect(scope).to receive(:runners_token).once.and_return('runners_token return value')
expect(scope).to receive(token_reset_method_name).once do
expect(scope).to receive(token_method_name).once.and_return("#{token_method_name} return value")
end
is_expected.to eq('runners_token return value')
is_expected.to eq("#{token_method_name} return value")
end
end
end
......@@ -50,48 +50,27 @@
allow(ApplicationSetting).to receive(:current_without_cache).and_return(scope)
end
context 'without user' do
let(:current_user) { nil }
it 'does not reset registration token and returns false' do
expect(scope).not_to receive(:reset_runners_registration_token!)
is_expected.to eq(false)
end
end
context 'with unauthorized user' do
let(:current_user) { user }
it 'calls assign_to on runner and returns value unchanged' do
expect(scope).not_to receive(:reset_runners_registration_token!)
is_expected.to eq(false)
end
end
context 'with admin user', :enable_admin_mode do
let(:current_user) { admin_user }
it 'resets registration token and returns value unchanged' do
expect(scope).to receive(:reset_runners_registration_token!).once do
expect(scope).to receive(:runners_registration_token).once.and_return('runners_registration_token return value')
end
is_expected.to eq('runners_registration_token return value')
end
it_behaves_like 'a registration token reset operation' do
let(:token_method_name) { :runners_registration_token }
let(:token_reset_method_name) { :reset_runners_registration_token! }
end
end
context 'with group scope' do
let_it_be(:scope) { create(:group) }
it_behaves_like 'a registration token reset operation'
it_behaves_like 'a registration token reset operation' do
let(:token_method_name) { :runners_token }
let(:token_reset_method_name) { :reset_runners_token! }
end
end
context 'with project scope' do
let_it_be(:scope) { create(:project) }
it_behaves_like 'a registration token reset operation'
it_behaves_like 'a registration token reset operation' do
let(:token_method_name) { :runners_token }
let(:token_reset_method_name) { :reset_runners_token! }
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment