Commit 4742dba4 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'master' of github.com:gitlabhq/gitlabhq

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