Commit a3f645ef authored by skv's avatar skv
Browse files

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 @@ def destroy
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 @@ def destroy
protected
def user
@user ||= User.find_by_username!(params[:id])
@user ||= User.find_by!(username: params[:id])
end
end
......@@ -41,7 +41,7 @@ def projects
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 @@ def destroy
protected
def group
@group ||= Group.find_by_path(params[:id])
@group ||= Group.find_by(path: params[:id])
end
def projects
......
......@@ -19,6 +19,6 @@ def leave
private
def group
@group ||= Group.find_by_path(params[:id])
@group ||= Group.find_by(path: params[:id])
end
end
......@@ -97,7 +97,7 @@ def bulk_update
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 @@ def issues_filtered
# 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 @@ def selected_target_project
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 @@ def destroy
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 @@ def create
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 @@ def update
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 @@ def destroy
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 @@ def apply_import
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 @@ def index
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 @@ def destroy
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 @@ def current_action?(*args)
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 @@ def new_issue_email(recipient_id, issue_id)
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 @@ def new_merge_request_email(recipient_id, merge_request_id)
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 @@ def self.cross_reference_exists?(noteable, mentioner)
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 @@ 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")