Commit b5291f95 authored by Gabriel Mazetto's avatar Gabriel Mazetto

Fixed Rubocop offenses

parent d1f1c5c6
class Dashboard::SnippetsController < Dashboard::ApplicationController class Dashboard::SnippetsController < Dashboard::ApplicationController
def index def index
@snippets = SnippetsFinder.new.execute(current_user, @snippets = SnippetsFinder.new.execute(
current_user,
filter: :by_user, filter: :by_user,
user: current_user, user: current_user,
scope: params[:scope] scope: params[:scope]
......
...@@ -68,7 +68,7 @@ class Projects::NotesController < Projects::ApplicationController ...@@ -68,7 +68,7 @@ class Projects::NotesController < Projects::ApplicationController
data = { data = {
author: current_user, author: current_user,
is_award: true, is_award: true,
note: note_params[:note].gsub(":", '') note: note_params[:note].delete(":")
} }
note = noteable.notes.find_by(data) note = noteable.notes.find_by(data)
......
...@@ -21,7 +21,7 @@ class Projects::ProtectedBranchesController < Projects::ApplicationController ...@@ -21,7 +21,7 @@ class Projects::ProtectedBranchesController < Projects::ApplicationController
if protected_branch && if protected_branch &&
protected_branch.update_attributes( protected_branch.update_attributes(
developers_can_push: params[:developers_can_push] developers_can_push: params[:developers_can_push]
) )
respond_to do |format| respond_to do |format|
......
...@@ -61,7 +61,7 @@ module ApplicationHelper ...@@ -61,7 +61,7 @@ module ApplicationHelper
options[:class] ||= '' options[:class] ||= ''
options[:class] << ' identicon' options[:class] << ' identicon'
bg_key = project.id % 7 bg_key = project.id % 7
style = "background-color: ##{ allowed_colors.values[bg_key] }; color: #555" style = "background-color: ##{allowed_colors.values[bg_key]}; color: #555"
content_tag(:div, class: options[:class], style: style) do content_tag(:div, class: options[:class], style: style) do
project.name[0, 1].upcase project.name[0, 1].upcase
......
module ExternalWikiHelper module ExternalWikiHelper
def get_project_wiki_path(project) def get_project_wiki_path(project)
external_wiki_service = project.services. external_wiki_service = project.services.
select { |service| service.to_param == 'external_wiki' }.first find { |service| service.to_param == 'external_wiki' }
if external_wiki_service.present? && external_wiki_service.active? if external_wiki_service.present? && external_wiki_service.active?
external_wiki_service.properties['external_wiki_url'] external_wiki_service.properties['external_wiki_url']
else else
......
...@@ -65,7 +65,8 @@ module GitlabMarkdownHelper ...@@ -65,7 +65,8 @@ module GitlabMarkdownHelper
end end
def asciidoc(text) def asciidoc(text)
Gitlab::Asciidoc.render(text, Gitlab::Asciidoc.render(
text,
project: @project, project: @project,
current_user: (current_user if defined?(current_user)), current_user: (current_user if defined?(current_user)),
......
...@@ -330,10 +330,9 @@ module ProjectsHelper ...@@ -330,10 +330,9 @@ module ProjectsHelper
def filename_path(project, filename) def filename_path(project, filename)
if project && blob = project.repository.send(filename) if project && blob = project.repository.send(filename)
namespace_project_blob_path( namespace_project_blob_path(
project.namespace, project.namespace,
project, project,
tree_join(project.default_branch, tree_join(project.default_branch, blob.name)
blob.name)
) )
end end
end end
......
...@@ -79,7 +79,7 @@ module TreeHelper ...@@ -79,7 +79,7 @@ module TreeHelper
part_path = File.join(part_path, part) unless part_path.empty? part_path = File.join(part_path, part) unless part_path.empty?
part_path = part if part_path.empty? part_path = part if part_path.empty?
next unless parts.last(2).include?(part) if parts.count > max_links next if parts.count > max_links && !parts.last(2).include?(part)
yield(part, tree_join(@ref, part_path)) yield(part, tree_join(@ref, part_path))
end end
end end
......
...@@ -17,7 +17,7 @@ class Notify < BaseMailer ...@@ -17,7 +17,7 @@ class Notify < BaseMailer
subject: subject, subject: subject,
body: body.html_safe, body: body.html_safe,
content_type: 'text/html' content_type: 'text/html'
) )
end end
# Splits "gitlab.corp.company.com" up into "gitlab.corp.company.com", # Splits "gitlab.corp.company.com" up into "gitlab.corp.company.com",
......
...@@ -126,12 +126,12 @@ class ApplicationSetting < ActiveRecord::Base ...@@ -126,12 +126,12 @@ class ApplicationSetting < ActiveRecord::Base
def restricted_signup_domains_raw=(values) def restricted_signup_domains_raw=(values)
self.restricted_signup_domains = [] self.restricted_signup_domains = []
self.restricted_signup_domains = values.split( self.restricted_signup_domains = values.split(
/\s*[,;]\s* # comma or semicolon, optionally surrounded by whitespace /\s*[,;]\s* # comma or semicolon, optionally surrounded by whitespace
| # or | # or
\s # any whitespace character \s # any whitespace character
| # or | # or
[\r\n] # any number of newline characters [\r\n] # any number of newline characters
/x) /x)
self.restricted_signup_domains.reject! { |d| d.empty? } self.restricted_signup_domains.reject! { |d| d.empty? }
end end
end end
...@@ -13,7 +13,7 @@ module TokenAuthenticatable ...@@ -13,7 +13,7 @@ module TokenAuthenticatable
@token_fields << token_field @token_fields << token_field
define_singleton_method("find_by_#{token_field}") do |token| define_singleton_method("find_by_#{token_field}") do |token|
where(token_field => token).first if token find_by(token_field => token) if token
end end
define_method("ensure_#{token_field}") do define_method("ensure_#{token_field}") do
...@@ -37,7 +37,7 @@ module TokenAuthenticatable ...@@ -37,7 +37,7 @@ module TokenAuthenticatable
def generate_token_for(token_field) def generate_token_for(token_field)
loop do loop do
token = Devise.friendly_token token = Devise.friendly_token
break token unless self.class.unscoped.where(token_field => token).first break token unless self.class.unscoped.find_by(token_field => token)
end end
end end
end end
...@@ -194,9 +194,7 @@ class MergeRequest < ActiveRecord::Base ...@@ -194,9 +194,7 @@ class MergeRequest < ActiveRecord::Base
similar_mrs = similar_mrs.where('id not in (?)', self.id) if self.id similar_mrs = similar_mrs.where('id not in (?)', self.id) if self.id
if similar_mrs.any? if similar_mrs.any?
errors.add :validate_branches, errors.add :validate_branches,
"Cannot Create: This merge request already exists: #{ "Cannot Create: This merge request already exists: #{similar_mrs.pluck(:title)}"
similar_mrs.pluck(:title)
}"
end end
end end
end end
......
...@@ -45,7 +45,7 @@ class Namespace < ActiveRecord::Base ...@@ -45,7 +45,7 @@ class Namespace < ActiveRecord::Base
class << self class << self
def by_path(path) def by_path(path)
where('lower(path) = :value', value: path.downcase).first find_by('lower(path) = :value', value: path.downcase)
end end
# Case insensetive search for namespace by path or name # Case insensetive search for namespace by path or name
...@@ -148,6 +148,6 @@ class Namespace < ActiveRecord::Base ...@@ -148,6 +148,6 @@ class Namespace < ActiveRecord::Base
end end
def find_fork_of(project) def find_fork_of(project)
projects.joins(:forked_project_link).where('forked_project_links.forked_from_project_id = ?', project.id).first projects.joins(:forked_project_link).find_by('forked_project_links.forked_from_project_id = ?', project.id)
end end
end end
...@@ -265,7 +265,7 @@ class Project < ActiveRecord::Base ...@@ -265,7 +265,7 @@ class Project < ActiveRecord::Base
joins(:namespace). joins(:namespace).
iwhere('namespaces.path' => namespace_path) iwhere('namespaces.path' => namespace_path)
projects.where('projects.path' => project_path).take || projects.find_by('projects.path' => project_path) ||
projects.iwhere('projects.path' => project_path).take projects.iwhere('projects.path' => project_path).take
end end
...@@ -450,7 +450,7 @@ class Project < ActiveRecord::Base ...@@ -450,7 +450,7 @@ class Project < ActiveRecord::Base
end end
def external_issue_tracker def external_issue_tracker
@external_issues_tracker ||= external_issues_trackers.select(&:activated?).first @external_issues_tracker ||= external_issues_trackers.find(&:activated?)
end end
def can_have_issues_tracker_id? def can_have_issues_tracker_id?
...@@ -496,7 +496,7 @@ class Project < ActiveRecord::Base ...@@ -496,7 +496,7 @@ class Project < ActiveRecord::Base
end end
def ci_service def ci_service
@ci_service ||= ci_services.select(&:activated?).first @ci_service ||= ci_services.find(&:activated?)
end end
def avatar_type def avatar_type
...@@ -547,7 +547,7 @@ class Project < ActiveRecord::Base ...@@ -547,7 +547,7 @@ class Project < ActiveRecord::Base
end end
def project_member_by_name_or_email(name = nil, email = nil) def project_member_by_name_or_email(name = nil, email = nil)
user = users.where('name like ? or email like ?', name, email).first user = users.find_by('name like ? or email like ?', name, email)
project_members.where(user: user) if user project_members.where(user: user) if user
end end
...@@ -722,7 +722,7 @@ class Project < ActiveRecord::Base ...@@ -722,7 +722,7 @@ class Project < ActiveRecord::Base
end end
def project_member(user) def project_member(user)
project_members.where(user_id: user).first project_members.find_by(user_id: user)
end end
def default_branch def default_branch
......
...@@ -27,12 +27,10 @@ class BambooService < CiService ...@@ -27,12 +27,10 @@ class BambooService < CiService
validates :build_key, presence: true, if: :activated? validates :build_key, presence: true, if: :activated?
validates :username, validates :username,
presence: true, presence: true,
if: ->(service) { service.password? }, if: ->(service) { service.activated? && service.password? }
if: :activated?
validates :password, validates :password,
presence: true, presence: true,
if: ->(service) { service.username? }, if: ->(service) { service.activated? && service.username? }
if: :activated?
attr_accessor :response attr_accessor :response
......
...@@ -58,6 +58,6 @@ class FlowdockService < Service ...@@ -58,6 +58,6 @@ class FlowdockService < Service
repo_url: "#{Gitlab.config.gitlab.url}/#{project.path_with_namespace}", repo_url: "#{Gitlab.config.gitlab.url}/#{project.path_with_namespace}",
commit_url: "#{Gitlab.config.gitlab.url}/#{project.path_with_namespace}/commit/%s", commit_url: "#{Gitlab.config.gitlab.url}/#{project.path_with_namespace}/commit/%s",
diff_url: "#{Gitlab.config.gitlab.url}/#{project.path_with_namespace}/compare/%s...%s", diff_url: "#{Gitlab.config.gitlab.url}/#{project.path_with_namespace}/compare/%s...%s",
) )
end end
end end
...@@ -57,6 +57,6 @@ class GemnasiumService < Service ...@@ -57,6 +57,6 @@ class GemnasiumService < Service
token: token, token: token,
api_key: api_key, api_key: api_key,
repo: project.repository.path_to_repo repo: project.repository.path_to_repo
) )
end end
end end
...@@ -27,12 +27,10 @@ class TeamcityService < CiService ...@@ -27,12 +27,10 @@ class TeamcityService < CiService
validates :build_type, presence: true, if: :activated? validates :build_type, presence: true, if: :activated?
validates :username, validates :username,
presence: true, presence: true,
if: ->(service) { service.password? }, if: ->(service) { service.activated? && service.password? }
if: :activated?
validates :password, validates :password,
presence: true, presence: true,
if: ->(service) { service.username? }, if: ->(service) { service.activated? && service.username? }
if: :activated?
attr_accessor :response attr_accessor :response
...@@ -147,6 +145,6 @@ class TeamcityService < CiService ...@@ -147,6 +145,6 @@ class TeamcityService < CiService
'</build>', '</build>',
headers: { 'Content-type' => 'application/xml' }, headers: { 'Content-type' => 'application/xml' },
basic_auth: auth basic_auth: auth
) )
end end
end end
...@@ -220,9 +220,9 @@ class User < ActiveRecord::Base ...@@ -220,9 +220,9 @@ class User < ActiveRecord::Base
def find_for_database_authentication(warden_conditions) def find_for_database_authentication(warden_conditions)
conditions = warden_conditions.dup conditions = warden_conditions.dup
if login = conditions.delete(:login) if login = conditions.delete(:login)
where(conditions).where(["lower(username) = :value OR lower(email) = :value", { value: login.downcase }]).first where(conditions).find_by("lower(username) = :value OR lower(email) = :value", value: login.downcase)
else else
where(conditions).first find_by(conditions)
end end
end end
...@@ -285,7 +285,7 @@ class User < ActiveRecord::Base ...@@ -285,7 +285,7 @@ class User < ActiveRecord::Base
end end
def by_username_or_id(name_or_id) def by_username_or_id(name_or_id)
where('users.username = ? OR users.id = ?', name_or_id.to_s, name_or_id.to_i).first find_by('users.username = ? OR users.id = ?', name_or_id.to_s, name_or_id.to_i)
end end
def build_user(attrs = {}) def build_user(attrs = {})
......
...@@ -112,7 +112,7 @@ module MergeRequests ...@@ -112,7 +112,7 @@ module MergeRequests
merge_requests_for_source_branch.each do |merge_request| merge_requests_for_source_branch.each do |merge_request|
SystemNoteService.change_branch_presence( SystemNoteService.change_branch_presence(
merge_request, merge_request.project, @current_user, merge_request, merge_request.project, @current_user,
:source, @branch_name, presence) :source, @branch_name, presence)
end end
end end
......
...@@ -31,11 +31,11 @@ if File.exists?(aws_file) ...@@ -31,11 +31,11 @@ if File.exists?(aws_file)
if Rails.env.test? if Rails.env.test?
Fog.mock! Fog.mock!
connection = ::Fog::Storage.new( connection = ::Fog::Storage.new(
aws_access_key_id: AWS_CONFIG['access_key_id'], aws_access_key_id: AWS_CONFIG['access_key_id'],
aws_secret_access_key: AWS_CONFIG['secret_access_key'], aws_secret_access_key: AWS_CONFIG['secret_access_key'],
provider: 'AWS', provider: 'AWS',
region: AWS_CONFIG['region'] region: AWS_CONFIG['region']
) )
connection.directories.create(key: AWS_CONFIG['bucket']) connection.directories.create(key: AWS_CONFIG['bucket'])
end end
end end
...@@ -441,7 +441,7 @@ Rails.application.routes.draw do ...@@ -441,7 +441,7 @@ Rails.application.routes.draw do
scope do scope do
post( post(
'/create_dir/*id', '/create_dir/*id',
to: 'tree#create_dir', to: 'tree#create_dir',
constraints: { id: /.+/ }, constraints: { id: /.+/ },
as: 'create_dir' as: 'create_dir'
......
...@@ -75,18 +75,18 @@ class Spinach::Features::ExploreGroups < Spinach::FeatureSteps ...@@ -75,18 +75,18 @@ class Spinach::Features::ExploreGroups < Spinach::FeatureSteps
name: projectname, name: projectname,
path: "#{groupname}-#{projectname}", path: "#{groupname}-#{projectname}",
visibility_level: visibility_level visibility_level: visibility_level
) )
create(:issue, create(:issue,
title: "#{projectname} feature", title: "#{projectname} feature",
project: project project: project
) )
create(:merge_request, create(:merge_request,
title: "#{projectname} feature implemented", title: "#{projectname} feature implemented",
source_project: project, source_project: project,
target_project: project target_project: project
) )
create(:closed_issue_event, create(:closed_issue_event,
project: project project: project
) )
end end
end end
...@@ -61,11 +61,11 @@ class Spinach::Features::ExploreProjects < Spinach::FeatureSteps ...@@ -61,11 +61,11 @@ class Spinach::Features::ExploreProjects < Spinach::FeatureSteps
create(:issue, create(:issue,
title: "Bug", title: "Bug",
project: public_project project: public_project
) )
create(:issue, create(:issue,
title: "New feature", title: "New feature",
project: public_project project: public_project
) )
visit namespace_project_issues_path(public_project.namespace, public_project) visit namespace_project_issues_path(public_project.namespace, public_project)
end end
...@@ -80,11 +80,11 @@ class Spinach::Features::ExploreProjects < Spinach::FeatureSteps ...@@ -80,11 +80,11 @@ class Spinach::Features::ExploreProjects < Spinach::FeatureSteps
create(:issue, create(:issue,
title: "Internal Bug", title: "Internal Bug",
project: internal_project project: internal_project
) )
create(:issue, create(:issue,
title: "New internal feature", title: "New internal feature",
project: internal_project project: internal_project
) )
visit namespace_project_issues_path(internal_project.namespace, internal_project) visit namespace_project_issues_path(internal_project.namespace, internal_project)
end end
...@@ -104,7 +104,7 @@ class Spinach::Features::ExploreProjects < Spinach::FeatureSteps ...@@ -104,7 +104,7 @@ class Spinach::Features::ExploreProjects < Spinach::FeatureSteps
title: "Bug fix for public project", title: "Bug fix for public project",
source_project: public_project, source_project: public_project,
target_project: public_project, target_project: public_project,
) )
end end
step 'I should see list of merge requests for "Community" project' do step 'I should see list of merge requests for "Community" project' do
...@@ -121,7 +121,7 @@ class Spinach::Features::ExploreProjects < Spinach::FeatureSteps ...@@ -121,7 +121,7 @@ class Spinach::Features::ExploreProjects < Spinach::FeatureSteps
title: "Feature implemented", title: "Feature implemented",
source_project: internal_project, source_project: internal_project,
target_project: internal_project target_project: internal_project
) )
end end
step 'I should see list of merge requests for "Internal" project' do step 'I should see list of merge requests for "Internal" project' do
......
...@@ -85,7 +85,7 @@ class Spinach::Features::Groups < Spinach::FeatureSteps ...@@ -85,7 +85,7 @@ class Spinach::Features::Groups < Spinach::FeatureSteps
step 'I should see new group "Owned" avatar' do step 'I should see new group "Owned" avatar' do
expect(owned_group.avatar).to be_instance_of AvatarUploader expect(owned_group.avatar).to be_instance_of AvatarUploader
expect(owned_group.avatar.url).to eq "/uploads/group/avatar/#{ Group.find_by(name:"Owned").id }/banana_sample.gif" expect(owned_group.avatar.url).to eq "/uploads/group/avatar/#{Group.find_by(name:"Owned").id}/banana_sample.gif"
end end
step 'I should see the "Remove avatar" button' do step 'I should see the "Remove avatar" button' do
......
...@@ -34,7 +34,7 @@ class Spinach::Features::Profile < Spinach::FeatureSteps ...@@ -34,7 +34,7 @@ class Spinach::Features::Profile < Spinach::FeatureSteps
step 'I should see new avatar' do step 'I should see new avatar' do
expect(@user.avatar).to be_instance_of AvatarUploader expect(@user.avatar).to be_instance_of AvatarUploader
expect(@user.avatar.url).to eq "/uploads/user/avatar/#{ @user.id }/banana_sample.gif" expect(@user.avatar.url).to eq "/uploads/user/avatar/#{@user.id}/banana_sample.gif"
end end
step 'I should see the "Remove avatar" button' do step 'I should see the "Remove avatar" button' do
......
...@@ -37,7 +37,7 @@ class Spinach::Features::Project < Spinach::FeatureSteps ...@@ -37,7 +37,7 @@ class Spinach::Features::Project < Spinach::FeatureSteps
step 'I should see new project avatar' do step 'I should see new project avatar' do
expect(@project.avatar).to be_instance_of AvatarUploader expect(@project.avatar).to be_instance_of AvatarUploader
url = @project.avatar.url url = @project.avatar.url
expect(url).to eq "/uploads/project/avatar/#{ @project.id }/banana_sample.gif" expect(url).to eq "/uploads/project/avatar/#{@project.id}/banana_sample.gif"
end end
step 'I should see the "Remove avatar" button' do step 'I should see the "Remove avatar" button' do
......
...@@ -230,13 +230,13 @@ class Spinach::Features::ProjectSourceBrowseFiles < Spinach::FeatureSteps ...@@ -230,13 +230,13 @@ class Spinach::Features::ProjectSourceBrowseFiles < Spinach::FeatureSteps
end end
step 'I am redirected to the new file' do step 'I am redirected to the new file' do
expect(current_path).to eq(namespace_project_blob_path( expect(current_path).to eq(
@project.namespace, @project, 'master/' + new_file_name)) namespace_project_blob_path(@project.namespace, @project, 'master/' + new_file_name))
end end
step 'I am redirected to the new file with directory' do step 'I am redirected to the new file with directory' do
expect(current_path).to eq(namespace_project_blob_path( expect(current_path).to eq(
@project.namespace, @project, 'master/' + new_file_name_with_directory)) namespace_project_blob_path(@project.namespace, @project, 'master/' + new_file_name_with_directory))
end end
step 'I am redirected to the new merge request page' do step 'I am redirected to the new merge request page' do
...@@ -244,8 +244,8 @@ class Spinach::Features::ProjectSourceBrowseFiles < Spinach::FeatureSteps ...@@ -244,8 +244,8 @@ class Spinach::Features::ProjectSourceBrowseFiles < Spinach::FeatureSteps
end end
step 'I am redirected to the root directory' do step 'I am redirected to the root directory' do
expect(current_path).to eq(namespace_project_tree_path( expect(current_path).to eq(
@project.namespace, @project, 'master/')) namespace_project_tree_path(@project.namespace, @project, 'master/'))
end end
step "I don't see the permalink link" do step "I don't see the permalink link" do
......
...@@ -212,8 +212,8 @@ module SharedPaths ...@@ -212,8 +212,8 @@ module SharedPaths
end end
step 'I visit a binary file in the repo' do step 'I visit a binary file in the repo' do
visit namespace_project_blob_path(@project.namespace, @project, File.join( visit namespace_project_blob_path(@project.namespace, @project,
root_ref, 'files/images/logo-black.png')) File.join(root_ref, 'files/images/logo-black.png'))
end end
step "I visit my project's commits page" do step "I visit my project's commits page" do
...@@ -316,8 +316,8 @@ module SharedPaths ...@@ -316,8 +316,8 @@ module SharedPaths
end end
step 'I am on the ".gitignore" edit file page' do step 'I am on the ".gitignore" edit file page' do
expect(current_path).to eq(namespace_project_edit_blob_path( expect(current_path).to eq(
@project.namespace, @project, File.join(root_ref, '.gitignore'))) namespace_project_edit_blob_path(@project.namespace, @project, File.join(root_ref, '.gitignore')))
end end
step 'I visit project source page for "6d39438"' do step 'I visit project source page for "6d39438"' do
......
...@@ -67,7 +67,7 @@ module API ...@@ -67,7 +67,7 @@ module API
expose :shared_runners_enabled expose :shared_runners_enabled
expose :creator_id expose :creator_id
expose :namespace expose :namespace
expose :forked_from_project, using: Entities::ForkedFromProject, if: lambda{ | project, options | project.forked? } expose :forked_from_project, using: Entities::ForkedFromProject, if: lambda{ |project, options| project.forked? }
expose :avatar_url expose :avatar_url
expose :star_count, :forks_count expose :star_count, :forks_count
end end
......
...@@ -2,7 +2,7 @@ module Gitlab ...@@ -2,7 +2,7 @@ module Gitlab
class Shell class Shell
class Error < StandardError; end class Error < StandardError; end
class KeyAdder < Struct.new(:io) KeyAdder = Struct.new(:io) do
def add_key(id, key) def add_key(id, key)
key.gsub!(/[[:space:]]+/, ' ').strip! key.gsub!(/[[:space:]]+/, ' ').strip!
io.puts("#{id}\t#{key}") io.puts("#{id}\t#{key}")
......