Commit a3f645ef authored by skv's avatar skv

Remove deprecated finders

parent 3fe578a7
......@@ -14,7 +14,6 @@ gem "protected_attributes"
gem 'rails-observers'
gem 'actionpack-page_caching'
gem 'actionpack-action_caching'
gem 'activerecord-deprecated_finders'
# Supported DBs
gem "mysql2", group: :mysql
......
......@@ -549,7 +549,6 @@ PLATFORMS
DEPENDENCIES
actionpack-action_caching
actionpack-page_caching
activerecord-deprecated_finders
acts-as-taggable-on
annotate (~> 2.6.0.beta2)
asciidoctor
......
......@@ -52,6 +52,6 @@ class Admin::GroupsController < Admin::ApplicationController
private
def group
@group = Group.find_by_path(params[:id])
@group = Group.find_by(path: params[:id])
end
end
......@@ -5,7 +5,7 @@ class Admin::ProjectsController < Admin::ApplicationController
def index
owner_id = params[:owner_id]
user = User.find_by_id(owner_id)
user = User.find_by(id: owner_id)
@projects = user ? user.owned_projects : Project.all
@projects = @projects.where("visibility_level IN (?)", params[:visibility_levels]) if params[:visibility_levels].present?
......
......@@ -100,6 +100,6 @@ class Admin::UsersController < Admin::ApplicationController
protected
def user
@user ||= User.find_by_username!(params[:id])
@user ||= User.find_by!(username: params[:id])
end
end
......@@ -41,7 +41,7 @@ class DashboardController < ApplicationController
current_user.authorized_projects
end
@projects = @projects.where(namespace_id: Group.find_by_name(params[:group])) if params[:group].present?
@projects = @projects.where(namespace_id: Group.find_by(name: params[:group])) if params[:group].present?
@projects = @projects.where(visibility_level: params[:visibility_level]) if params[:visibility_level].present?
@projects = @projects.includes(:namespace)
@projects = @projects.tagged_with(params[:label]) if params[:label].present?
......
......@@ -87,7 +87,7 @@ class GroupsController < ApplicationController
protected
def group
@group ||= Group.find_by_path(params[:id])
@group ||= Group.find_by(path: params[:id])
end
def projects
......
......@@ -19,6 +19,6 @@ class Profiles::GroupsController < ApplicationController
private
def group
@group ||= Group.find_by_path(params[:id])
@group ||= Group.find_by(path: params[:id])
end
end
......@@ -97,7 +97,7 @@ class Projects::IssuesController < Projects::ApplicationController
def issue
@issue ||= begin
@project.issues.find_by_iid!(params[:id])
@project.issues.find_by!(iid: params[:id])
rescue ActiveRecord::RecordNotFound
redirect_old
end
......@@ -128,7 +128,7 @@ class Projects::IssuesController < Projects::ApplicationController
# To prevent 404 errors we provide a redirect to correct iids until 7.0 release
#
def redirect_old
issue = @project.issues.find_by_id(params[:id])
issue = @project.issues.find_by(id: params[:id])
if issue
redirect_to project_issue_path(@project, issue)
......
......@@ -169,7 +169,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
end
def merge_request
@merge_request ||= @project.merge_requests.find_by_iid!(params[:id])
@merge_request ||= @project.merge_requests.find_by!(iid: params[:id])
end
def closes_issues
......
......@@ -76,7 +76,7 @@ class Projects::MilestonesController < Projects::ApplicationController
protected
def milestone
@milestone ||= @project.milestones.find_by_iid!(params[:id])
@milestone ||= @project.milestones.find_by!(iid: params[:id])
end
def authorize_admin_milestone!
......
......@@ -26,7 +26,7 @@ class Projects::TeamMembersController < Projects::ApplicationController
end
def update
@user_project_relation = project.users_projects.find_by_user_id(member)
@user_project_relation = project.users_projects.find_by(user_id: member)
@user_project_relation.update_attributes(params[:team_member])
unless @user_project_relation.valid?
......@@ -36,7 +36,7 @@ class Projects::TeamMembersController < Projects::ApplicationController
end
def destroy
@user_project_relation = project.users_projects.find_by_user_id(member)
@user_project_relation = project.users_projects.find_by(user_id: member)
@user_project_relation.destroy
respond_to do |format|
......@@ -46,7 +46,7 @@ class Projects::TeamMembersController < Projects::ApplicationController
end
def leave
project.users_projects.find_by_user_id(current_user).destroy
project.users_projects.find_by(user_id: current_user).destroy
respond_to do |format|
format.html { redirect_to :back }
......@@ -65,6 +65,6 @@ class Projects::TeamMembersController < Projects::ApplicationController
protected
def member
@member ||= User.find_by_username(params[:id])
@member ||= User.find_by(username: params[:id])
end
end
class SearchController < ApplicationController
def show
@project = Project.find_by_id(params[:project_id]) if params[:project_id].present?
@group = Group.find_by_id(params[:group_id]) if params[:group_id].present?
@project = Project.find_by(id: params[:project_id]) if params[:project_id].present?
@group = Group.find_by(id: params[:group_id]) if params[:group_id].present?
if @project
return access_denied! unless can?(current_user, :download_code, @project)
......
......@@ -18,7 +18,7 @@ class SnippetsController < ApplicationController
end
def user_index
@user = User.find_by_username(params[:username])
@user = User.find_by(username: params[:username])
@snippets = @user.snippets.fresh.non_expired
if @user == current_user
......
......@@ -2,7 +2,7 @@ class UsersController < ApplicationController
layout 'navless'
def show
@user = User.find_by_username!(params[:username])
@user = User.find_by!(username: params[:username])
@projects = @user.authorized_projects.where(id: current_user.authorized_projects.pluck(:id)).includes(:namespace)
@events = @user.recent_events.where(project_id: @projects.map(&:id)).limit(20)
......
......@@ -30,7 +30,7 @@ class UsersGroupsController < ApplicationController
protected
def group
@group ||= Group.find_by_path(params[:group_id])
@group ||= Group.find_by(path: params[:group_id])
end
def authorize_admin_group!
......
......@@ -50,7 +50,7 @@ module ApplicationHelper
end
def avatar_icon(user_email = '', size = nil)
user = User.find_by_email(user_email)
user = User.find_by(email: user_email)
if user && user.avatar.present?
user.avatar.url
else
......
......@@ -8,7 +8,7 @@ module Emails
def reassigned_issue_email(recipient_id, issue_id, previous_assignee_id)
@issue = Issue.find(issue_id)
@previous_assignee = User.find_by_id(previous_assignee_id) if previous_assignee_id
@previous_assignee = User.find_by(id: previous_assignee_id) if previous_assignee_id
@project = @issue.project
mail(to: recipient(recipient_id), subject: subject("Changed issue ##{@issue.iid}", @issue.title))
end
......
......@@ -8,7 +8,7 @@ module Emails
def reassigned_merge_request_email(recipient_id, merge_request_id, previous_assignee_id)
@merge_request = MergeRequest.find(merge_request_id)
@previous_assignee = User.find_by_id(previous_assignee_id) if previous_assignee_id
@previous_assignee = User.find_by(id: previous_assignee_id) if previous_assignee_id
@project = @merge_request.project
mail(to: recipient(recipient_id), subject: subject("Changed merge request ##{@merge_request.iid}", @merge_request.title))
end
......
......@@ -123,8 +123,8 @@ class Note < ActiveRecord::Base
def commit_author
@commit_author ||=
project.users.find_by_email(noteable.author_email) ||
project.users.find_by_name(noteable.author_name)
project.users.find_by(email: noteable.author_email) ||
project.users.find_by(name: noteable.author_name)
rescue
nil
end
......
......@@ -141,10 +141,10 @@ class Project < ActiveRecord::Base
def find_with_namespace(id)
if id.include?("/")
id = id.split("/")
namespace = Namespace.find_by_path(id.first)
namespace = Namespace.find_by(path: id.first)
return nil unless namespace
where(namespace_id: namespace.id).find_by_path(id.second)
where(namespace_id: namespace.id).find_by(path: id.second)
else
where(path: id, namespace_id: nil).last
end
......@@ -288,7 +288,7 @@ class Project < ActiveRecord::Base
# Get Team Member record by user id
def team_member_by_id(user_id)
users_projects.find_by_user_id(user_id)
users_projects.find_by(user_id: user_id)
end
def name_with_namespace
......
......@@ -22,22 +22,22 @@ class ProjectTeam
end
def find(user_id)
user = project.users.find_by_id(user_id)
user = project.users.find_by(id: user_id)
if group
user ||= group.users.find_by_id(user_id)
user ||= group.users.find_by(id: user_id)
end
user
end
def find_tm(user_id)
tm = project.users_projects.find_by_user_id(user_id)
tm = project.users_projects.find_by(user_id: user_id)
# If user is not in project members
# we should check for group membership
if group && !tm
tm = group.users_groups.find_by_user_id(user_id)
tm = group.users_groups.find_by(user_id: user_id)
end
tm
......
......@@ -238,7 +238,7 @@ class User < ActiveRecord::Base
def namespace_uniq
namespace_name = self.username
if Namespace.find_by_path(namespace_name)
if Namespace.find_by(path: namespace_name)
self.errors.add :username, "already exist"
end
end
......@@ -382,7 +382,7 @@ class User < ActiveRecord::Base
end
def created_by
User.find_by_id(created_by_id) if created_by_id
User.find_by(id: created_by_id) if created_by_id
end
def sanitize_attrs
......
......@@ -195,10 +195,10 @@ class NotificationService
users.reject do |user|
next user.notification.disabled? unless project
tm = project.users_projects.find_by_user_id(user.id)
tm = project.users_projects.find_by(user_id: user.id)
if !tm && project.group
tm = project.group.users_groups.find_by_user_id(user.id)
tm = project.group.users_groups.find_by(user_id: user.id)
end
# reject users who globally disabled notification and has no membership
......
......@@ -73,7 +73,7 @@ module Projects
end
def allowed_namespace?(user, namespace_id)
namespace = Namespace.find_by_id(namespace_id)
namespace = Namespace.find_by(id: namespace_id)
current_user.can?(:manage_namespace, namespace)
end
end
......
......@@ -15,7 +15,7 @@ module Search
authorized_projects_ids += current_user.authorized_projects.pluck(:id) if current_user
authorized_projects_ids += Project.public_or_internal_only(current_user).pluck(:id)
group = Group.find_by_id(params[:group_id]) if params[:group_id].present?
group = Group.find_by(id: params[:group_id]) if params[:group_id].present?
projects = Project.where(id: authorized_projects_ids)
projects = projects.where(namespace_id: group.id) if group
projects = projects.search(query)
......
......@@ -19,7 +19,7 @@ project_urls = [
project_urls.each_with_index do |url, i|
group_path, project_path = url.split('/')[-2..-1]
group = Group.find_by_path(group_path)
group = Group.find_by(path: group_path)
unless group
group = Group.new(
......
......@@ -4,7 +4,7 @@ class RemoveProjectIdFromKey < ActiveRecord::Migration
Key.where('project_id IS NOT NULL').update_all(type: 'DeployKey')
DeployKey.all.each do |key|
project = Project.find_by_id(key.project_id)
project = Project.find_by(id: key.project_id)
if project
project.deploy_keys << key
print '.'
......
......@@ -40,7 +40,7 @@ class AdminGroups < Spinach::FeatureSteps
end
When 'I select user "John" from user list as "Reporter"' do
user = User.find_by_name("John")
user = User.find_by(name: "John")
select2(user.id, from: "#user_ids", multiple: true)
within "#new_team_member" do
select "Reporter", from: "group_access"
......
......@@ -43,7 +43,7 @@ class Dashboard < Spinach::FeatureSteps
end
And 'user with name "John Doe" left project "Shop"' do
user = User.find_by_name "John Doe"
user = User.find_by(name: "John Doe")
Event.create(
project: project,
author_id: user.id,
......@@ -85,6 +85,6 @@ class Dashboard < Spinach::FeatureSteps
end
def project
@project ||= Project.find_by_name "Shop"
@project ||= Project.find_by(name: "Shop")
end
end
......@@ -4,7 +4,7 @@ class DashboardWithArchivedProjects < Spinach::FeatureSteps
include SharedProject
When 'project "Forum" is archived' do
project = Project.find_by_name "Forum"
project = Project.find_by(name: "Forum")
project.update_attribute(:archived, true)
end
......
......@@ -39,7 +39,7 @@ class Groups < Spinach::FeatureSteps
end
And 'I select user "John" from list with role "Reporter"' do
user = User.find_by_name("John")
user = User.find_by(name: "John")
within ".users-group-form" do
select2(user.id, from: "#user_ids", multiple: true)
select "Reporter", from: "group_access"
......
......@@ -18,7 +18,7 @@ class ProfileSshKeys < Spinach::FeatureSteps
end
Then 'I should see new ssh key "Laptop"' do
key = Key.find_by_title("Laptop")
key = Key.find_by(title: "Laptop")
page.should have_content(key.title)
page.should have_content(key.key)
current_path.should == profile_key_path(key)
......
......@@ -4,17 +4,17 @@ class ProjectArchived < Spinach::FeatureSteps
include SharedPaths
When 'project "Forum" is archived' do
project = Project.find_by_name "Forum"
project = Project.find_by(name: "Forum")
project.update_attribute(:archived, true)
end
When 'project "Shop" is archived' do
project = Project.find_by_name "Shop"
project = Project.find_by(name: "Shop")
project.update_attribute(:archived, true)
end
When 'I visit project "Forum" page' do
project = Project.find_by_name "Forum"
project = Project.find_by(name: "Forum")
visit project_path(project)
end
......
......@@ -29,7 +29,7 @@ class ProjectBrowseBranches < Spinach::FeatureSteps
end
And 'project "Shop" has protected branches' do
project = Project.find_by_name("Shop")
project = Project.find_by(name: "Shop")
project.protected_branches.create(name: "stable")
end
end
......@@ -11,7 +11,7 @@ class ForkProject < Spinach::FeatureSteps
end
step 'I am a member of project "Shop"' do
@project = Project.find_by_name "Shop"
@project = Project.find_by(name: "Shop")
@project ||= create(:project_with_code, name: "Shop", group: create(:group))
@project.team << [@user, :reporter]
end
......@@ -19,7 +19,7 @@ class ForkProject < Spinach::FeatureSteps
step 'I should see the forked project page' do
page.should have_content "Project was successfully forked."
current_path.should include current_user.namespace.path
@forked_project = Project.find_by_namespace_id(current_user.namespace.path)
@forked_project = Project.find_by(namespace_id: current_user.namespace.path)
end
step 'I already have a project named "Shop" in my namespace' do
......
......@@ -6,7 +6,7 @@ class ProjectForkedMergeRequests < Spinach::FeatureSteps
include Select2Helper
step 'I am a member of project "Shop"' do
@project = Project.find_by_name "Shop"
@project = Project.find_by(name: "Shop")
@project ||= create(:project_with_code, name: "Shop")
@project.team << [@user, :reporter]
end
......@@ -14,7 +14,7 @@ class ProjectForkedMergeRequests < Spinach::FeatureSteps
step 'I have a project forked off of "Shop" called "Forked Shop"' do
@forking_user = @user
forked_project_link = build(:forked_project_link)
@forked_project = Project.find_by_name "Forked Shop"
@forked_project = Project.find_by(name: "Forked Shop")
@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)
forked_project_link.forked_from_project = @project
......@@ -114,7 +114,7 @@ class ProjectForkedMergeRequests < Spinach::FeatureSteps
end
step 'project "Forked Shop" has push event' do
@forked_project = Project.find_by_name("Forked Shop")
@forked_project = Project.find_by(name: "Forked Shop")
data = {
before: "0000000000000000000000000000000000000000",
......@@ -172,7 +172,7 @@ class ProjectForkedMergeRequests < Spinach::FeatureSteps
end
def project
@project ||= Project.find_by_name!("Shop")
@project ||= Project.find_by!(name: "Shop")
end
# Verify a link is generated against the correct project
......
......@@ -7,7 +7,7 @@ class ProjectGraph < Spinach::FeatureSteps
end
When 'I visit project "Shop" graph page' do
project = Project.find_by_name("Shop")
project = Project.find_by(name: "Shop")
visit project_graph_path(project, "master")
end
end
......@@ -4,7 +4,7 @@ class ProjectIssueTracker < Spinach::FeatureSteps
include SharedPaths
step 'project "Shop" has issues enabled' do
@project = Project.find_by_name "Shop"
@project = Project.find_by(name: "Shop")
@project ||= create(:project_with_code, name: "Shop", namespace: @user.namespace)
@project.issues_enabled = true
end
......
......@@ -54,7 +54,7 @@ class ProjectIssues < Spinach::FeatureSteps
end
Then 'I should see issue "500 error on profile"' do
issue = Issue.find_by_title("500 error on profile")
issue = Issue.find_by(title: "500 error on profile")
page.should have_content issue.title
page.should have_content issue.author_name
page.should have_content issue.project.name
......@@ -81,14 +81,14 @@ class ProjectIssues < Spinach::FeatureSteps
end
Given 'project "Shop" has milestone "v2.2"' do
project = Project.find_by_name("Shop")
project = Project.find_by(name: "Shop")
milestone = create(:milestone, title: "v2.2", project: project)
3.times { create(:issue, project: project, milestone: milestone) }
end
And 'project "Shop" has milestone "v3.0"' do
project = Project.find_by_name("Shop")
project = Project.find_by(name: "Shop")
milestone = create(:milestone, title: "v3.0", project: project)
3.times { create(:issue, project: project, milestone: milestone) }
......@@ -104,20 +104,20 @@ class ProjectIssues < Spinach::FeatureSteps
end
When 'I select first assignee from "Shop" project' do
project = Project.find_by_name "Shop"
project = Project.find_by(name: "Shop")
first_assignee = project.users.first
select first_assignee.name, from: "assignee_id"
end
Then 'I should see first assignee from "Shop" as selected assignee' do
issues_assignee_selector = "#issue_assignee_id_chzn > a"
project = Project.find_by_name "Shop"
project = Project.find_by(name: "Shop")
assignee_name = project.users.first.name
page.find(issues_assignee_selector).should have_content(assignee_name)
end
And 'project "Shop" have "Release 0.4" open issue' do
project = Project.find_by_name("Shop")
project = Project.find_by(name: "Shop")
create(:issue,
title: "Release 0.4",
project: project,
......@@ -125,7 +125,7 @@ class ProjectIssues < Spinach::FeatureSteps
end
And 'project "Shop" have "Tweet control" open issue' do
project = Project.find_by_name("Shop")
project = Project.find_by(name: "Shop")
create(:issue,
title: "Tweet control",
project: project,
......@@ -133,7 +133,7 @@ class ProjectIssues < Spinach::FeatureSteps
end
And 'project "Shop" have "Release 0.3" closed issue' do
project = Project.find_by_name("Shop")
project = Project.find_by(name: "Shop")
create(:closed_issue,
title: "Release 0.3",
project: project,
......
......@@ -16,7 +16,7 @@ class ProjectLabels < Spinach::FeatureSteps
end
And 'project "Shop" have issues tags: "bug", "feature"' do
project = Project.find_by_name("Shop")
project = Project.find_by(name: "Shop")
['bug', 'feature'].each do |label|
create(:issue, project: project, label_list: label)
end
......
......@@ -3,7 +3,7 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps
include SharedPaths
And 'I own project "Delta"' do
@project = Project.find_by_name "Delta"
@project = Project.find_by(name: "Delta")
@project ||= create(:project_with_code, name: "Delta", namespace: @user.namespace)
@project.team << [@user, :master]
end
......
......@@ -27,7 +27,7 @@ class ProjectMergeRequests < Spinach::FeatureSteps
end
step 'I should see closed merge request "Bug NS-04"' do
merge_request = MergeRequest.find_by_title!("Bug NS-04")
merge_request = MergeRequest.find_by!(title: "Bug NS-04")
merge_request.closed?.should be_true
page.should have_content "Closed by"
end
......@@ -180,11 +180,11 @@ class ProjectMergeRequests < Spinach::FeatureSteps
end
def project
@project ||= Project.find_by_name!("Shop")
@project ||= Project.find_by!(name: "Shop")
end
def merge_request
@merge_request ||= MergeRequest.find_by_title!("Bug NS-05")
@merge_request ||= MergeRequest.find_by!(title: "Bug NS-05")
end
def init_diff_note
......
......@@ -4,7 +4,7 @@ class ProjectMilestones < Spinach::FeatureSteps
include SharedPaths
Then 'I should see milestone "v2.2"' do
milestone = @project.milestones.find_by_title("v2.2")
milestone = @project.milestones.find_by(title: "v2.2")
page.should have_content(milestone.title[0..10])
page.should have_content(milestone.expires_at)
page.should have_content("Browse Issues")
......@@ -24,22 +24,22 @@ class ProjectMilestones < Spinach::FeatureSteps
end
Then 'I should see milestone "v2.3"' do
milestone = @project.milestones.find_by_title("v2.3")
milestone = @project.milestones.find_by(title: "v2.3")
page.should have_content(milestone.title[0..10])
page.should have_content(milestone.expires_at)
page.should have_content("Browse Issues")
end
And 'project "Shop" has milestone "v2.2"' do
project = Project.find_by_name("Shop")
project = Project.find_by(name: "Shop")
milestone = create(:milestone, title: "v2.2", project: project)
3.times { create(:issue, project: project, milestone: milestone) }
end
Given 'the milestone has open and closed issues' do
project = Project.find_by_name("Shop")
milestone = project.milestones.find_by_title('v2.2')
project = Project.find_by(name: "Shop")
milestone = project.milestones.find_by(title: 'v2.2')
# 3 Open issues created above; create one closed issue
create(:closed_issue, project: project, milestone: milestone)
......
......@@ -10,7 +10,7 @@ class ProjectNetworkGraph < Spinach::FeatureSteps
# Stub Graph max_size to speed up test (10 commits vs. 650)
Network::Graph.stub(max_count: 10)
project = Project.find_by_name("Shop")
project = Project.find_by(name: "Shop")
visit project_network_path(project, "master")
end
......
......@@ -90,10 +90,10 @@ class ProjectSnippets < Spinach::FeatureSteps
end
def project
@project ||= Project.find_by_name!("Shop")
@project ||= Project.find_by!(name: "Shop")
end
def project_snippet
@project_snippet ||= ProjectSnippet.find_by_title!("Snippet One")
@project_snippet ||= ProjectSnippet.find_by!(title: "Snippet one")
end
end
......@@ -10,7 +10,7 @@ class ProjectTeamManagement < Spinach::FeatureSteps
end
And 'I should see "Sam" in team list' do
user = User.find_by_name("Sam")
user = User.find_by(name: "Sam")
page.should have_content(user.name)
page.should have_content(user.username)
end
......@@ -20,7 +20,7 @@ class ProjectTeamManagement < Spinach::FeatureSteps
end
And 'I select "Mike" as "Reporter"' do
user = User.find_by_name("Mike")
user = User.find_by(name: "Mike")
select2(user.id, from: "#user_ids", multiple: true)
within "#new_team_member" do
......@@ -42,7 +42,7 @@ class ProjectTeamManagement < Spinach::FeatureSteps
end
And 'I change "Sam" role to "Reporter"' do
user = User.find_by_name("Sam")
user = User.find_by(name: "Sam")
within "#user_#{user.id}" do
select "Reporter", from: "team_member_project_access"
end
......@@ -59,7 +59,7 @@ class ProjectTeamManagement < Spinach::FeatureSteps
end
And 'I should not see "Sam" in team list' do
user = User.find_by_name("Sam")
user = User.find_by(name: "Sam")
page.should_not have_content(user.name)
page.should_not have_content(user.username)
end
......@@ -73,8 +73,8 @@ class ProjectTeamManagement < Spinach::FeatureSteps
end
And '"Sam" is "Shop" developer' do
user = User.find_by_name("Sam")
project = Project.find_by_name("Shop")
user = User.find_by(name: "Sam")
project = Project.find_by(name: "Shop")
project.team << [user, :developer]
end
......@@ -84,8 +84,8 @@ class ProjectTeamManagement < Spinach::FeatureSteps
end
And '"Mike" is "Website" reporter' do
user = User.find_by_name("Mike")
project = Project.find_by_name("Website")
user = User.find_by(name: "Mike")
project = Project.find_by(name: "Website")
project.team << [user, :reporter]
end
......@@ -94,13 +94,13 @@ class ProjectTeamManagement < Spinach::FeatureSteps
end
When 'I submit "Website" project for import team' do
project = Project.find_by_name("Website")
project = Project.find_by(name: "Website")
select project.name_with_namespace, from: 'source_project_id'
click_button 'Import'
end
step 'I click cancel link for "Sam"' do
within "#user_#{User.find_by_name('Sam').id}" do
within "#user_#{User.find_by(name: 'Sam').id}" do
click_link('Remove user from team')
end
end
......
......@@ -12,7 +12,7 @@ class Spinach::Features::ProjectRedirects < Spinach::FeatureSteps
end
step 'I visit project "Community" page' do
project = Project.find_by_name('Community')
project = Project.find_by(name: 'Community')
visit project_path(project)
end
......@@ -23,12 +23,12 @@ class Spinach::Features::ProjectRedirects < Spinach::FeatureSteps
end
step 'I visit project "Enterprise" page' do
project = Project.find_by_name('Enterprise')
project = Project.find_by(name: 'Enterprise')
visit project_path(project)
end
step 'I visit project "CommunityDoesNotExist" page' do
project = Project.find_by_name('Community')
project = Project.find_by(name: 'Community')
visit project_path(project) + 'DoesNotExist'
end
end
......
......@@ -33,12 +33,12 @@ class Spinach::Features::PublicProjectsFeature < Spinach::FeatureSteps
end
step 'I visit empty project page' do
project = Project.find_by_name('Empty Public Project')
project = Project.find_by(name: 'Empty Public Project')
visit project_path(project)
end
step 'I visit project "Community" page' do
project = Project.find_by_name('Community')
project = Project.find_by(name: 'Community')
visit project_path(project)
end
......@@ -47,14 +47,14 @@ class Spinach::Features::PublicProjectsFeature < Spinach::FeatureSteps
end
step 'I should see empty public project details with http clone info' do
project = Project.find_by_name('Empty Public Project')
project = Project.find_by(name: 'Empty Public Project')
page.all(:css, '.git-empty .clone').each do |element|
element.text.should include(project.http_url_to_repo)
end
end
step 'I should see empty public project details with ssh clone info' do
project = Project.find_by_name('Empty Public Project')
project = Project.find_by(name: 'Empty Public Project')
page.all(:css, '.git-empty .clone').each do |element|
element.text.should include(project.url_to_repo)
end
......@@ -65,7 +65,7 @@ class Spinach::Features::PublicProjectsFeature < Spinach::FeatureSteps
end
step 'I visit project "Enterprise" page' do
project = Project.find_by_name('Enterprise')
project = Project.find_by(name: 'Enterprise')
visit project_path(project)
end
......@@ -88,7 +88,7 @@ class Spinach::Features::PublicProjectsFeature < Spinach::FeatureSteps
end
step 'I visit project "Internal" page' do
project = Project.find_by_name('Internal')
project = Project.find_by(name: 'Internal')
visit project_path(project)
end
......@@ -99,12 +99,12 @@ class Spinach::Features::PublicProjectsFeature < Spinach::FeatureSteps
end
step 'I should see an http link to the repository' do
project = Project.find_by_name 'Community'
project = Project.find_by(name: 'Community')
page.should have_field('project_clone', with: project.http_url_to_repo)
end
step 'I should see an ssh link to the repository' do
project = Project.find_by_name 'Community'
project = Project.find_by(name: 'Community')
page.should have_field('project_clone', with: project.url_to_repo)
end
end
......
......@@ -241,7 +241,7 @@ module SharedPaths
end
step 'I visit issue page "Release 0.4"' do
issue = Issue.find_by_title("Release 0.4")
issue = Issue.find_by(title: "Release 0.4")
visit project_issue_path(issue.project, issue)
end
......@@ -250,12 +250,12 @@ module SharedPaths
end
step 'I visit merge request page "Bug NS-04"' do
mr = MergeRequest.find_by_title("Bug NS-04")
mr = MergeRequest.find_by(title: "Bug NS-04")
visit project_merge_request_path(mr.target_project, mr)
end
step 'I visit merge request page "Bug NS-05"' do
mr = MergeRequest.find_by_title("Bug NS-05")
mr = MergeRequest.find_by(title: "Bug NS-05")
visit project_merge_request_path(mr.target_project, mr)
end
......@@ -292,7 +292,7 @@ module SharedPaths
end
step 'I visit public page for "Community" project' do
visit public_project_path(Project.find_by_name("Community"))
visit public_project_path(Project.find_by(name: "Community"))
end
# ----------------------------------------
......@@ -316,6 +316,6 @@ module SharedPaths
end
def project
project = Project.find_by_name!("Shop")
project = Project.find_by!(name: "Shop")
end
end
......@@ -9,20 +9,20 @@ module SharedProject
# Create a specific project called "Shop"
And 'I own project "Shop"' do
@project = Project.find_by_name "Shop"
@project = Project.find_by(name: "Shop")
@project ||= create(:project_with_code, name: "Shop", namespace: @user.namespace)
@project.team << [@user, :master]
end
# Create another specific project called "Forum"
And 'I own project "Forum"' do
@project = Project.find_by_name "Forum"
@project = Project.find_by(name: "Forum")
@project ||= create(:project_with_code, name: "Forum", namespace: @user.namespace, path: 'forum_project')
@project.team << [@user, :master]
end
And 'project "Shop" has push event' do
@project = Project.find_by_name("Shop")
@project = Project.find_by(name: "Shop")
data = {
before: "0000000000000000000000000000000000000000",
......@@ -48,7 +48,7 @@ module SharedProject
end
Then 'I should see project "Shop" activity feed' do
project = Project.find_by_name("Shop")
project = Project.find_by(name: "Shop")
page.should have_content "#{@user.name} pushed new branch new_design at #{project.name_with_namespace}"
end
......
......@@ -12,6 +12,6 @@ class DiscoverSnippets < Spinach::FeatureSteps
end
def snippet
@snippet ||= PersonalSnippet.find_by_title!("Personal snippet one")
@snippet ||= PersonalSnippet.find_by!(title: "Personal snippet one")
end
end
......@@ -59,6 +59,6 @@ class SnippetsFeature < Spinach::FeatureSteps
end
def snippet
@snippet ||= PersonalSnippet.find_by_title!("Personal snippet one")
@snippet ||= PersonalSnippet.find_by!(title: "Personal snippet one")
end
end
......@@ -36,6 +36,6 @@ class UserSnippets < Spinach::FeatureSteps
end
def snippet
@snippet ||= PersonalSnippet.find_by_title!("Personal snippet one")
@snippet ||= PersonalSnippet.find_by!(title: "Personal snippet one")
end
end
......@@ -38,14 +38,14 @@ module API
attrs[:key].strip!
# check if key already exist in project
key = user_project.deploy_keys.find_by_key(attrs[:key])
key = user_project.deploy_keys.find_by(key: attrs[:key])
if key
present key, with: Entities::SSHKey
return
end
# Check for available deploy keys in other projects
key = current_user.accessible_deploy_keys.find_by_key(attrs[:key])
key = current_user.accessible_deploy_keys.find_by(key: attrs[:key])
if key
user_project.deploy_keys << key
present key, with: Entities::SSHKey
......
......@@ -48,19 +48,19 @@ module API
class ProjectMember < UserBasic
expose :project_access, as: :access_level do |user, options|
options[:project].users_projects.find_by_user_id(user.id).project_access
options[:project].users_projects.find_by(user_id: user.id).project_access
end
end
class TeamMember < UserBasic
expose :permission, as: :access_level do |user, options|
options[:user_team].user_team_user_relationships.find_by_user_id(user.id).permission
options[:user_team].user_team_user_relationships.find_by(user_id: user.id).permission
end
end
class TeamProject < Project
expose :greatest_access, as: :greatest_access_level do |project, options|
options[:user_team].user_team_project_relationships.find_by_project_id(project.id).greatest_access
options[:user_team].user_team_project_relationships.find_by(project_id: project.id).greatest_access
end
end
......@@ -74,7 +74,7 @@ module API
class GroupMember < UserBasic
expose :group_access, as: :access_level do |user, options|
options[:group].users_groups.find_by_user_id(user.id).group_access
options[:group].users_groups.find_by(user_id: user.id).group_access
end
end
......
......@@ -121,11 +121,11 @@ module API
render_api_error!("Wrong access level", 422)
end
group = find_group(params[:id])
if group.users_groups.find_by_user_id(params[:user_id])
if group.users_groups.find_by(user_id: params[:user_id])
render_api_error!("Already exists", 409)
end
group.add_users([params[:user_id]], params[:access_level])
member = group.users_groups.find_by_user_id(params[:user_id])
member = group.users_groups.find_by(user_id: params[:user_id])
present member.user, with: Entities::GroupMember, group: group
end
......@@ -139,7 +139,7 @@ module API
# DELETE /groups/:id/members/:user_id
delete ":id/members/:user_id" do
group = find_group(params[:id])
member = group.users_groups.find_by_user_id(params[:user_id])
member = group.users_groups.find_by(user_id: params[:user_id])
if member.nil?
render_api_error!("404 Not Found - user_id:#{params[:user_id]} not a member of group #{group.name}",404)
else
......
......@@ -7,7 +7,7 @@ module API
def current_user
private_token = (params[PRIVATE_TOKEN_PARAM] || env[PRIVATE_TOKEN_HEADER]).to_s
@current_user ||= User.find_by_authentication_token(private_token)
@current_user ||= User.find_by(authentication_token: private_token)
identifier = sudo_identifier()
# If the sudo is the current user do nothing
......@@ -47,7 +47,7 @@ module API
end
def find_project(id)
project = Project.find_by_id(id) || Project.find_with_namespace(id)
project = Project.find_by(id: id) || Project.find_with_namespace(id)
if project && can?(current_user, :read_project, project)
project
......
......@@ -81,7 +81,7 @@ module API
merge_request.target_project = user_project
else
if target_matches_fork(target_project_id,user_project)
merge_request.target_project = Project.find_by_id(attrs[:target_project_id])
merge_request.target_project = Project.find_by(id: attrs[:target_project_id])
else
render_api_error!('(Bad Request) Specified target project that is not the source project, or the source fork of the project.', 400)
end
......
......@@ -266,7 +266,7 @@ module API
authorize! :admin_project, user_project
required_attributes! [:access_level]
team_member = user_project.users_projects.find_by_user_id(params[:user_id])
team_member = user_project.users_projects.find_by(user_id: params[:user_id])
not_found!("User can not be found") if team_member.nil?
if team_member.update_attributes(project_access: params[:access_level])
......@@ -286,7 +286,7 @@ module API
# DELETE /projects/:id/members/:user_id
delete ":id/members/:user_id" do
authorize! :admin_project, user_project
team_member = user_project.users_projects.find_by_user_id(params[:user_id])
team_member = user_project.users_projects.find_by(user_id: params[:user_id])
unless team_member.nil?
team_member.destroy
else
......
......@@ -51,7 +51,7 @@ module API
@branch = user_project.repository.find_branch(params[:branch])
not_found! unless @branch
protected_branch = user_project.protected_branches.find_by_name(@branch.name)
protected_branch = user_project.protected_branches.find_by(name: @branch.name)
user_project.protected_branches.create(name: @branch.name) unless protected_branch
present @branch, with: Entities::RepoObject, project: user_project
......@@ -69,7 +69,7 @@ module API
@branch = user_project.repository.find_branch(params[:branch])
not_found! unless @branch
protected_branch = user_project.protected_branches.find_by_name(@branch.name)
protected_branch = user_project.protected_branches.find_by(name: @branch.name)
protected_branch.destroy if protected_branch
present @branch, with: Entities::RepoObject, project: user_project
......
......@@ -117,7 +117,7 @@ module API
# DELETE /users/:id
delete ":id" do
authenticated_as_admin!
user = User.find_by_id(params[:id])
user = User.find_by(id: params[:id])
if user
user.destroy
......
module Gitlab
class Auth
def find(login, password)
user = User.find_by_email(login) || User.find_by_username(login)
user = User.find_by(email: login) || User.find_by(username: login)
if user.nil? || user.ldap_user?
# Second chance - try LDAP authentication
......
......@@ -6,17 +6,17 @@ module Gitlab
if identifier.blank?
# Local push from gitlab
email = project.repository.commit(newrev).author_email rescue nil
User.find_by_email(email) if email
User.find_by(email: email) if email
elsif identifier =~ /\Auser-\d+\Z/
# git push over http
user_id = identifier.gsub("user-", "")
User.find_by_id(user_id)
User.find_by(id: user_id)
elsif identifier =~ /\Akey-\d+\Z/
# git push over ssh
key_id = identifier.gsub("key-", "")
Key.find_by_id(key_id).try(:user)
Key.find_by(id: key_id).try(:user)
end
end
end
......
......@@ -44,13 +44,13 @@ module Gitlab
end
def find_user(email)
user = model.find_by_email(email)
user = model.find_by(email: email)
# If no user found and allow_username_or_email_login is true
# we look for user by extracting part of their email
if !user && email && ldap_conf['allow_username_or_email_login']
uname = email.partition('@').first
user = model.find_by_username(uname)
user = model.find_by(username: uname)
end
user
......
......@@ -15,7 +15,7 @@ namespace :gitlab do
desc "GITLAB | Add a specific user to all projects (as a developer)"
task :user_to_projects, [:email] => :environment do |t, args|
user = User.find_by_email args.email
user = User.find_by(email: args.email)
project_ids = Project.pluck(:id)
puts "Importing #{user.email} users into #{project_ids.size} projects"
UsersProject.add_users_into_projects(project_ids, Array.wrap(user.id), UsersProject::DEVELOPER)
......
......@@ -43,13 +43,13 @@ namespace :gitlab do
username.gsub!("+", ".")
# return username if no matches
return username unless User.find_by_username(username)
return username unless User.find_by(username: username)
# look for same username
(1..10).each do |i|
suffixed_username = "#{username}#{i}"
return suffixed_username unless User.find_by_username(suffixed_username)
return suffixed_username unless User.find_by(username: suffixed_username)
end
end
......
......@@ -50,7 +50,7 @@ namespace :gitlab do
# find group namespace
if group_name
group = Group.find_by_path(group_name)
group = Group.find_by(path: group_name)
# create group namespace
if !group
group = Group.new(:name => group_name)
......
......@@ -25,7 +25,7 @@ describe Gitlab::LDAP do
it "should update credentials by email if missing uid" do
user = double('User')
User.stub find_by_extern_uid_and_provider: nil
User.stub find_by_email: user
User.stub(:find_by).with(hash_including(email: anything())) { user }
user.should_receive :update_attributes
gl_auth.find_or_create(@auth)
end
......@@ -35,8 +35,8 @@ describe Gitlab::LDAP do
value = Gitlab.config.ldap.allow_username_or_email_login
Gitlab.config.ldap['allow_username_or_email_login'] = true
User.stub find_by_extern_uid_and_provider: nil
User.stub find_by_email: nil
User.stub find_by_username: user
User.stub(:find_by).with(hash_including(email: anything())) { nil }
User.stub(:find_by).with(hash_including(username: anything())) { user }
user.should_receive :update_attributes
gl_auth.find_or_create(@auth)
Gitlab.config.ldap['allow_username_or_email_login'] = value
......@@ -47,8 +47,8 @@ describe Gitlab::LDAP do
value = Gitlab.config.ldap.allow_username_or_email_login
Gitlab.config.ldap['allow_username_or_email_login'] = false
User.stub find_by_extern_uid_and_provider: nil
User.stub find_by_email: nil
User.stub find_by_username: user
User.stub(:find_by).with(hash_including(email: anything())) { nil }
User.stub(:find_by).with(hash_including(username: anything())) { user }
user.should_not_receive :update_attributes
gl_auth.find_or_create(@auth)
Gitlab.config.ldap['allow_username_or_email_login'] = value
......
......@@ -93,7 +93,7 @@ describe API::API do
expect {
post api("/users", admin), attr
}.to change { User.count }.by(1)
user = User.find_by_username(attr[:username])
user = User.find_by(username: attr[:username])
user.projects_limit.should == limit
user.theme_id.should == Gitlab::Theme::MARS
Gitlab.config.gitlab.unstub(:default_projects_limit)
......
......@@ -19,7 +19,7 @@ describe PostReceive do
end
it "does not run if the author is not in the project" do
Key.stub(find_by_id: nil)
Key.stub(:find_by).with(hash_including(id: anything())) { nil }
project.should_not_receive(:execute_hooks)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment