diff options
author | Adam Niedzielski <adamsunday@gmail.com> | 2016-08-02 21:37:22 +0300 |
---|---|---|
committer | Adam Niedzielski <adamsunday@gmail.com> | 2016-08-02 21:37:22 +0300 |
commit | b2c8dc6f35ceb08e23422a356831070b5136809d (patch) | |
tree | 248fd3b5723e8fc2a8d19c05f1bce272a8e80cfc | |
parent | 420e59030b151a5634e31beaa1d80f1eac079295 (diff) |
Replace optional parameters with keyword arguments.
-rw-r--r-- | app/controllers/projects/project_members_controller.rb | 7 | ||||
-rw-r--r-- | app/models/group.rb | 2 | ||||
-rw-r--r-- | app/models/member.rb | 2 | ||||
-rw-r--r-- | app/models/members/project_member.rb | 10 | ||||
-rw-r--r-- | app/models/project_team.rb | 10 | ||||
-rw-r--r-- | spec/mailers/notify_spec.rb | 14 | ||||
-rw-r--r-- | spec/models/member_spec.rb | 14 |
7 files changed, 45 insertions, 14 deletions
diff --git a/app/controllers/projects/project_members_controller.rb b/app/controllers/projects/project_members_controller.rb index 0fe96b66fa2..7b84be54a3a 100644 --- a/app/controllers/projects/project_members_controller.rb +++ b/app/controllers/projects/project_members_controller.rb @@ -36,7 +36,12 @@ class Projects::ProjectMembersController < Projects::ApplicationController end def create - @project.team.add_users(params[:user_ids].split(','), params[:access_level], current_user, params[:expires_at]) + @project.team.add_users( + params[:user_ids].split(','), + params[:access_level], + expires_at: params[:expires_at], + current_user: current_user + ) redirect_to namespace_project_project_members_path(@project.namespace, @project) end diff --git a/app/models/group.rb b/app/models/group.rb index 37631b99701..11c39bbdfe4 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -97,7 +97,7 @@ class Group < Namespace def add_users(user_ids, access_level, current_user = nil) user_ids.each do |user_id| - Member.add_user(self.group_members, user_id, access_level, current_user) + Member.add_user(self.group_members, user_id, access_level, current_user: current_user) end end diff --git a/app/models/member.rb b/app/models/member.rb index 998144330b1..6b9206163c4 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -74,7 +74,7 @@ class Member < ActiveRecord::Base user end - def add_user(members, user_id, access_level, current_user = nil, expires_at = nil) + def add_user(members, user_id, access_level, current_user: nil, expires_at: nil) user = user_for_id(user_id) # `user` can be either a User object or an email to be invited diff --git a/app/models/members/project_member.rb b/app/models/members/project_member.rb index b86b536005b..d5666de79cc 100644 --- a/app/models/members/project_member.rb +++ b/app/models/members/project_member.rb @@ -33,7 +33,7 @@ class ProjectMember < Member # :master # ) # - def add_users_into_projects(project_ids, user_ids, access, current_user = nil, expires_at = nil) + def add_users_into_projects(project_ids, user_ids, access, current_user: nil, expires_at: nil) access_level = if roles_hash.has_key?(access) roles_hash[access] elsif roles_hash.values.include?(access.to_i) @@ -49,7 +49,13 @@ class ProjectMember < Member project = Project.find(project_id) users.each do |user| - Member.add_user(project.project_members, user, access_level, current_user, expires_at) + Member.add_user( + project.project_members, + user, + access_level, + current_user: current_user, + expires_at: expires_at + ) end end end diff --git a/app/models/project_team.rb b/app/models/project_team.rb index cf1d2396974..1865c5253e2 100644 --- a/app/models/project_team.rb +++ b/app/models/project_team.rb @@ -15,7 +15,7 @@ class ProjectTeam users, access, current_user = *args if users.respond_to?(:each) - add_users(users, access, current_user) + add_users(users, access, current_user: current_user) else add_user(users, access, current_user) end @@ -33,18 +33,18 @@ class ProjectTeam member end - def add_users(users, access, current_user = nil, expires_at = nil) + def add_users(users, access, current_user: nil, expires_at: nil) ProjectMember.add_users_into_projects( [project.id], users, access, - current_user, - expires_at + current_user: current_user, + expires_at: expires_at ) end def add_user(user, access, current_user = nil) - add_users([user], access, current_user) + add_users([user], access, current_user: current_user) end # Remove all users from project team diff --git a/spec/mailers/notify_spec.rb b/spec/mailers/notify_spec.rb index 3685b2b17b5..828d2845988 100644 --- a/spec/mailers/notify_spec.rb +++ b/spec/mailers/notify_spec.rb @@ -493,7 +493,12 @@ describe Notify do end def invite_to_project(project:, email:, inviter:) - ProjectMember.add_user(project.project_members, 'toto@example.com', Gitlab::Access::DEVELOPER, inviter) + Member.add_user( + project.project_members, + 'toto@example.com', + Gitlab::Access::DEVELOPER, + current_user: inviter + ) project.project_members.invite.last end @@ -740,7 +745,12 @@ describe Notify do end def invite_to_group(group:, email:, inviter:) - GroupMember.add_user(group.group_members, 'toto@example.com', Gitlab::Access::DEVELOPER, inviter) + Member.add_user( + group.group_members, + 'toto@example.com', + Gitlab::Access::DEVELOPER, + current_user: inviter + ) group.group_members.invite.last end diff --git a/spec/models/member_spec.rb b/spec/models/member_spec.rb index 44cd3c08718..2f6cccdc417 100644 --- a/spec/models/member_spec.rb +++ b/spec/models/member_spec.rb @@ -65,11 +65,21 @@ describe Member, models: true do @master_user = create(:user).tap { |u| project.team << [u, :master] } @master = project.members.find_by(user_id: @master_user.id) - ProjectMember.add_user(project.members, 'toto1@example.com', Gitlab::Access::DEVELOPER, @master_user) + Member.add_user( + project.members, + 'toto1@example.com', + Gitlab::Access::DEVELOPER, + current_user: @master_user + ) @invited_member = project.members.invite.find_by_invite_email('toto1@example.com') accepted_invite_user = build(:user) - ProjectMember.add_user(project.members, 'toto2@example.com', Gitlab::Access::DEVELOPER, @master_user) + Member.add_user( + project.members, + 'toto2@example.com', + Gitlab::Access::DEVELOPER, + current_user: @master_user + ) @accepted_invite_member = project.members.invite.find_by_invite_email('toto2@example.com').tap { |u| u.accept_invite!(accepted_invite_user) } requested_user = create(:user).tap { |u| project.request_access(u) } |