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
......@@ -16,7 +16,7 @@ class ProjectLabels < Spinach::FeatureSteps
end
And 'project "Shop" have issues tags: "bug", "feature"' do
project = Project.find_by_name("Shop")
project = Project.find_by(name: "Shop")
['bug', 'feature'].each do |label|
create(:issue, project: project, label_list: label)
end
......
......@@ -3,7 +3,7 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps
include SharedPaths
And 'I own project "Delta"' do
@project = Project.find_by_name "Delta"
@project = Project.find_by(name: "Delta")
@project ||= create(:project_with_code, name: "Delta", namespace: @user.namespace)
@project.team << [@user, :master]
end
......
......@@ -27,7 +27,7 @@ class ProjectMergeRequests < Spinach::FeatureSteps
end
step 'I should see closed merge request "Bug NS-04"' do
merge_request = MergeRequest.find_by_title!("Bug NS-04")
merge_request = MergeRequest.find_by!(title: "Bug NS-04")
merge_request.closed?.should be_true
page.should have_content "Closed by"
end
......@@ -180,11 +180,11 @@ class ProjectMergeRequests < Spinach::FeatureSteps
end
def project
@project ||= Project.find_by_name!("Shop")
@project ||= Project.find_by!(name: "Shop")
end
def merge_request
@merge_request ||= MergeRequest.find_by_title!("Bug NS-05")
@merge_request ||= MergeRequest.find_by!(title: "Bug NS-05")
end
def init_diff_note
......
......@@ -4,7 +4,7 @@ class ProjectMilestones < Spinach::FeatureSteps
include SharedPaths
Then 'I should see milestone "v2.2"' do
milestone = @project.milestones.find_by_title("v2.2")
milestone = @project.milestones.find_by(title: "v2.2")
page.should have_content(milestone.title[0..10])
page.should have_content(milestone.expires_at)
page.should have_content("Browse Issues")
......@@ -24,22 +24,22 @@ class ProjectMilestones < Spinach::FeatureSteps
end
Then 'I should see milestone "v2.3"' do
milestone = @project.milestones.find_by_title("v2.3")
milestone = @project.milestones.find_by(title: "v2.3")
page.should have_content(milestone.title[0..10])
page.should have_content(milestone.expires_at)
page.should have_content("Browse Issues")
end
And 'project "Shop" has milestone "v2.2"' do
project = Project.find_by_name("Shop")
project = Project.find_by(name: "Shop")
milestone = create(:milestone, title: "v2.2", project: project)
3.times { create(:issue, project: project, milestone: milestone) }
end
Given 'the milestone has open and closed issues' do
project = Project.find_by_name("Shop")
milestone = project.milestones.find_by_title('v2.2')
project = Project.find_by(name: "Shop")
milestone = project.milestones.find_by(title: 'v2.2')
# 3 Open issues created above; create one closed issue
create(:closed_issue, project: project, milestone: milestone)
......
......@@ -10,7 +10,7 @@ class ProjectNetworkGraph < Spinach::FeatureSteps
# Stub Graph max_size to speed up test (10 commits vs. 650)
Network::Graph.stub(max_count: 10)
project = Project.find_by_name("Shop")
project = Project.find_by(name: "Shop")
visit project_network_path(project, "master")
end
......
......@@ -90,10 +90,10 @@ class ProjectSnippets < Spinach::FeatureSteps
end
def project
@project ||= Project.find_by_name!("Shop")
@project ||= Project.find_by!(name: "Shop")
end
def project_snippet
@project_snippet ||= ProjectSnippet.find_by_title!("Snippet One")
@project_snippet ||= ProjectSnippet.find_by!(title: "Snippet one")
end
end
......@@ -10,7 +10,7 @@ class ProjectTeamManagement < Spinach::FeatureSteps
end
And 'I should see "Sam" in team list' do
user = User.find_by_name("Sam")
user = User.find_by(name: "Sam")
page.should have_content(user.name)
page.should have_content(user.username)
end
......@@ -20,7 +20,7 @@ class ProjectTeamManagement < Spinach::FeatureSteps
end
And 'I select "Mike" as "Reporter"' do
user = User.find_by_name("Mike")
user = User.find_by(name: "Mike")
select2(user.id, from: "#user_ids", multiple: true)
within "#new_team_member" do
......@@ -42,7 +42,7 @@ class ProjectTeamManagement < Spinach::FeatureSteps
end
And 'I change "Sam" role to "Reporter"' do
user = User.find_by_name("Sam")
user = User.find_by(name: "Sam")
within "#user_#{user.id}" do
select "Reporter", from: "team_member_project_access"
end
......@@ -59,7 +59,7 @@ class ProjectTeamManagement < Spinach::FeatureSteps
end
And 'I should not see "Sam" in team list' do
user = User.find_by_name("Sam")
user = User.find_by(name: "Sam")
page.should_not have_content(user.name)
page.should_not have_content(user.username)
end
......@@ -73,8 +73,8 @@ class ProjectTeamManagement < Spinach::FeatureSteps
end
And '"Sam" is "Shop" developer' do
user = User.find_by_name("Sam")
project = Project.find_by_name("Shop")
user = User.find_by(name: "Sam")
project = Project.find_by(name: "Shop")
project.team << [user, :developer]
end
......@@ -84,8 +84,8 @@ class ProjectTeamManagement < Spinach::FeatureSteps
end
And '"Mike" is "Website" reporter' do
user = User.find_by_name("Mike")
project = Project.find_by_name("Website")
user = User.find_by(name: "Mike")
project = Project.find_by(name: "Website")
project.team << [user, :reporter]
end
......@@ -94,13 +94,13 @@ class ProjectTeamManagement < Spinach::FeatureSteps
end
When 'I submit "Website" project for import team' do
project = Project.find_by_name("Website")
project = Project.find_by(name: "Website")
select project.name_with_namespace, from: 'source_project_id'
click_button 'Import'
end
step 'I click cancel link for "Sam"' do
within "#user_#{User.find_by_name('Sam').id}" do
within "#user_#{User.find_by(name: 'Sam').id}" do
click_link('Remove user from team')
end
end
......
......@@ -12,7 +12,7 @@ class Spinach::Features::ProjectRedirects < Spinach::FeatureSteps
end
step 'I visit project "Community" page' do
project = Project.find_by_name('Community')
project = Project.find_by(name: 'Community')
visit project_path(project)
end
......@@ -23,12 +23,12 @@ class Spinach::Features::ProjectRedirects < Spinach::FeatureSteps
end
step 'I visit project "Enterprise" page' do
project = Project.find_by_name('Enterprise')
project = Project.find_by(name: 'Enterprise')
visit project_path(project)
end
step 'I visit project "CommunityDoesNotExist" page' do
project = Project.find_by_name('Community')
project = Project.find_by(name: 'Community')
visit project_path(project) + 'DoesNotExist'
end
end
......
......@@ -33,12 +33,12 @@ class Spinach::Features::PublicProjectsFeature < Spinach::FeatureSteps
end
step 'I visit empty project page' do
project = Project.find_by_name('Empty Public Project')
project = Project.find_by(name: 'Empty Public Project')
visit project_path(project)
end
step 'I visit project "Community" page' do
project = Project.find_by_name('Community')
project = Project.find_by(name: 'Community')
visit project_path(project)
end
......@@ -47,14 +47,14 @@ class Spinach::Features::PublicProjectsFeature < Spinach::FeatureSteps
end
step 'I should see empty public project details with http clone info' do
project = Project.find_by_name('Empty Public Project')
project = Project.find_by(name: 'Empty Public Project')
page.all(:css, '.git-empty .clone').each do |element|
element.text.should include(project.http_url_to_repo)
end
end
step 'I should see empty public project details with ssh clone info' do
project = Project.find_by_name('Empty Public Project')
project = Project.find_by(name: 'Empty Public Project')
page.all(:css, '.git-empty .clone').each do |element|
element.text.should include(project.url_to_repo)
end
......@@ -65,7 +65,7 @@ class Spinach::Features::PublicProjectsFeature < Spinach::FeatureSteps
end
step 'I visit project "Enterprise" page' do
project = Project.find_by_name('Enterprise')
project = Project.find_by(name: 'Enterprise')
visit project_path(project)
end
......@@ -88,7 +88,7 @@ class Spinach::Features::PublicProjectsFeature < Spinach::FeatureSteps
end
step 'I visit project "Internal" page' do
project = Project.find_by_name('Internal')
project = Project.find_by(name: 'Internal')
visit project_path(project)
end
......@@ -99,12 +99,12 @@ class Spinach::Features::PublicProjectsFeature < Spinach::FeatureSteps
end
step 'I should see an http link to the repository' do
project = Project.find_by_name 'Community'
project = Project.find_by(name: 'Community')
page.should have_field('project_clone', with: project.http_url_to_repo)
end
step 'I should see an ssh link to the repository' do
project = Project.find_by_name 'Community'
project = Project.find_by(name: 'Community')
page.should have_field('project_clone', with: project.url_to_repo)
end
end
......
......@@ -241,7 +241,7 @@ module SharedPaths
end
step 'I visit issue page "Release 0.4"' do
issue = Issue.find_by_title("Release 0.4")
issue = Issue.find_by(title: "Release 0.4")
visit project_issue_path(issue.project, issue)
end
......@@ -250,12 +250,12 @@ module SharedPaths
end
step 'I visit merge request page "Bug NS-04"' do
mr = MergeRequest.find_by_title("Bug NS-04")
mr = MergeRequest.find_by(title: "Bug NS-04")
visit project_merge_request_path(mr.target_project, mr)
end
step 'I visit merge request page "Bug NS-05"' do
mr = MergeRequest.find_by_title("Bug NS-05")
mr = MergeRequest.find_by(title: "Bug NS-05")
visit project_merge_request_path(mr.target_project, mr)
end
......@@ -292,7 +292,7 @@ module SharedPaths
end
step 'I visit public page for "Community" project' do
visit public_project_path(Project.find_by_name("Community"))
visit public_project_path(Project.find_by(name: "Community"))
end
# ----------------------------------------
......@@ -316,6 +316,6 @@ def root_ref
end
def project
project = Project.find_by_name!("Shop")
project = Project.find_by!(name: "Shop")
end
end
......@@ -9,20 +9,20 @@ module SharedProject
# Create a specific project called "Shop"
And 'I own project "Shop"' do
@project = Project.find_by_name "Shop"
@project = Project.find_by(name: "Shop")
@project ||= create(:project_with_code, name: "Shop", namespace: @user.namespace)
@project.team << [@user, :master]
end
# Create another specific project called "Forum"
And 'I own project "Forum"' do
@project = Project.find_by_name "Forum"
@project = Project.find_by(name: "Forum")
@project ||= create(:project_with_code, name: "Forum", namespace: @user.namespace, path: 'forum_project')
@project.team << [@user, :master]
end
And 'project "Shop" has push event' do
@project = Project.find_by_name("Shop")
@project = Project.find_by(name: "Shop")
data = {
before: "0000000000000000000000000000000000000000",
......@@ -48,7 +48,7 @@ module SharedProject
end
Then 'I should see project "Shop" activity feed' do
project = Project.find_by_name("Shop")
project = Project.find_by(name: "Shop")
page.should have_content "#{@user.name} pushed new branch new_design at #{project.name_with_namespace}"
end
......
......@@ -12,6 +12,6 @@ class DiscoverSnippets < Spinach::FeatureSteps
end
def snippet
@snippet ||= PersonalSnippet.find_by_title!("Personal snippet one")
@snippet ||= PersonalSnippet.find_by!(title: "Personal snippet one")
end
end
......@@ -59,6 +59,6 @@ class SnippetsFeature < Spinach::FeatureSteps
end
def snippet
@snippet ||= PersonalSnippet.find_by_title!("Personal snippet one")
@snippet ||= PersonalSnippet.find_by!(title: "Personal snippet one")
end
end
......@@ -36,6 +36,6 @@ class UserSnippets < Spinach::FeatureSteps
end
def snippet
@snippet ||= PersonalSnippet.find_by_title!("Personal snippet one")
@snippet ||= PersonalSnippet.find_by!(title: "Personal snippet one")
end
end
......@@ -38,14 +38,14 @@ class DeployKeys < Grape::API
attrs[:key].strip!
# check if key already exist in project
key = user_project.deploy_keys.find_by_key(attrs[:key])
key = user_project.deploy_keys.find_by(key: attrs[:key])
if key
present key, with: Entities::SSHKey
return
end
# Check for available deploy keys in other projects
key = current_user.accessible_deploy_keys.find_by_key(attrs[:key])
key = current_user.accessible_deploy_keys.find_by(key: attrs[:key])
if key
user_project.deploy_keys << key
present key, with: Entities::SSHKey
......
......@@ -48,19 +48,19 @@ class Project < Grape::Entity
class ProjectMember < UserBasic
expose :project_access, as: :access_level do |user, options|
options[:project].users_projects.find_by_user_id(user.id).project_access
options[:project].users_projects.find_by(user_id: user.id).project_access
end
end
class TeamMember < UserBasic
expose :permission, as: :access_level do |user, options|
options[:user_team].user_team_user_relationships.find_by_user_id(user.id).permission
options[:user_team].user_team_user_relationships.find_by(user_id: user.id).permission
end
end
class TeamProject < Project
expose :greatest_access, as: :greatest_access_level do |project, options|
options[:user_team].user_team_project_relationships.find_by_project_id(project.id).greatest_access
options[:user_team].user_team_project_relationships.find_by(project_id: project.id).greatest_access
end
end
......@@ -74,7 +74,7 @@ class GroupDetail < Group
class GroupMember < UserBasic
expose :group_access, as: :access_level do |user, options|
options[:group].users_groups.find_by_user_id(user.id).group_access
options[:group].users_groups.find_by(user_id: user.id).group_access
end
end
......
......@@ -121,11 +121,11 @@ def validate_access_level?(level)
render_api_error!("Wrong access level", 422)
end
group = find_group(params[:id])
if group.users_groups.find_by_user_id(params[:user_id])
if group.users_groups.find_by(user_id: params[:user_id])
render_api_error!("Already exists", 409)
end
group.add_users([params[:user_id]], params[:access_level])
member = group.users_groups.find_by_user_id(params[:user_id])
member = group.users_groups.find_by(user_id: params[:user_id])
present member.user, with: Entities::GroupMember, group: group
end
......@@ -139,7 +139,7 @@ def validate_access_level?(level)
# DELETE /groups/:id/members/:user_id
delete ":id/members/:user_id" do
group = find_group(params[:id])
member = group.users_groups.find_by_user_id(params[:user_id])
member = group.users_groups.find_by(user_id: params[:user_id])
if member.nil?
render_api_error!("404 Not Found - user_id:#{params[:user_id]} not a member of group #{group.name}",404)
else
......
......@@ -7,7 +7,7 @@ module APIHelpers
def current_user
private_token = (params[PRIVATE_TOKEN_PARAM] || env[PRIVATE_TOKEN_HEADER]).to_s
@current_user ||= User.find_by_authentication_token(private_token)
@current_user ||= User.find_by(authentication_token: private_token)
identifier = sudo_identifier()
# If the sudo is the current user do nothing
......@@ -47,7 +47,7 @@ def user_project
end
def find_project(id)
project = Project.find_by_id(id) || Project.find_with_namespace(id)
project = Project.find_by(id: id) || Project.find_with_namespace(id)
if project && can?(current_user, :read_project, project)
project
......
......@@ -81,7 +81,7 @@ def target_matches_fork(target_project_id,user_project)
merge_request.target_project = user_project
else
if target_matches_fork(target_project_id,user_project)
merge_request.target_project = Project.find_by_id(attrs[:target_project_id])
merge_request.target_project = Project.find_by(id: attrs[:target_project_id])
else
render_api_error!('(Bad Request) Specified target project that is not the source project, or the source fork of the project.', 400)
end
......
......@@ -266,7 +266,7 @@ def map_public_to_visibility_level(attrs)
authorize! :admin_project, user_project
required_attributes! [:access_level]
team_member = user_project.users_projects.find_by_user_id(params[:user_id])
team_member = user_project.users_projects.find_by(user_id: params[:user_id])
not_found!("User can not be found") if team_member.nil?
if team_member.update_attributes(project_access: params[:access_level])
......@@ -286,7 +286,7 @@ def map_public_to_visibility_level(attrs)
# DELETE /projects/:id/members/:user_id
delete ":id/members/:user_id" do
authorize! :admin_project, user_project
team_member = user_project.users_projects.find_by_user_id(params[:user_id])
team_member = user_project.users_projects.find_by(user_id: params[:user_id])
unless team_member.nil?
team_member.destroy
else
......
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