Read about our upcoming Code of Conduct on this issue

Commit a3f645ef authored by skv's avatar skv
Browse files

Remove deprecated finders

parent fd7bd12feb01
......@@ -141,10 +141,10 @@ def search query
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 @@ def team_member_by_name_or_email(name = nil, email = nil)
# 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 @@ def << args
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 @@ def generate_password
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 @@ def accessible_deploy_keys
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 @@ def reject_muted_users(users, project = nil)
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 @@ def deny_namespace
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 @@ def execute
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.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 @@ def up
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,
......
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