Commit a3f645ef51ec12ce93934b4ddb11313613d8c451
1 parent
3fe578a7
Exists in
spb-stable
and in
3 other branches
Remove deprecated finders
Showing
71 changed files
with
145 additions
and
147 deletions
Show diff stats
Gemfile
Gemfile.lock
app/controllers/admin/groups_controller.rb
app/controllers/admin/projects_controller.rb
... | ... | @@ -5,7 +5,7 @@ class Admin::ProjectsController < Admin::ApplicationController |
5 | 5 | |
6 | 6 | def index |
7 | 7 | owner_id = params[:owner_id] |
8 | - user = User.find_by_id(owner_id) | |
8 | + user = User.find_by(id: owner_id) | |
9 | 9 | |
10 | 10 | @projects = user ? user.owned_projects : Project.all |
11 | 11 | @projects = @projects.where("visibility_level IN (?)", params[:visibility_levels]) if params[:visibility_levels].present? | ... | ... |
app/controllers/admin/users_controller.rb
app/controllers/dashboard_controller.rb
... | ... | @@ -41,7 +41,7 @@ class DashboardController < ApplicationController |
41 | 41 | current_user.authorized_projects |
42 | 42 | end |
43 | 43 | |
44 | - @projects = @projects.where(namespace_id: Group.find_by_name(params[:group])) if params[:group].present? | |
44 | + @projects = @projects.where(namespace_id: Group.find_by(name: params[:group])) if params[:group].present? | |
45 | 45 | @projects = @projects.where(visibility_level: params[:visibility_level]) if params[:visibility_level].present? |
46 | 46 | @projects = @projects.includes(:namespace) |
47 | 47 | @projects = @projects.tagged_with(params[:label]) if params[:label].present? | ... | ... |
app/controllers/groups_controller.rb
app/controllers/profiles/groups_controller.rb
app/controllers/projects/issues_controller.rb
... | ... | @@ -97,7 +97,7 @@ class Projects::IssuesController < Projects::ApplicationController |
97 | 97 | |
98 | 98 | def issue |
99 | 99 | @issue ||= begin |
100 | - @project.issues.find_by_iid!(params[:id]) | |
100 | + @project.issues.find_by!(iid: params[:id]) | |
101 | 101 | rescue ActiveRecord::RecordNotFound |
102 | 102 | redirect_old |
103 | 103 | end |
... | ... | @@ -128,7 +128,7 @@ class Projects::IssuesController < Projects::ApplicationController |
128 | 128 | # To prevent 404 errors we provide a redirect to correct iids until 7.0 release |
129 | 129 | # |
130 | 130 | def redirect_old |
131 | - issue = @project.issues.find_by_id(params[:id]) | |
131 | + issue = @project.issues.find_by(id: params[:id]) | |
132 | 132 | |
133 | 133 | if issue |
134 | 134 | redirect_to project_issue_path(@project, issue) | ... | ... |
app/controllers/projects/merge_requests_controller.rb
... | ... | @@ -169,7 +169,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController |
169 | 169 | end |
170 | 170 | |
171 | 171 | def merge_request |
172 | - @merge_request ||= @project.merge_requests.find_by_iid!(params[:id]) | |
172 | + @merge_request ||= @project.merge_requests.find_by!(iid: params[:id]) | |
173 | 173 | end |
174 | 174 | |
175 | 175 | def closes_issues | ... | ... |
app/controllers/projects/milestones_controller.rb
... | ... | @@ -76,7 +76,7 @@ class Projects::MilestonesController < Projects::ApplicationController |
76 | 76 | protected |
77 | 77 | |
78 | 78 | def milestone |
79 | - @milestone ||= @project.milestones.find_by_iid!(params[:id]) | |
79 | + @milestone ||= @project.milestones.find_by!(iid: params[:id]) | |
80 | 80 | end |
81 | 81 | |
82 | 82 | def authorize_admin_milestone! | ... | ... |
app/controllers/projects/team_members_controller.rb
... | ... | @@ -26,7 +26,7 @@ class Projects::TeamMembersController < Projects::ApplicationController |
26 | 26 | end |
27 | 27 | |
28 | 28 | def update |
29 | - @user_project_relation = project.users_projects.find_by_user_id(member) | |
29 | + @user_project_relation = project.users_projects.find_by(user_id: member) | |
30 | 30 | @user_project_relation.update_attributes(params[:team_member]) |
31 | 31 | |
32 | 32 | unless @user_project_relation.valid? |
... | ... | @@ -36,7 +36,7 @@ class Projects::TeamMembersController < Projects::ApplicationController |
36 | 36 | end |
37 | 37 | |
38 | 38 | def destroy |
39 | - @user_project_relation = project.users_projects.find_by_user_id(member) | |
39 | + @user_project_relation = project.users_projects.find_by(user_id: member) | |
40 | 40 | @user_project_relation.destroy |
41 | 41 | |
42 | 42 | respond_to do |format| |
... | ... | @@ -46,7 +46,7 @@ class Projects::TeamMembersController < Projects::ApplicationController |
46 | 46 | end |
47 | 47 | |
48 | 48 | def leave |
49 | - project.users_projects.find_by_user_id(current_user).destroy | |
49 | + project.users_projects.find_by(user_id: current_user).destroy | |
50 | 50 | |
51 | 51 | respond_to do |format| |
52 | 52 | format.html { redirect_to :back } |
... | ... | @@ -65,6 +65,6 @@ class Projects::TeamMembersController < Projects::ApplicationController |
65 | 65 | protected |
66 | 66 | |
67 | 67 | def member |
68 | - @member ||= User.find_by_username(params[:id]) | |
68 | + @member ||= User.find_by(username: params[:id]) | |
69 | 69 | end |
70 | 70 | end | ... | ... |
app/controllers/search_controller.rb
1 | 1 | class SearchController < ApplicationController |
2 | 2 | def show |
3 | - @project = Project.find_by_id(params[:project_id]) if params[:project_id].present? | |
4 | - @group = Group.find_by_id(params[:group_id]) if params[:group_id].present? | |
3 | + @project = Project.find_by(id: params[:project_id]) if params[:project_id].present? | |
4 | + @group = Group.find_by(id: params[:group_id]) if params[:group_id].present? | |
5 | 5 | |
6 | 6 | if @project |
7 | 7 | return access_denied! unless can?(current_user, :download_code, @project) | ... | ... |
app/controllers/snippets_controller.rb
... | ... | @@ -18,7 +18,7 @@ class SnippetsController < ApplicationController |
18 | 18 | end |
19 | 19 | |
20 | 20 | def user_index |
21 | - @user = User.find_by_username(params[:username]) | |
21 | + @user = User.find_by(username: params[:username]) | |
22 | 22 | @snippets = @user.snippets.fresh.non_expired |
23 | 23 | |
24 | 24 | if @user == current_user | ... | ... |
app/controllers/users_controller.rb
... | ... | @@ -2,7 +2,7 @@ class UsersController < ApplicationController |
2 | 2 | layout 'navless' |
3 | 3 | |
4 | 4 | def show |
5 | - @user = User.find_by_username!(params[:username]) | |
5 | + @user = User.find_by!(username: params[:username]) | |
6 | 6 | @projects = @user.authorized_projects.where(id: current_user.authorized_projects.pluck(:id)).includes(:namespace) |
7 | 7 | @events = @user.recent_events.where(project_id: @projects.map(&:id)).limit(20) |
8 | 8 | ... | ... |
app/controllers/users_groups_controller.rb
app/helpers/application_helper.rb
app/mailers/emails/issues.rb
... | ... | @@ -8,7 +8,7 @@ module Emails |
8 | 8 | |
9 | 9 | def reassigned_issue_email(recipient_id, issue_id, previous_assignee_id) |
10 | 10 | @issue = Issue.find(issue_id) |
11 | - @previous_assignee = User.find_by_id(previous_assignee_id) if previous_assignee_id | |
11 | + @previous_assignee = User.find_by(id: previous_assignee_id) if previous_assignee_id | |
12 | 12 | @project = @issue.project |
13 | 13 | mail(to: recipient(recipient_id), subject: subject("Changed issue ##{@issue.iid}", @issue.title)) |
14 | 14 | end | ... | ... |
app/mailers/emails/merge_requests.rb
... | ... | @@ -8,7 +8,7 @@ module Emails |
8 | 8 | |
9 | 9 | def reassigned_merge_request_email(recipient_id, merge_request_id, previous_assignee_id) |
10 | 10 | @merge_request = MergeRequest.find(merge_request_id) |
11 | - @previous_assignee = User.find_by_id(previous_assignee_id) if previous_assignee_id | |
11 | + @previous_assignee = User.find_by(id: previous_assignee_id) if previous_assignee_id | |
12 | 12 | @project = @merge_request.project |
13 | 13 | mail(to: recipient(recipient_id), subject: subject("Changed merge request ##{@merge_request.iid}", @merge_request.title)) |
14 | 14 | end | ... | ... |
app/models/note.rb
... | ... | @@ -123,8 +123,8 @@ class Note < ActiveRecord::Base |
123 | 123 | |
124 | 124 | def commit_author |
125 | 125 | @commit_author ||= |
126 | - project.users.find_by_email(noteable.author_email) || | |
127 | - project.users.find_by_name(noteable.author_name) | |
126 | + project.users.find_by(email: noteable.author_email) || | |
127 | + project.users.find_by(name: noteable.author_name) | |
128 | 128 | rescue |
129 | 129 | nil |
130 | 130 | end | ... | ... |
app/models/project.rb
... | ... | @@ -141,10 +141,10 @@ class Project < ActiveRecord::Base |
141 | 141 | def find_with_namespace(id) |
142 | 142 | if id.include?("/") |
143 | 143 | id = id.split("/") |
144 | - namespace = Namespace.find_by_path(id.first) | |
144 | + namespace = Namespace.find_by(path: id.first) | |
145 | 145 | return nil unless namespace |
146 | 146 | |
147 | - where(namespace_id: namespace.id).find_by_path(id.second) | |
147 | + where(namespace_id: namespace.id).find_by(path: id.second) | |
148 | 148 | else |
149 | 149 | where(path: id, namespace_id: nil).last |
150 | 150 | end |
... | ... | @@ -288,7 +288,7 @@ class Project < ActiveRecord::Base |
288 | 288 | |
289 | 289 | # Get Team Member record by user id |
290 | 290 | def team_member_by_id(user_id) |
291 | - users_projects.find_by_user_id(user_id) | |
291 | + users_projects.find_by(user_id: user_id) | |
292 | 292 | end |
293 | 293 | |
294 | 294 | def name_with_namespace | ... | ... |
app/models/project_team.rb
... | ... | @@ -22,22 +22,22 @@ class ProjectTeam |
22 | 22 | end |
23 | 23 | |
24 | 24 | def find(user_id) |
25 | - user = project.users.find_by_id(user_id) | |
25 | + user = project.users.find_by(id: user_id) | |
26 | 26 | |
27 | 27 | if group |
28 | - user ||= group.users.find_by_id(user_id) | |
28 | + user ||= group.users.find_by(id: user_id) | |
29 | 29 | end |
30 | 30 | |
31 | 31 | user |
32 | 32 | end |
33 | 33 | |
34 | 34 | def find_tm(user_id) |
35 | - tm = project.users_projects.find_by_user_id(user_id) | |
35 | + tm = project.users_projects.find_by(user_id: user_id) | |
36 | 36 | |
37 | 37 | # If user is not in project members |
38 | 38 | # we should check for group membership |
39 | 39 | if group && !tm |
40 | - tm = group.users_groups.find_by_user_id(user_id) | |
40 | + tm = group.users_groups.find_by(user_id: user_id) | |
41 | 41 | end |
42 | 42 | |
43 | 43 | tm | ... | ... |
app/models/user.rb
... | ... | @@ -238,7 +238,7 @@ class User < ActiveRecord::Base |
238 | 238 | |
239 | 239 | def namespace_uniq |
240 | 240 | namespace_name = self.username |
241 | - if Namespace.find_by_path(namespace_name) | |
241 | + if Namespace.find_by(path: namespace_name) | |
242 | 242 | self.errors.add :username, "already exist" |
243 | 243 | end |
244 | 244 | end |
... | ... | @@ -382,7 +382,7 @@ class User < ActiveRecord::Base |
382 | 382 | end |
383 | 383 | |
384 | 384 | def created_by |
385 | - User.find_by_id(created_by_id) if created_by_id | |
385 | + User.find_by(id: created_by_id) if created_by_id | |
386 | 386 | end |
387 | 387 | |
388 | 388 | def sanitize_attrs | ... | ... |
app/services/notification_service.rb
... | ... | @@ -195,10 +195,10 @@ class NotificationService |
195 | 195 | users.reject do |user| |
196 | 196 | next user.notification.disabled? unless project |
197 | 197 | |
198 | - tm = project.users_projects.find_by_user_id(user.id) | |
198 | + tm = project.users_projects.find_by(user_id: user.id) | |
199 | 199 | |
200 | 200 | if !tm && project.group |
201 | - tm = project.group.users_groups.find_by_user_id(user.id) | |
201 | + tm = project.group.users_groups.find_by(user_id: user.id) | |
202 | 202 | end |
203 | 203 | |
204 | 204 | # reject users who globally disabled notification and has no membership | ... | ... |
app/services/projects/create_service.rb
app/services/search/global_service.rb
... | ... | @@ -15,7 +15,7 @@ module Search |
15 | 15 | authorized_projects_ids += current_user.authorized_projects.pluck(:id) if current_user |
16 | 16 | authorized_projects_ids += Project.public_or_internal_only(current_user).pluck(:id) |
17 | 17 | |
18 | - group = Group.find_by_id(params[:group_id]) if params[:group_id].present? | |
18 | + group = Group.find_by(id: params[:group_id]) if params[:group_id].present? | |
19 | 19 | projects = Project.where(id: authorized_projects_ids) |
20 | 20 | projects = projects.where(namespace_id: group.id) if group |
21 | 21 | projects = projects.search(query) | ... | ... |
db/fixtures/development/04_project.rb
db/migrate/20130506095501_remove_project_id_from_key.rb
... | ... | @@ -4,7 +4,7 @@ class RemoveProjectIdFromKey < ActiveRecord::Migration |
4 | 4 | Key.where('project_id IS NOT NULL').update_all(type: 'DeployKey') |
5 | 5 | |
6 | 6 | DeployKey.all.each do |key| |
7 | - project = Project.find_by_id(key.project_id) | |
7 | + project = Project.find_by(id: key.project_id) | |
8 | 8 | if project |
9 | 9 | project.deploy_keys << key |
10 | 10 | print '.' | ... | ... |
features/steps/admin/admin_groups.rb
... | ... | @@ -40,7 +40,7 @@ class AdminGroups < Spinach::FeatureSteps |
40 | 40 | end |
41 | 41 | |
42 | 42 | When 'I select user "John" from user list as "Reporter"' do |
43 | - user = User.find_by_name("John") | |
43 | + user = User.find_by(name: "John") | |
44 | 44 | select2(user.id, from: "#user_ids", multiple: true) |
45 | 45 | within "#new_team_member" do |
46 | 46 | select "Reporter", from: "group_access" | ... | ... |
features/steps/dashboard/dashboard.rb
... | ... | @@ -43,7 +43,7 @@ class Dashboard < Spinach::FeatureSteps |
43 | 43 | end |
44 | 44 | |
45 | 45 | And 'user with name "John Doe" left project "Shop"' do |
46 | - user = User.find_by_name "John Doe" | |
46 | + user = User.find_by(name: "John Doe") | |
47 | 47 | Event.create( |
48 | 48 | project: project, |
49 | 49 | author_id: user.id, |
... | ... | @@ -85,6 +85,6 @@ class Dashboard < Spinach::FeatureSteps |
85 | 85 | end |
86 | 86 | |
87 | 87 | def project |
88 | - @project ||= Project.find_by_name "Shop" | |
88 | + @project ||= Project.find_by(name: "Shop") | |
89 | 89 | end |
90 | 90 | end | ... | ... |
features/steps/dashboard/dashboard_with_archived_projects.rb
... | ... | @@ -4,7 +4,7 @@ class DashboardWithArchivedProjects < Spinach::FeatureSteps |
4 | 4 | include SharedProject |
5 | 5 | |
6 | 6 | When 'project "Forum" is archived' do |
7 | - project = Project.find_by_name "Forum" | |
7 | + project = Project.find_by(name: "Forum") | |
8 | 8 | project.update_attribute(:archived, true) |
9 | 9 | end |
10 | 10 | ... | ... |
features/steps/group/group.rb
... | ... | @@ -39,7 +39,7 @@ class Groups < Spinach::FeatureSteps |
39 | 39 | end |
40 | 40 | |
41 | 41 | And 'I select user "John" from list with role "Reporter"' do |
42 | - user = User.find_by_name("John") | |
42 | + user = User.find_by(name: "John") | |
43 | 43 | within ".users-group-form" do |
44 | 44 | select2(user.id, from: "#user_ids", multiple: true) |
45 | 45 | select "Reporter", from: "group_access" | ... | ... |
features/steps/profile/profile_ssh_keys.rb
... | ... | @@ -18,7 +18,7 @@ class ProfileSshKeys < Spinach::FeatureSteps |
18 | 18 | end |
19 | 19 | |
20 | 20 | Then 'I should see new ssh key "Laptop"' do |
21 | - key = Key.find_by_title("Laptop") | |
21 | + key = Key.find_by(title: "Laptop") | |
22 | 22 | page.should have_content(key.title) |
23 | 23 | page.should have_content(key.key) |
24 | 24 | current_path.should == profile_key_path(key) | ... | ... |
features/steps/project/project_archived.rb
... | ... | @@ -4,17 +4,17 @@ class ProjectArchived < Spinach::FeatureSteps |
4 | 4 | include SharedPaths |
5 | 5 | |
6 | 6 | When 'project "Forum" is archived' do |
7 | - project = Project.find_by_name "Forum" | |
7 | + project = Project.find_by(name: "Forum") | |
8 | 8 | project.update_attribute(:archived, true) |
9 | 9 | end |
10 | 10 | |
11 | 11 | When 'project "Shop" is archived' do |
12 | - project = Project.find_by_name "Shop" | |
12 | + project = Project.find_by(name: "Shop") | |
13 | 13 | project.update_attribute(:archived, true) |
14 | 14 | end |
15 | 15 | |
16 | 16 | When 'I visit project "Forum" page' do |
17 | - project = Project.find_by_name "Forum" | |
17 | + project = Project.find_by(name: "Forum") | |
18 | 18 | visit project_path(project) |
19 | 19 | end |
20 | 20 | ... | ... |
features/steps/project/project_browse_branches.rb
... | ... | @@ -29,7 +29,7 @@ class ProjectBrowseBranches < Spinach::FeatureSteps |
29 | 29 | end |
30 | 30 | |
31 | 31 | And 'project "Shop" has protected branches' do |
32 | - project = Project.find_by_name("Shop") | |
32 | + project = Project.find_by(name: "Shop") | |
33 | 33 | project.protected_branches.create(name: "stable") |
34 | 34 | end |
35 | 35 | end | ... | ... |
features/steps/project/project_fork.rb
... | ... | @@ -11,7 +11,7 @@ class ForkProject < Spinach::FeatureSteps |
11 | 11 | end |
12 | 12 | |
13 | 13 | step 'I am a member of project "Shop"' do |
14 | - @project = Project.find_by_name "Shop" | |
14 | + @project = Project.find_by(name: "Shop") | |
15 | 15 | @project ||= create(:project_with_code, name: "Shop", group: create(:group)) |
16 | 16 | @project.team << [@user, :reporter] |
17 | 17 | end |
... | ... | @@ -19,7 +19,7 @@ class ForkProject < Spinach::FeatureSteps |
19 | 19 | step 'I should see the forked project page' do |
20 | 20 | page.should have_content "Project was successfully forked." |
21 | 21 | current_path.should include current_user.namespace.path |
22 | - @forked_project = Project.find_by_namespace_id(current_user.namespace.path) | |
22 | + @forked_project = Project.find_by(namespace_id: current_user.namespace.path) | |
23 | 23 | end |
24 | 24 | |
25 | 25 | step 'I already have a project named "Shop" in my namespace' do | ... | ... |
features/steps/project/project_forked_merge_requests.rb
... | ... | @@ -6,7 +6,7 @@ class ProjectForkedMergeRequests < Spinach::FeatureSteps |
6 | 6 | include Select2Helper |
7 | 7 | |
8 | 8 | step 'I am a member of project "Shop"' do |
9 | - @project = Project.find_by_name "Shop" | |
9 | + @project = Project.find_by(name: "Shop") | |
10 | 10 | @project ||= create(:project_with_code, name: "Shop") |
11 | 11 | @project.team << [@user, :reporter] |
12 | 12 | end |
... | ... | @@ -14,7 +14,7 @@ class ProjectForkedMergeRequests < Spinach::FeatureSteps |
14 | 14 | step 'I have a project forked off of "Shop" called "Forked Shop"' do |
15 | 15 | @forking_user = @user |
16 | 16 | forked_project_link = build(:forked_project_link) |
17 | - @forked_project = Project.find_by_name "Forked Shop" | |
17 | + @forked_project = Project.find_by(name: "Forked Shop") | |
18 | 18 | @forked_project ||= create(:source_project_with_code, name: "Forked Shop", forked_project_link: forked_project_link, creator_id: @forking_user.id , namespace: @forking_user.namespace) |
19 | 19 | |
20 | 20 | forked_project_link.forked_from_project = @project |
... | ... | @@ -114,7 +114,7 @@ class ProjectForkedMergeRequests < Spinach::FeatureSteps |
114 | 114 | end |
115 | 115 | |
116 | 116 | step 'project "Forked Shop" has push event' do |
117 | - @forked_project = Project.find_by_name("Forked Shop") | |
117 | + @forked_project = Project.find_by(name: "Forked Shop") | |
118 | 118 | |
119 | 119 | data = { |
120 | 120 | before: "0000000000000000000000000000000000000000", |
... | ... | @@ -172,7 +172,7 @@ class ProjectForkedMergeRequests < Spinach::FeatureSteps |
172 | 172 | end |
173 | 173 | |
174 | 174 | def project |
175 | - @project ||= Project.find_by_name!("Shop") | |
175 | + @project ||= Project.find_by!(name: "Shop") | |
176 | 176 | end |
177 | 177 | |
178 | 178 | # Verify a link is generated against the correct project | ... | ... |
features/steps/project/project_graph.rb
features/steps/project/project_issue_tracker.rb
... | ... | @@ -4,7 +4,7 @@ class ProjectIssueTracker < Spinach::FeatureSteps |
4 | 4 | include SharedPaths |
5 | 5 | |
6 | 6 | step 'project "Shop" has issues enabled' do |
7 | - @project = Project.find_by_name "Shop" | |
7 | + @project = Project.find_by(name: "Shop") | |
8 | 8 | @project ||= create(:project_with_code, name: "Shop", namespace: @user.namespace) |
9 | 9 | @project.issues_enabled = true |
10 | 10 | end | ... | ... |
features/steps/project/project_issues.rb
... | ... | @@ -54,7 +54,7 @@ class ProjectIssues < Spinach::FeatureSteps |
54 | 54 | end |
55 | 55 | |
56 | 56 | Then 'I should see issue "500 error on profile"' do |
57 | - issue = Issue.find_by_title("500 error on profile") | |
57 | + issue = Issue.find_by(title: "500 error on profile") | |
58 | 58 | page.should have_content issue.title |
59 | 59 | page.should have_content issue.author_name |
60 | 60 | page.should have_content issue.project.name |
... | ... | @@ -81,14 +81,14 @@ class ProjectIssues < Spinach::FeatureSteps |
81 | 81 | end |
82 | 82 | |
83 | 83 | Given 'project "Shop" has milestone "v2.2"' do |
84 | - project = Project.find_by_name("Shop") | |
84 | + project = Project.find_by(name: "Shop") | |
85 | 85 | milestone = create(:milestone, title: "v2.2", project: project) |
86 | 86 | |
87 | 87 | 3.times { create(:issue, project: project, milestone: milestone) } |
88 | 88 | end |
89 | 89 | |
90 | 90 | And 'project "Shop" has milestone "v3.0"' do |
91 | - project = Project.find_by_name("Shop") | |
91 | + project = Project.find_by(name: "Shop") | |
92 | 92 | milestone = create(:milestone, title: "v3.0", project: project) |
93 | 93 | |
94 | 94 | 3.times { create(:issue, project: project, milestone: milestone) } |
... | ... | @@ -104,20 +104,20 @@ class ProjectIssues < Spinach::FeatureSteps |
104 | 104 | end |
105 | 105 | |
106 | 106 | When 'I select first assignee from "Shop" project' do |
107 | - project = Project.find_by_name "Shop" | |
107 | + project = Project.find_by(name: "Shop") | |
108 | 108 | first_assignee = project.users.first |
109 | 109 | select first_assignee.name, from: "assignee_id" |
110 | 110 | end |
111 | 111 | |
112 | 112 | Then 'I should see first assignee from "Shop" as selected assignee' do |
113 | 113 | issues_assignee_selector = "#issue_assignee_id_chzn > a" |
114 | - project = Project.find_by_name "Shop" | |
114 | + project = Project.find_by(name: "Shop") | |
115 | 115 | assignee_name = project.users.first.name |
116 | 116 | page.find(issues_assignee_selector).should have_content(assignee_name) |
117 | 117 | end |
118 | 118 | |
119 | 119 | And 'project "Shop" have "Release 0.4" open issue' do |
120 | - project = Project.find_by_name("Shop") | |
120 | + project = Project.find_by(name: "Shop") | |
121 | 121 | create(:issue, |
122 | 122 | title: "Release 0.4", |
123 | 123 | project: project, |
... | ... | @@ -125,7 +125,7 @@ class ProjectIssues < Spinach::FeatureSteps |
125 | 125 | end |
126 | 126 | |
127 | 127 | And 'project "Shop" have "Tweet control" open issue' do |
128 | - project = Project.find_by_name("Shop") | |
128 | + project = Project.find_by(name: "Shop") | |
129 | 129 | create(:issue, |
130 | 130 | title: "Tweet control", |
131 | 131 | project: project, |
... | ... | @@ -133,7 +133,7 @@ class ProjectIssues < Spinach::FeatureSteps |
133 | 133 | end |
134 | 134 | |
135 | 135 | And 'project "Shop" have "Release 0.3" closed issue' do |
136 | - project = Project.find_by_name("Shop") | |
136 | + project = Project.find_by(name: "Shop") | |
137 | 137 | create(:closed_issue, |
138 | 138 | title: "Release 0.3", |
139 | 139 | project: project, | ... | ... |
features/steps/project/project_labels.rb
... | ... | @@ -16,7 +16,7 @@ class ProjectLabels < Spinach::FeatureSteps |
16 | 16 | end |
17 | 17 | |
18 | 18 | And 'project "Shop" have issues tags: "bug", "feature"' do |
19 | - project = Project.find_by_name("Shop") | |
19 | + project = Project.find_by(name: "Shop") | |
20 | 20 | ['bug', 'feature'].each do |label| |
21 | 21 | create(:issue, project: project, label_list: label) |
22 | 22 | end | ... | ... |
features/steps/project/project_markdown_render.rb
... | ... | @@ -3,7 +3,7 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps |
3 | 3 | include SharedPaths |
4 | 4 | |
5 | 5 | And 'I own project "Delta"' do |
6 | - @project = Project.find_by_name "Delta" | |
6 | + @project = Project.find_by(name: "Delta") | |
7 | 7 | @project ||= create(:project_with_code, name: "Delta", namespace: @user.namespace) |
8 | 8 | @project.team << [@user, :master] |
9 | 9 | end | ... | ... |
features/steps/project/project_merge_requests.rb
... | ... | @@ -27,7 +27,7 @@ class ProjectMergeRequests < Spinach::FeatureSteps |
27 | 27 | end |
28 | 28 | |
29 | 29 | step 'I should see closed merge request "Bug NS-04"' do |
30 | - merge_request = MergeRequest.find_by_title!("Bug NS-04") | |
30 | + merge_request = MergeRequest.find_by!(title: "Bug NS-04") | |
31 | 31 | merge_request.closed?.should be_true |
32 | 32 | page.should have_content "Closed by" |
33 | 33 | end |
... | ... | @@ -180,11 +180,11 @@ class ProjectMergeRequests < Spinach::FeatureSteps |
180 | 180 | end |
181 | 181 | |
182 | 182 | def project |
183 | - @project ||= Project.find_by_name!("Shop") | |
183 | + @project ||= Project.find_by!(name: "Shop") | |
184 | 184 | end |
185 | 185 | |
186 | 186 | def merge_request |
187 | - @merge_request ||= MergeRequest.find_by_title!("Bug NS-05") | |
187 | + @merge_request ||= MergeRequest.find_by!(title: "Bug NS-05") | |
188 | 188 | end |
189 | 189 | |
190 | 190 | def init_diff_note | ... | ... |
features/steps/project/project_milestones.rb
... | ... | @@ -4,7 +4,7 @@ class ProjectMilestones < Spinach::FeatureSteps |
4 | 4 | include SharedPaths |
5 | 5 | |
6 | 6 | Then 'I should see milestone "v2.2"' do |
7 | - milestone = @project.milestones.find_by_title("v2.2") | |
7 | + milestone = @project.milestones.find_by(title: "v2.2") | |
8 | 8 | page.should have_content(milestone.title[0..10]) |
9 | 9 | page.should have_content(milestone.expires_at) |
10 | 10 | page.should have_content("Browse Issues") |
... | ... | @@ -24,22 +24,22 @@ class ProjectMilestones < Spinach::FeatureSteps |
24 | 24 | end |
25 | 25 | |
26 | 26 | Then 'I should see milestone "v2.3"' do |
27 | - milestone = @project.milestones.find_by_title("v2.3") | |
27 | + milestone = @project.milestones.find_by(title: "v2.3") | |
28 | 28 | page.should have_content(milestone.title[0..10]) |
29 | 29 | page.should have_content(milestone.expires_at) |
30 | 30 | page.should have_content("Browse Issues") |
31 | 31 | end |
32 | 32 | |
33 | 33 | And 'project "Shop" has milestone "v2.2"' do |
34 | - project = Project.find_by_name("Shop") | |
34 | + project = Project.find_by(name: "Shop") | |
35 | 35 | milestone = create(:milestone, title: "v2.2", project: project) |
36 | 36 | |
37 | 37 | 3.times { create(:issue, project: project, milestone: milestone) } |
38 | 38 | end |
39 | 39 | |
40 | 40 | Given 'the milestone has open and closed issues' do |
41 | - project = Project.find_by_name("Shop") | |
42 | - milestone = project.milestones.find_by_title('v2.2') | |
41 | + project = Project.find_by(name: "Shop") | |
42 | + milestone = project.milestones.find_by(title: 'v2.2') | |
43 | 43 | |
44 | 44 | # 3 Open issues created above; create one closed issue |
45 | 45 | create(:closed_issue, project: project, milestone: milestone) | ... | ... |
features/steps/project/project_network_graph.rb
... | ... | @@ -10,7 +10,7 @@ class ProjectNetworkGraph < Spinach::FeatureSteps |
10 | 10 | # Stub Graph max_size to speed up test (10 commits vs. 650) |
11 | 11 | Network::Graph.stub(max_count: 10) |
12 | 12 | |
13 | - project = Project.find_by_name("Shop") | |
13 | + project = Project.find_by(name: "Shop") | |
14 | 14 | visit project_network_path(project, "master") |
15 | 15 | end |
16 | 16 | ... | ... |
features/steps/project/project_snippets.rb
... | ... | @@ -90,10 +90,10 @@ class ProjectSnippets < Spinach::FeatureSteps |
90 | 90 | end |
91 | 91 | |
92 | 92 | def project |
93 | - @project ||= Project.find_by_name!("Shop") | |
93 | + @project ||= Project.find_by!(name: "Shop") | |
94 | 94 | end |
95 | 95 | |
96 | 96 | def project_snippet |
97 | - @project_snippet ||= ProjectSnippet.find_by_title!("Snippet One") | |
97 | + @project_snippet ||= ProjectSnippet.find_by!(title: "Snippet one") | |
98 | 98 | end |
99 | 99 | end | ... | ... |
features/steps/project/project_team_management.rb
... | ... | @@ -10,7 +10,7 @@ class ProjectTeamManagement < Spinach::FeatureSteps |
10 | 10 | end |
11 | 11 | |
12 | 12 | And 'I should see "Sam" in team list' do |
13 | - user = User.find_by_name("Sam") | |
13 | + user = User.find_by(name: "Sam") | |
14 | 14 | page.should have_content(user.name) |
15 | 15 | page.should have_content(user.username) |
16 | 16 | end |
... | ... | @@ -20,7 +20,7 @@ class ProjectTeamManagement < Spinach::FeatureSteps |
20 | 20 | end |
21 | 21 | |
22 | 22 | And 'I select "Mike" as "Reporter"' do |
23 | - user = User.find_by_name("Mike") | |
23 | + user = User.find_by(name: "Mike") | |
24 | 24 | |
25 | 25 | select2(user.id, from: "#user_ids", multiple: true) |
26 | 26 | within "#new_team_member" do |
... | ... | @@ -42,7 +42,7 @@ class ProjectTeamManagement < Spinach::FeatureSteps |
42 | 42 | end |
43 | 43 | |
44 | 44 | And 'I change "Sam" role to "Reporter"' do |
45 | - user = User.find_by_name("Sam") | |
45 | + user = User.find_by(name: "Sam") | |
46 | 46 | within "#user_#{user.id}" do |
47 | 47 | select "Reporter", from: "team_member_project_access" |
48 | 48 | end |
... | ... | @@ -59,7 +59,7 @@ class ProjectTeamManagement < Spinach::FeatureSteps |
59 | 59 | end |
60 | 60 | |
61 | 61 | And 'I should not see "Sam" in team list' do |
62 | - user = User.find_by_name("Sam") | |
62 | + user = User.find_by(name: "Sam") | |
63 | 63 | page.should_not have_content(user.name) |
64 | 64 | page.should_not have_content(user.username) |
65 | 65 | end |
... | ... | @@ -73,8 +73,8 @@ class ProjectTeamManagement < Spinach::FeatureSteps |
73 | 73 | end |
74 | 74 | |
75 | 75 | And '"Sam" is "Shop" developer' do |
76 | - user = User.find_by_name("Sam") | |
77 | - project = Project.find_by_name("Shop") | |
76 | + user = User.find_by(name: "Sam") | |
77 | + project = Project.find_by(name: "Shop") | |
78 | 78 | project.team << [user, :developer] |
79 | 79 | end |
80 | 80 | |
... | ... | @@ -84,8 +84,8 @@ class ProjectTeamManagement < Spinach::FeatureSteps |
84 | 84 | end |
85 | 85 | |
86 | 86 | And '"Mike" is "Website" reporter' do |
87 | - user = User.find_by_name("Mike") | |
88 | - project = Project.find_by_name("Website") | |
87 | + user = User.find_by(name: "Mike") | |
88 | + project = Project.find_by(name: "Website") | |
89 | 89 | project.team << [user, :reporter] |
90 | 90 | end |
91 | 91 | |
... | ... | @@ -94,13 +94,13 @@ class ProjectTeamManagement < Spinach::FeatureSteps |
94 | 94 | end |
95 | 95 | |
96 | 96 | When 'I submit "Website" project for import team' do |
97 | - project = Project.find_by_name("Website") | |
97 | + project = Project.find_by(name: "Website") | |
98 | 98 | select project.name_with_namespace, from: 'source_project_id' |
99 | 99 | click_button 'Import' |
100 | 100 | end |
101 | 101 | |
102 | 102 | step 'I click cancel link for "Sam"' do |
103 | - within "#user_#{User.find_by_name('Sam').id}" do | |
103 | + within "#user_#{User.find_by(name: 'Sam').id}" do | |
104 | 104 | click_link('Remove user from team') |
105 | 105 | end |
106 | 106 | end | ... | ... |
features/steps/project/redirects.rb
... | ... | @@ -12,7 +12,7 @@ class Spinach::Features::ProjectRedirects < Spinach::FeatureSteps |
12 | 12 | end |
13 | 13 | |
14 | 14 | step 'I visit project "Community" page' do |
15 | - project = Project.find_by_name('Community') | |
15 | + project = Project.find_by(name: 'Community') | |
16 | 16 | visit project_path(project) |
17 | 17 | end |
18 | 18 | |
... | ... | @@ -23,12 +23,12 @@ class Spinach::Features::ProjectRedirects < Spinach::FeatureSteps |
23 | 23 | end |
24 | 24 | |
25 | 25 | step 'I visit project "Enterprise" page' do |
26 | - project = Project.find_by_name('Enterprise') | |
26 | + project = Project.find_by(name: 'Enterprise') | |
27 | 27 | visit project_path(project) |
28 | 28 | end |
29 | 29 | |
30 | 30 | step 'I visit project "CommunityDoesNotExist" page' do |
31 | - project = Project.find_by_name('Community') | |
31 | + project = Project.find_by(name: 'Community') | |
32 | 32 | visit project_path(project) + 'DoesNotExist' |
33 | 33 | end |
34 | 34 | end | ... | ... |
features/steps/public/projects_feature.rb
... | ... | @@ -33,12 +33,12 @@ class Spinach::Features::PublicProjectsFeature < Spinach::FeatureSteps |
33 | 33 | end |
34 | 34 | |
35 | 35 | step 'I visit empty project page' do |
36 | - project = Project.find_by_name('Empty Public Project') | |
36 | + project = Project.find_by(name: 'Empty Public Project') | |
37 | 37 | visit project_path(project) |
38 | 38 | end |
39 | 39 | |
40 | 40 | step 'I visit project "Community" page' do |
41 | - project = Project.find_by_name('Community') | |
41 | + project = Project.find_by(name: 'Community') | |
42 | 42 | visit project_path(project) |
43 | 43 | end |
44 | 44 | |
... | ... | @@ -47,14 +47,14 @@ class Spinach::Features::PublicProjectsFeature < Spinach::FeatureSteps |
47 | 47 | end |
48 | 48 | |
49 | 49 | step 'I should see empty public project details with http clone info' do |
50 | - project = Project.find_by_name('Empty Public Project') | |
50 | + project = Project.find_by(name: 'Empty Public Project') | |
51 | 51 | page.all(:css, '.git-empty .clone').each do |element| |
52 | 52 | element.text.should include(project.http_url_to_repo) |
53 | 53 | end |
54 | 54 | end |
55 | 55 | |
56 | 56 | step 'I should see empty public project details with ssh clone info' do |
57 | - project = Project.find_by_name('Empty Public Project') | |
57 | + project = Project.find_by(name: 'Empty Public Project') | |
58 | 58 | page.all(:css, '.git-empty .clone').each do |element| |
59 | 59 | element.text.should include(project.url_to_repo) |
60 | 60 | end |
... | ... | @@ -65,7 +65,7 @@ class Spinach::Features::PublicProjectsFeature < Spinach::FeatureSteps |
65 | 65 | end |
66 | 66 | |
67 | 67 | step 'I visit project "Enterprise" page' do |
68 | - project = Project.find_by_name('Enterprise') | |
68 | + project = Project.find_by(name: 'Enterprise') | |
69 | 69 | visit project_path(project) |
70 | 70 | end |
71 | 71 | |
... | ... | @@ -88,7 +88,7 @@ class Spinach::Features::PublicProjectsFeature < Spinach::FeatureSteps |
88 | 88 | end |
89 | 89 | |
90 | 90 | step 'I visit project "Internal" page' do |
91 | - project = Project.find_by_name('Internal') | |
91 | + project = Project.find_by(name: 'Internal') | |
92 | 92 | visit project_path(project) |
93 | 93 | end |
94 | 94 | |
... | ... | @@ -99,12 +99,12 @@ class Spinach::Features::PublicProjectsFeature < Spinach::FeatureSteps |
99 | 99 | end |
100 | 100 | |
101 | 101 | step 'I should see an http link to the repository' do |
102 | - project = Project.find_by_name 'Community' | |
102 | + project = Project.find_by(name: 'Community') | |
103 | 103 | page.should have_field('project_clone', with: project.http_url_to_repo) |
104 | 104 | end |
105 | 105 | |
106 | 106 | step 'I should see an ssh link to the repository' do |
107 | - project = Project.find_by_name 'Community' | |
107 | + project = Project.find_by(name: 'Community') | |
108 | 108 | page.should have_field('project_clone', with: project.url_to_repo) |
109 | 109 | end |
110 | 110 | end | ... | ... |
features/steps/shared/paths.rb
... | ... | @@ -241,7 +241,7 @@ module SharedPaths |
241 | 241 | end |
242 | 242 | |
243 | 243 | step 'I visit issue page "Release 0.4"' do |
244 | - issue = Issue.find_by_title("Release 0.4") | |
244 | + issue = Issue.find_by(title: "Release 0.4") | |
245 | 245 | visit project_issue_path(issue.project, issue) |
246 | 246 | end |
247 | 247 | |
... | ... | @@ -250,12 +250,12 @@ module SharedPaths |
250 | 250 | end |
251 | 251 | |
252 | 252 | step 'I visit merge request page "Bug NS-04"' do |
253 | - mr = MergeRequest.find_by_title("Bug NS-04") | |
253 | + mr = MergeRequest.find_by(title: "Bug NS-04") | |
254 | 254 | visit project_merge_request_path(mr.target_project, mr) |
255 | 255 | end |
256 | 256 | |
257 | 257 | step 'I visit merge request page "Bug NS-05"' do |
258 | - mr = MergeRequest.find_by_title("Bug NS-05") | |
258 | + mr = MergeRequest.find_by(title: "Bug NS-05") | |
259 | 259 | visit project_merge_request_path(mr.target_project, mr) |
260 | 260 | end |
261 | 261 | |
... | ... | @@ -292,7 +292,7 @@ module SharedPaths |
292 | 292 | end |
293 | 293 | |
294 | 294 | step 'I visit public page for "Community" project' do |
295 | - visit public_project_path(Project.find_by_name("Community")) | |
295 | + visit public_project_path(Project.find_by(name: "Community")) | |
296 | 296 | end |
297 | 297 | |
298 | 298 | # ---------------------------------------- |
... | ... | @@ -316,6 +316,6 @@ module SharedPaths |
316 | 316 | end |
317 | 317 | |
318 | 318 | def project |
319 | - project = Project.find_by_name!("Shop") | |
319 | + project = Project.find_by!(name: "Shop") | |
320 | 320 | end |
321 | 321 | end | ... | ... |
features/steps/shared/project.rb
... | ... | @@ -9,20 +9,20 @@ module SharedProject |
9 | 9 | |
10 | 10 | # Create a specific project called "Shop" |
11 | 11 | And 'I own project "Shop"' do |
12 | - @project = Project.find_by_name "Shop" | |
12 | + @project = Project.find_by(name: "Shop") | |
13 | 13 | @project ||= create(:project_with_code, name: "Shop", namespace: @user.namespace) |
14 | 14 | @project.team << [@user, :master] |
15 | 15 | end |
16 | 16 | |
17 | 17 | # Create another specific project called "Forum" |
18 | 18 | And 'I own project "Forum"' do |
19 | - @project = Project.find_by_name "Forum" | |
19 | + @project = Project.find_by(name: "Forum") | |
20 | 20 | @project ||= create(:project_with_code, name: "Forum", namespace: @user.namespace, path: 'forum_project') |
21 | 21 | @project.team << [@user, :master] |
22 | 22 | end |
23 | 23 | |
24 | 24 | And 'project "Shop" has push event' do |
25 | - @project = Project.find_by_name("Shop") | |
25 | + @project = Project.find_by(name: "Shop") | |
26 | 26 | |
27 | 27 | data = { |
28 | 28 | before: "0000000000000000000000000000000000000000", |
... | ... | @@ -48,7 +48,7 @@ module SharedProject |
48 | 48 | end |
49 | 49 | |
50 | 50 | Then 'I should see project "Shop" activity feed' do |
51 | - project = Project.find_by_name("Shop") | |
51 | + project = Project.find_by(name: "Shop") | |
52 | 52 | page.should have_content "#{@user.name} pushed new branch new_design at #{project.name_with_namespace}" |
53 | 53 | end |
54 | 54 | ... | ... |
features/steps/snippets/discover_snippets.rb
features/steps/snippets/snippets.rb
features/steps/snippets/user_snippets.rb
lib/api/deploy_keys.rb
... | ... | @@ -38,14 +38,14 @@ module API |
38 | 38 | attrs[:key].strip! |
39 | 39 | |
40 | 40 | # check if key already exist in project |
41 | - key = user_project.deploy_keys.find_by_key(attrs[:key]) | |
41 | + key = user_project.deploy_keys.find_by(key: attrs[:key]) | |
42 | 42 | if key |
43 | 43 | present key, with: Entities::SSHKey |
44 | 44 | return |
45 | 45 | end |
46 | 46 | |
47 | 47 | # Check for available deploy keys in other projects |
48 | - key = current_user.accessible_deploy_keys.find_by_key(attrs[:key]) | |
48 | + key = current_user.accessible_deploy_keys.find_by(key: attrs[:key]) | |
49 | 49 | if key |
50 | 50 | user_project.deploy_keys << key |
51 | 51 | present key, with: Entities::SSHKey | ... | ... |
lib/api/entities.rb
... | ... | @@ -48,19 +48,19 @@ module API |
48 | 48 | |
49 | 49 | class ProjectMember < UserBasic |
50 | 50 | expose :project_access, as: :access_level do |user, options| |
51 | - options[:project].users_projects.find_by_user_id(user.id).project_access | |
51 | + options[:project].users_projects.find_by(user_id: user.id).project_access | |
52 | 52 | end |
53 | 53 | end |
54 | 54 | |
55 | 55 | class TeamMember < UserBasic |
56 | 56 | expose :permission, as: :access_level do |user, options| |
57 | - options[:user_team].user_team_user_relationships.find_by_user_id(user.id).permission | |
57 | + options[:user_team].user_team_user_relationships.find_by(user_id: user.id).permission | |
58 | 58 | end |
59 | 59 | end |
60 | 60 | |
61 | 61 | class TeamProject < Project |
62 | 62 | expose :greatest_access, as: :greatest_access_level do |project, options| |
63 | - options[:user_team].user_team_project_relationships.find_by_project_id(project.id).greatest_access | |
63 | + options[:user_team].user_team_project_relationships.find_by(project_id: project.id).greatest_access | |
64 | 64 | end |
65 | 65 | end |
66 | 66 | |
... | ... | @@ -74,7 +74,7 @@ module API |
74 | 74 | |
75 | 75 | class GroupMember < UserBasic |
76 | 76 | expose :group_access, as: :access_level do |user, options| |
77 | - options[:group].users_groups.find_by_user_id(user.id).group_access | |
77 | + options[:group].users_groups.find_by(user_id: user.id).group_access | |
78 | 78 | end |
79 | 79 | end |
80 | 80 | ... | ... |
lib/api/groups.rb
... | ... | @@ -121,11 +121,11 @@ module API |
121 | 121 | render_api_error!("Wrong access level", 422) |
122 | 122 | end |
123 | 123 | group = find_group(params[:id]) |
124 | - if group.users_groups.find_by_user_id(params[:user_id]) | |
124 | + if group.users_groups.find_by(user_id: params[:user_id]) | |
125 | 125 | render_api_error!("Already exists", 409) |
126 | 126 | end |
127 | 127 | group.add_users([params[:user_id]], params[:access_level]) |
128 | - member = group.users_groups.find_by_user_id(params[:user_id]) | |
128 | + member = group.users_groups.find_by(user_id: params[:user_id]) | |
129 | 129 | present member.user, with: Entities::GroupMember, group: group |
130 | 130 | end |
131 | 131 | |
... | ... | @@ -139,7 +139,7 @@ module API |
139 | 139 | # DELETE /groups/:id/members/:user_id |
140 | 140 | delete ":id/members/:user_id" do |
141 | 141 | group = find_group(params[:id]) |
142 | - member = group.users_groups.find_by_user_id(params[:user_id]) | |
142 | + member = group.users_groups.find_by(user_id: params[:user_id]) | |
143 | 143 | if member.nil? |
144 | 144 | render_api_error!("404 Not Found - user_id:#{params[:user_id]} not a member of group #{group.name}",404) |
145 | 145 | else | ... | ... |
lib/api/helpers.rb
... | ... | @@ -7,7 +7,7 @@ module API |
7 | 7 | |
8 | 8 | def current_user |
9 | 9 | private_token = (params[PRIVATE_TOKEN_PARAM] || env[PRIVATE_TOKEN_HEADER]).to_s |
10 | - @current_user ||= User.find_by_authentication_token(private_token) | |
10 | + @current_user ||= User.find_by(authentication_token: private_token) | |
11 | 11 | identifier = sudo_identifier() |
12 | 12 | |
13 | 13 | # If the sudo is the current user do nothing |
... | ... | @@ -47,7 +47,7 @@ module API |
47 | 47 | end |
48 | 48 | |
49 | 49 | def find_project(id) |
50 | - project = Project.find_by_id(id) || Project.find_with_namespace(id) | |
50 | + project = Project.find_by(id: id) || Project.find_with_namespace(id) | |
51 | 51 | |
52 | 52 | if project && can?(current_user, :read_project, project) |
53 | 53 | project | ... | ... |
lib/api/merge_requests.rb
... | ... | @@ -81,7 +81,7 @@ module API |
81 | 81 | merge_request.target_project = user_project |
82 | 82 | else |
83 | 83 | if target_matches_fork(target_project_id,user_project) |
84 | - merge_request.target_project = Project.find_by_id(attrs[:target_project_id]) | |
84 | + merge_request.target_project = Project.find_by(id: attrs[:target_project_id]) | |
85 | 85 | else |
86 | 86 | render_api_error!('(Bad Request) Specified target project that is not the source project, or the source fork of the project.', 400) |
87 | 87 | end | ... | ... |
lib/api/projects.rb
... | ... | @@ -266,7 +266,7 @@ module API |
266 | 266 | authorize! :admin_project, user_project |
267 | 267 | required_attributes! [:access_level] |
268 | 268 | |
269 | - team_member = user_project.users_projects.find_by_user_id(params[:user_id]) | |
269 | + team_member = user_project.users_projects.find_by(user_id: params[:user_id]) | |
270 | 270 | not_found!("User can not be found") if team_member.nil? |
271 | 271 | |
272 | 272 | if team_member.update_attributes(project_access: params[:access_level]) |
... | ... | @@ -286,7 +286,7 @@ module API |
286 | 286 | # DELETE /projects/:id/members/:user_id |
287 | 287 | delete ":id/members/:user_id" do |
288 | 288 | authorize! :admin_project, user_project |
289 | - team_member = user_project.users_projects.find_by_user_id(params[:user_id]) | |
289 | + team_member = user_project.users_projects.find_by(user_id: params[:user_id]) | |
290 | 290 | unless team_member.nil? |
291 | 291 | team_member.destroy |
292 | 292 | else | ... | ... |
lib/api/repositories.rb
... | ... | @@ -51,7 +51,7 @@ module API |
51 | 51 | |
52 | 52 | @branch = user_project.repository.find_branch(params[:branch]) |
53 | 53 | not_found! unless @branch |
54 | - protected_branch = user_project.protected_branches.find_by_name(@branch.name) | |
54 | + protected_branch = user_project.protected_branches.find_by(name: @branch.name) | |
55 | 55 | user_project.protected_branches.create(name: @branch.name) unless protected_branch |
56 | 56 | |
57 | 57 | present @branch, with: Entities::RepoObject, project: user_project |
... | ... | @@ -69,7 +69,7 @@ module API |
69 | 69 | |
70 | 70 | @branch = user_project.repository.find_branch(params[:branch]) |
71 | 71 | not_found! unless @branch |
72 | - protected_branch = user_project.protected_branches.find_by_name(@branch.name) | |
72 | + protected_branch = user_project.protected_branches.find_by(name: @branch.name) | |
73 | 73 | protected_branch.destroy if protected_branch |
74 | 74 | |
75 | 75 | present @branch, with: Entities::RepoObject, project: user_project | ... | ... |
lib/api/users.rb
lib/gitlab/auth.rb
lib/gitlab/identifier.rb
... | ... | @@ -6,17 +6,17 @@ module Gitlab |
6 | 6 | if identifier.blank? |
7 | 7 | # Local push from gitlab |
8 | 8 | email = project.repository.commit(newrev).author_email rescue nil |
9 | - User.find_by_email(email) if email | |
9 | + User.find_by(email: email) if email | |
10 | 10 | |
11 | 11 | elsif identifier =~ /\Auser-\d+\Z/ |
12 | 12 | # git push over http |
13 | 13 | user_id = identifier.gsub("user-", "") |
14 | - User.find_by_id(user_id) | |
14 | + User.find_by(id: user_id) | |
15 | 15 | |
16 | 16 | elsif identifier =~ /\Akey-\d+\Z/ |
17 | 17 | # git push over ssh |
18 | 18 | key_id = identifier.gsub("key-", "") |
19 | - Key.find_by_id(key_id).try(:user) | |
19 | + Key.find_by(id: key_id).try(:user) | |
20 | 20 | end |
21 | 21 | end |
22 | 22 | end | ... | ... |
lib/gitlab/ldap/user.rb
... | ... | @@ -44,13 +44,13 @@ module Gitlab |
44 | 44 | end |
45 | 45 | |
46 | 46 | def find_user(email) |
47 | - user = model.find_by_email(email) | |
47 | + user = model.find_by(email: email) | |
48 | 48 | |
49 | 49 | # If no user found and allow_username_or_email_login is true |
50 | 50 | # we look for user by extracting part of their email |
51 | 51 | if !user && email && ldap_conf['allow_username_or_email_login'] |
52 | 52 | uname = email.partition('@').first |
53 | - user = model.find_by_username(uname) | |
53 | + user = model.find_by(username: uname) | |
54 | 54 | end |
55 | 55 | |
56 | 56 | user | ... | ... |
lib/tasks/gitlab/bulk_add_permission.rake
... | ... | @@ -15,7 +15,7 @@ namespace :gitlab do |
15 | 15 | |
16 | 16 | desc "GITLAB | Add a specific user to all projects (as a developer)" |
17 | 17 | task :user_to_projects, [:email] => :environment do |t, args| |
18 | - user = User.find_by_email args.email | |
18 | + user = User.find_by(email: args.email) | |
19 | 19 | project_ids = Project.pluck(:id) |
20 | 20 | puts "Importing #{user.email} users into #{project_ids.size} projects" |
21 | 21 | UsersProject.add_users_into_projects(project_ids, Array.wrap(user.id), UsersProject::DEVELOPER) | ... | ... |
lib/tasks/gitlab/enable_namespaces.rake
... | ... | @@ -43,13 +43,13 @@ namespace :gitlab do |
43 | 43 | username.gsub!("+", ".") |
44 | 44 | |
45 | 45 | # return username if no matches |
46 | - return username unless User.find_by_username(username) | |
46 | + return username unless User.find_by(username: username) | |
47 | 47 | |
48 | 48 | # look for same username |
49 | 49 | (1..10).each do |i| |
50 | 50 | suffixed_username = "#{username}#{i}" |
51 | 51 | |
52 | - return suffixed_username unless User.find_by_username(suffixed_username) | |
52 | + return suffixed_username unless User.find_by(username: suffixed_username) | |
53 | 53 | end |
54 | 54 | end |
55 | 55 | ... | ... |
lib/tasks/gitlab/import.rake
spec/lib/gitlab/ldap/ldap_user_auth_spec.rb
... | ... | @@ -25,7 +25,7 @@ describe Gitlab::LDAP do |
25 | 25 | it "should update credentials by email if missing uid" do |
26 | 26 | user = double('User') |
27 | 27 | User.stub find_by_extern_uid_and_provider: nil |
28 | - User.stub find_by_email: user | |
28 | + User.stub(:find_by).with(hash_including(email: anything())) { user } | |
29 | 29 | user.should_receive :update_attributes |
30 | 30 | gl_auth.find_or_create(@auth) |
31 | 31 | end |
... | ... | @@ -35,8 +35,8 @@ describe Gitlab::LDAP do |
35 | 35 | value = Gitlab.config.ldap.allow_username_or_email_login |
36 | 36 | Gitlab.config.ldap['allow_username_or_email_login'] = true |
37 | 37 | User.stub find_by_extern_uid_and_provider: nil |
38 | - User.stub find_by_email: nil | |
39 | - User.stub find_by_username: user | |
38 | + User.stub(:find_by).with(hash_including(email: anything())) { nil } | |
39 | + User.stub(:find_by).with(hash_including(username: anything())) { user } | |
40 | 40 | user.should_receive :update_attributes |
41 | 41 | gl_auth.find_or_create(@auth) |
42 | 42 | Gitlab.config.ldap['allow_username_or_email_login'] = value |
... | ... | @@ -47,8 +47,8 @@ describe Gitlab::LDAP do |
47 | 47 | value = Gitlab.config.ldap.allow_username_or_email_login |
48 | 48 | Gitlab.config.ldap['allow_username_or_email_login'] = false |
49 | 49 | User.stub find_by_extern_uid_and_provider: nil |
50 | - User.stub find_by_email: nil | |
51 | - User.stub find_by_username: user | |
50 | + User.stub(:find_by).with(hash_including(email: anything())) { nil } | |
51 | + User.stub(:find_by).with(hash_including(username: anything())) { user } | |
52 | 52 | user.should_not_receive :update_attributes |
53 | 53 | gl_auth.find_or_create(@auth) |
54 | 54 | Gitlab.config.ldap['allow_username_or_email_login'] = value | ... | ... |
spec/requests/api/users_spec.rb
... | ... | @@ -93,7 +93,7 @@ describe API::API do |
93 | 93 | expect { |
94 | 94 | post api("/users", admin), attr |
95 | 95 | }.to change { User.count }.by(1) |
96 | - user = User.find_by_username(attr[:username]) | |
96 | + user = User.find_by(username: attr[:username]) | |
97 | 97 | user.projects_limit.should == limit |
98 | 98 | user.theme_id.should == Gitlab::Theme::MARS |
99 | 99 | Gitlab.config.gitlab.unstub(:default_projects_limit) | ... | ... |
spec/workers/post_receive_spec.rb