Commit fb0f8b98 authored by Douwe Maan's avatar Douwe Maan

Fix EE offenses

parent f5faea30
......@@ -62,9 +62,9 @@ class AutocompleteController < ApplicationController
return if params[:project_id].blank?
return if ability.blank?
@users.to_a.
select { |user| user.can?(ability, @project) }.
take(Kaminari.config.default_per_page)
@users.to_a
.select { |user| user.can?(ability, @project) }
.take(Kaminari.config.default_per_page)
end
def find_users
......
......@@ -42,7 +42,7 @@ module MembershipActions
end
def log_audit_event(member, options = {})
AuditEventService.new(current_user, membershipable, options).
for_member(member).security_event
AuditEventService.new(current_user, membershipable, options)
.for_member(member).security_event
end
end
......@@ -66,7 +66,7 @@ module ServiceParams
:multiproject_enabled,
:pass_unstable,
:project_name
]
].freeze
# Parameters to ignore if no value is specified
FILTER_BLANK_PARAMS = [:password].freeze
......
......@@ -6,9 +6,9 @@ class Groups::AnalyticsController < Groups::ApplicationController
def show
@users = @group.users
@start_date = params[:start_date] || Date.today - 1.week
@events = Event.contributions.
where("created_at > ?", @start_date).
where(project_id: @group.projects)
@events = Event.contributions
.where("created_at > ?", @start_date)
.where(project_id: @group.projects)
@stats = {}
......
......@@ -63,8 +63,8 @@ class Projects::DeployKeysController < Projects::ApplicationController
end
def log_audit_event(key_title, options = {})
AuditEventService.new(current_user, @project, options).
for_deploy_key(key_title).security_event
AuditEventService.new(current_user, @project, options)
.for_deploy_key(key_title).security_event
end
def load_key
......
......@@ -528,9 +528,9 @@ class Projects::MergeRequestsController < Projects::ApplicationController
return render_404
end
::MergeRequests::ApprovalService.
new(project, current_user).
execute(@merge_request)
::MergeRequests::ApprovalService
.new(project, current_user)
.execute(@merge_request)
render_approvals_json
end
......@@ -541,9 +541,9 @@ class Projects::MergeRequestsController < Projects::ApplicationController
def unapprove
if @merge_request.has_approved?(current_user)
::MergeRequests::RemoveApprovalService.
new(project, current_user).
execute(@merge_request)
::MergeRequests::RemoveApprovalService
.new(project, current_user)
.execute(@merge_request)
end
render_approvals_json
......
......@@ -76,7 +76,7 @@ class Projects::ProtectedBranchesController < Projects::ApplicationController
def load_gon_index
params = { open_branches: @project.open_branches.map { |br| { text: br.name, id: br.name, title: br.name } } }
params.merge!(current_project_id: @project.id) if @project
params[:current_project_id] = @project.id if @project
gon.push(params.merge(access_levels_options))
end
end
......@@ -4,7 +4,7 @@ module AuditEventsHelper
end
def select_keys(key, value)
if key.match(/^(author|target)_.*/)
if key =~ /^(author|target)_.*/
""
else
"#{key} <strong>#{value}</strong>"
......
......@@ -110,13 +110,14 @@ module MergeRequestsHelper
more_approvals = merge_request.approvals_left - merge_request.approvers_left.count
approvers_names = merge_request.approvers_left.map(&:name)
if more_approvals > 0
str << " (from #{render_items_list(approvers_names + ["#{more_approvals} more"])})"
elsif more_approvals < 0
str << " (from #{render_items_list(approvers_names, "or")})"
else
str << " (from #{render_items_list(approvers_names)})"
end
str <<
if more_approvals > 0
" (from #{render_items_list(approvers_names + ["#{more_approvals} more"])})"
elsif more_approvals < 0
" (from #{render_items_list(approvers_names, "or")})"
else
" (from #{render_items_list(approvers_names)})"
end
end
str
......
......@@ -244,10 +244,10 @@ class ApplicationSetting < ActiveRecord::Base
end
def update_mirror_cron_jobs
Project.mirror.where('sync_time < ?', minimum_mirror_sync_time).
update_all(sync_time: minimum_mirror_sync_time)
RemoteMirror.where('sync_time < ?', minimum_mirror_sync_time).
update_all(sync_time: minimum_mirror_sync_time)
Project.mirror.where('sync_time < ?', minimum_mirror_sync_time)
.update_all(sync_time: minimum_mirror_sync_time)
RemoteMirror.where('sync_time < ?', minimum_mirror_sync_time)
.update_all(sync_time: minimum_mirror_sync_time)
Gitlab::Mirror.configure_cron_jobs!
end
......
......@@ -50,9 +50,9 @@ module Approvable
wheres << "id IN (#{project.group.members.where(has_access).select(:user_id).to_sql})"
end
users = User.
active.
where("(#{wheres.join(' OR ')}) AND id NOT IN (#{approvals.select(:user_id).to_sql})")
users = User
.active
.where("(#{wheres.join(' OR ')}) AND id NOT IN (#{approvals.select(:user_id).to_sql})")
users = users.where.not(id: author.id) if author
......
......@@ -14,7 +14,7 @@ module Elastic
analyzer: {
default: {
tokenizer: 'standard',
filter: ['standard', 'lowercase', 'my_stemmer']
filter: %w(standard lowercase my_stemmer)
},
my_ngram_analyzer: {
tokenizer: 'my_ngram_tokenizer',
......@@ -32,7 +32,7 @@ module Elastic
type: 'nGram',
min_gram: 2,
max_gram: 3,
token_chars: [ 'letter', 'digit' ]
token_chars: %w(letter digit)
}
}
}
......@@ -96,7 +96,7 @@ module Elastic
{ index: { _id: r.id, _parent: r.es_parent, data: r.__elasticsearch__.as_indexed_json } }
end
options.merge!(transform: transform)
options[:transform] = transform
self.import(options)
end
......
......@@ -38,11 +38,12 @@ module Elastic
end
def self.elastic_search(query, options: {})
if query =~ /#(\d+)\z/
query_hash = iid_query_hash(query_hash, $1)
else
query_hash = basic_query_hash(%w(title^2 description), query)
end
query_hash =
if query =~ /#(\d+)\z/
iid_query_hash(query_hash, $1)
else
basic_query_hash(%w(title^2 description), query)
end
query_hash = project_ids_filter(query_hash, options)
query_hash = confidentiality_filter(query_hash, options[:current_user])
......@@ -58,10 +59,12 @@ module Elastic
bool: {
should: [
{ term: { confidential: false } },
{ bool: {
{
bool: {
must: [
{ term: { confidential: true } },
{ bool: {
{
bool: {
should: [
{ term: { author_id: current_user.id } },
{ term: { assignee_id: current_user.id } },
......
......@@ -60,11 +60,12 @@ module Elastic
end
def self.elastic_search(query, options: {})
if query =~ /#(\d+)\z/
query_hash = iid_query_hash(query_hash, $1)
else
query_hash = basic_query_hash(%w(title^2 description), query)
end
query_hash =
if query =~ /#(\d+)\z/
iid_query_hash(query_hash, $1)
else
basic_query_hash(%w(title^2 description), query)
end
query_hash = project_ids_filter(query_hash, options)
......
......@@ -90,7 +90,8 @@ module Elastic
bool: {
must: [
{ term: { "issue.confidential" => true } },
{ bool: {
{
bool: {
should: [
{ term: { "issue.author_id" => current_user.id } },
{ term: { "issue.assignee_id" => current_user.id } },
......
......@@ -11,9 +11,7 @@ module Elastic
project.id
end
def project_id
project.id
end
delegate :id, to: :project, prefix: true
def client_for_indexing
self.__elasticsearch__.client
......
......@@ -11,9 +11,7 @@ module Elastic
"wiki_#{project.id}"
end
def project_id
project.id
end
delegate :id, to: :project, prefix: true
def client_for_indexing
self.__elasticsearch__.client
......
......@@ -10,9 +10,9 @@ class Issue < ActiveRecord::Base
include FasterCacheKeys
WEIGHT_RANGE = 1..9
WEIGHT_ALL = 'Everything'
WEIGHT_ANY = 'Any Weight'
WEIGHT_NONE = 'No Weight'
WEIGHT_ALL = 'Everything'.freeze
WEIGHT_ANY = 'Any Weight'.freeze
WEIGHT_NONE = 'No Weight'.freeze
DueDateStruct = Struct.new(:title, :name).freeze
NoDueDate = DueDateStruct.new('No Due Date', '0').freeze
......
......@@ -11,8 +11,8 @@ class Repository
CommitError = Class.new(StandardError)
MIRROR_REMOTE = "upstream"
MIRROR_GEO = "geo"
MIRROR_REMOTE = "upstream".freeze
MIRROR_GEO = "geo".freeze
# Methods that cache data from the Git repository.
#
......
......@@ -347,8 +347,8 @@ class User < ActiveRecord::Base
end
def non_ldap
joins('LEFT JOIN identities ON identities.user_id = users.id').
where('identities.provider IS NULL OR identities.provider NOT LIKE ?', 'ldap%')
joins('LEFT JOIN identities ON identities.user_id = users.id')
.where('identities.provider IS NULL OR identities.provider NOT LIKE ?', 'ldap%')
end
def reference_prefix
......
......@@ -11,19 +11,19 @@ module EE
return super unless shared_runner_build_limits_feature_enabled?
# select projects which have allowed number of shared runner minutes or are public
super.
where("projects.visibility_level=? OR (#{builds_check_limit.to_sql})=1",
super
.where("projects.visibility_level=? OR (#{builds_check_limit.to_sql})=1",
::Gitlab::VisibilityLevel::PUBLIC)
end
def builds_check_limit
::Namespace.reorder(nil).
where('namespaces.id = projects.namespace_id').
joins('LEFT JOIN namespace_statistics ON namespace_statistics.namespace_id = namespaces.id').
where('COALESCE(namespaces.shared_runners_minutes_limit, ?, 0) = 0 OR ' \
::Namespace.reorder(nil)
.where('namespaces.id = projects.namespace_id')
.joins('LEFT JOIN namespace_statistics ON namespace_statistics.namespace_id = namespaces.id')
.where('COALESCE(namespaces.shared_runners_minutes_limit, ?, 0) = 0 OR ' \
'COALESCE(namespace_statistics.shared_runners_seconds, 0) < COALESCE(namespaces.shared_runners_minutes_limit, ?, 0) * 60',
application_shared_runners_minutes, application_shared_runners_minutes).
select('1')
application_shared_runners_minutes, application_shared_runners_minutes)
.select('1')
end
def application_shared_runners_minutes
......
......@@ -64,7 +64,7 @@ module Projects
def update_tags(&block)
old_tags = repository_tags_with_target.each_with_object({}) { |tag, tags| tags[tag.name] = tag }
fetch_result = block.call
fetch_result = yield
return fetch_result unless fetch_result
repository.expire_tags_cache
......
......@@ -5,7 +5,7 @@ class ElasticIndexerWorker
sidekiq_options queue: :elasticsearch, retry: 2
ISSUE_TRACKED_FIELDS = %w(assignee_id author_id confidential)
ISSUE_TRACKED_FIELDS = [%w(assignee_id author_id confidential)].freeze
def perform(operation, class_name, record_id, options = {})
return true unless current_application_settings.elasticsearch_indexing?
......
......@@ -7,7 +7,7 @@ class RebaseWorker
current_user = User.find(current_user_id)
merge_request = MergeRequest.find(merge_request_id)
MergeRequests::RebaseService.new(merge_request.target_project, current_user).
execute(merge_request)
MergeRequests::RebaseService.new(merge_request.target_project, current_user)
.execute(merge_request)
end
end
......@@ -15,9 +15,9 @@ class UpdateAllMirrorsWorker
end
def fail_stuck_mirrors!
stuck = Project.mirror.
with_import_status(:started).
where('mirror_last_update_at < ?', 2.hours.ago)
stuck = Project.mirror
.with_import_status(:started)
.where('mirror_last_update_at < ?', 2.hours.ago)
stuck.find_each(batch_size: 50) do |project|
project.mark_import_as_failed('The mirror update took too long to complete.')
......
......@@ -68,7 +68,8 @@ class Settings < Settingslogic
# By inserting in the Kerberos dedicated URL ":@", we give to curl an empty username and password and GSS auth goes ahead
# Known bug reported in http://sourceforge.net/p/curl/bugs/440/ and http://curl.haxx.se/docs/knownbugs.html
def build_gitlab_kerberos_url
[ kerberos_protocol,
[
kerberos_protocol,
"://:@",
gitlab.host,
":#{kerberos_port}",
......
......@@ -5,7 +5,7 @@ class AddColumnUserIdToProtectedBranchesAccessLevels < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = true
DOWNTIME_REASON = "This migrations adds two indexes, and so requires downtime."
DOWNTIME_REASON = "This migrations adds two indexes, and so requires downtime.".freeze
# When using the methods "add_concurrent_index" or "add_column_with_default"
# you must disable the use of transactions as these methods can not run in an
......
......@@ -5,7 +5,7 @@ class AddGroupIdColumnsToProtectedBranchAccessLevels < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = true
DOWNTIME_REASON = "This migrations adds two foreign keys, and so requires downtime."
DOWNTIME_REASON = "This migrations adds two foreign keys, and so requires downtime.".freeze
# When using the methods "add_concurrent_index" or "add_column_with_default"
# you must disable the use of transactions as these methods can not run in an
......
......@@ -6,7 +6,7 @@ class AddApproverGroups < ActiveRecord::Migration
DOWNTIME = true
DOWNTIME_REASON = 'Adding foreign key'
DOWNTIME_REASON = 'Adding foreign key'.freeze
def change
create_table :approver_groups do |t|
......
......@@ -5,7 +5,7 @@ class CreateUserActivities < ActiveRecord::Migration
# When a migration requires downtime you **must** uncomment the following
# constant and define a short and easy to understand explanation as to why the
# migration requires downtime.
DOWNTIME_REASON = 'Adding foreign key'
DOWNTIME_REASON = 'Adding foreign key'.freeze
# When using the methods "add_concurrent_index" or "add_column_with_default"
# you must disable the use of transactions as these methods can not run in an
......
......@@ -6,7 +6,7 @@ class MigrateEESidekiqQueuesFromDefault < ActiveRecord::Migration
DOWNTIME = true
DOWNTIME_REASON = <<-EOF
DOWNTIME_REASON = <<-EOF.freeze
Moving Sidekiq jobs from queues requires Sidekiq to be stopped. Not stopping
Sidekiq will result in the loss of jobs that are scheduled after this
migration completes.
......@@ -24,7 +24,7 @@ class MigrateEESidekiqQueuesFromDefault < ActiveRecord::Migration
'LdapGroupSyncWorker' => :cronjob,
'LdapSyncWorker' => :cronjob,
}
}
}.freeze
def up
Sidekiq.redis do |redis|
......@@ -46,7 +46,7 @@ class MigrateEESidekiqQueuesFromDefault < ActiveRecord::Migration
def migrate_from_queue(redis, queue, job_mapping)
while job = redis.lpop("queue:#{queue}")
payload = JSON.load(job)
payload = JSON.parse(job)
new_queue = job_mapping[payload['class']]
# If we have no target queue to migrate to we're probably dealing with
......
......@@ -20,7 +20,7 @@ module EE
attributes: %w(dn cn memberuid member submember uniquemember memberof)
}
options.merge!(size: size) if size
options[:size] = size if size
ldap_search(options).map do |entry|
LDAP::Group.new(entry, self)
......
......@@ -39,9 +39,7 @@ module EE
entry.memberuid
end
def dn
entry.dn
end
delegate :dn, to: :entry
def member_dns(nested_groups_to_skip = [])
dns = []
......
......@@ -4,9 +4,9 @@ module EE
module Person
def ssh_keys
if config.sync_ssh_keys? && entry.respond_to?(config.sync_ssh_keys)
entry[config.sync_ssh_keys.to_sym].
map { |key| key[/(ssh|ecdsa)-[^ ]+ [^\s]+/] }.
compact
entry[config.sync_ssh_keys.to_sym]
.map { |key| key[/(ssh|ecdsa)-[^ ]+ [^\s]+/] }
.compact
else
[]
end
......@@ -23,12 +23,12 @@ module EE
require 'net/ldap/dn'
dn_components = []
Net::LDAP::DN.new(dn).each_pair { |name, value| dn_components << { name: name, value: value } }
dn_components.
reverse.
take_while { |rdn| rdn[:name].casecmp('DC').zero? }. # Domain Component
map { |rdn| rdn[:value] }.
reverse.
join('.')
dn_components
.reverse
.take_while { |rdn| rdn[:name].casecmp('DC').zero? } # Domain Component
.map { |rdn| rdn[:value] }
.reverse
.join('.')
end
end
end
......
......@@ -29,7 +29,8 @@ module Gitlab
client.indices.create index: index_name,
body: {
settings: settings.to_hash,
mappings: mappings.to_hash }
mappings: mappings.to_hash
}
end
def self.delete_index
......
......@@ -2,7 +2,7 @@ module Gitlab
module Geo
class UpdateQueue
BATCH_SIZE = 250
NAMESPACE = 'geo:gitlab'
NAMESPACE = 'geo:gitlab'.freeze
def initialize(queue)
@queue = queue
......
......@@ -268,7 +268,7 @@ module Gitlab
return false unless Gitlab.config.gitlab_shell.git_annex_enabled
return false if changes.blank?
changes = changes.lines if changes.kind_of?(String)
changes = changes.lines if changes.is_a?(String)
# Iterate over all changes to find if user allowed all of them to be applied
# 0000000000000000000000000000000000000000 3073696294ddd52e9e6b6fc3f429109cac24626f refs/heads/synced/git-annex
......
......@@ -155,9 +155,7 @@ module Gitlab
user.update(email: ldap_email)
end
def sync_ssh_keys?
ldap_config.sync_ssh_keys?
end
delegate :sync_ssh_keys?, to: :ldap_config
def import_kerberos_identities?
# Kerberos may be enabled for Git HTTP access and/or as an Omniauth provider
......
module Gitlab
module Middleware
class ReadonlyGeo
DISALLOWED_METHODS = %w(POST PATCH PUT DELETE)
APPLICATION_JSON = 'application/json'
DISALLOWED_METHODS = [%w(POST PATCH PUT DELETE)].freeze
APPLICATION_JSON = 'application/json'.freeze
API_VERSIONS = (3..4)
def initialize(app)
......@@ -37,7 +37,7 @@ module Gitlab
end
def geo_routes
geo_routes = ['refresh_wikis', 'receive_events']
geo_routes = %w(refresh_wikis receive_events)
API_VERSIONS.flat_map { |version| geo_routes.map { |route| "api/v#{version}/geo/#{route}" } }
end
......
......@@ -37,11 +37,12 @@ module Gitlab
end
if admin_groups_enabled? && @user
if (auth_hash.groups & Gitlab::Saml::Config.admin_groups).empty?
@user.admin = false
else
@user.admin = true
end
@user.admin =
if (auth_hash.groups & Gitlab::Saml::Config.admin_groups).empty?
false
else
true
end
end
@user
......
......@@ -89,7 +89,7 @@ module Gitlab
end
def list_remote_tags(storage, name, remote)
output, status = Popen::popen([gitlab_shell_projects_path, 'list-remote-tags', storage, "#{name}.git", remote])
output, status = Popen.popen([gitlab_shell_projects_path, 'list-remote-tags', storage, "#{name}.git", remote])
tags_with_targets = []
raise Error, output unless status.zero?
......@@ -130,7 +130,7 @@ module Gitlab
args << '--force' if forced
args << '--no-tags' if no_tags
output, status = Popen::popen(args)
output, status = Popen.popen(args)
raise Error, output unless status.zero?
true
end
......@@ -308,7 +308,7 @@ module Gitlab
#
def push_remote_branches(storage, project_name, remote_name, branch_names)
args = [gitlab_shell_projects_path, 'push-branches', storage, "#{project_name}.git", remote_name, *branch_names]
output, status = Popen::popen(args)
output, status = Popen.popen(args)
raise Error, output unless status.zero?
true
end
......@@ -324,7 +324,7 @@ module Gitlab
#
def delete_remote_branches(storage, project_name, remote_name, branch_names)
args = [gitlab_shell_projects_path, 'delete-remote-branches', storage, "#{project_name}.git", remote_name, *branch_names]
output, status = Popen::popen(args)
output, status = Popen.popen(args)
raise Error, output unless status.zero?
true
end
......
module Gitlab
module SidekiqCluster
# The signals that should terminate both the master and workers.
TERMINATE_SIGNALS = %i(INT TERM)
TERMINATE_SIGNALS = [%i(INT TERM)].freeze
# The signals that should simply be forwarded to the workers.
FORWARD_SIGNALS = %i(TTIN USR1 USR2 HUP)
FORWARD_SIGNALS = [%i(TTIN USR1 USR2 HUP)].freeze
# Traps the given signals and yields the block whenever these signals are
# received.
......
......@@ -10,7 +10,7 @@ module Gitlab
:last_page?,
:next_page, to: :pagination_delegate
KEY = 'user/activities'
KEY = 'user/activities'.freeze
def self.record(user)
Gitlab::Redis.with do |redis|
......
......@@ -1132,7 +1132,7 @@ namespace :gitlab do
try_fixing_it(
'If you have a valid certificate make sure you have the full certificate chain in the pem file'
)
rescue Exception => e
rescue Exception => e # rubocop:disable Lint/RescueException
display_error.call(e)
end
end
......
......@@ -15,7 +15,7 @@ namespace :gitlab do
# check redis version
redis_version = run_and_match(%w(redis-cli --version), /redis-cli (\d+\.\d+\.\d+)/).to_a
# check for system defined proxies
proxies = Gitlab::Proxy.detect_proxy.map{|k,v| "#{k}: #{v}"}.join("\n\t\t")
proxies = Gitlab::Proxy.detect_proxy.map{|k, v| "#{k}: #{v}"}.join("\n\t\t")
puts ""
puts "System information".color(:yellow)
......@@ -40,12 +40,12 @@ namespace :gitlab do
http_clone_url = project.http_url_to_repo
ssh_clone_url = project.ssh_url_to_repo
if Gitlab::Geo.current_node
geo_node_type = Gitlab::Geo.current_node.primary ? 'Primary' : 'Secondary'
else
geo_node_type = 'Undefined'.color(:red)
end
geo_node_type =
if Gitlab::Geo.current_node
Gitlab::Geo.current_node.primary ? 'Primary' : 'Secondary'
else
'Undefined'.color(:red)
end
omniauth_providers = Gitlab.config.omniauth.providers
omniauth_providers.map! { |provider| provider['name'] }
......
......@@ -5,7 +5,6 @@ namespace :gitlab do
raise 'No LDAP server hash defined. See config/gitlab.yml.example for an example' unless config.servers.any?
provider = config.servers.first['provider_name']
valid_providers = config.providers
unmigrated_group_links = LdapGroupLink.where('provider IS NULL OR provider NOT IN (?)', config.providers)
puts "found #{unmigrated_group_links.count} unmigrated LDAP links"
puts "setting provider to #{provider}"
......
......@@ -12,8 +12,7 @@ describe Admin::PushRulesController do
params =
{ deny_delete_tag: true, delete_branch_regex: "any", commit_message_regex: "any",
force_push_regex: "any", author_email_regex: "any", member_check: true, file_name_regex: "any",
max_file_size: "0", prevent_secrets: true
}
max_file_size: "0", prevent_secrets: true }
expect_any_instance_of(PushRule).to receive(:update_attributes).with(params)
......
......@@ -25,8 +25,8 @@ describe Projects::ApproverGroupsController do
allow(controller).to receive(:authorize_create_merge_request!)
expect { go_delete(project, merge_request_id: merge.to_param, id: approver_group.id) }.
to change { merge.reload.approver_groups.count }.by(-1)
expect { go_delete(project, merge_request_id: merge.to_param, id: approver_group.id) }
.to change { merge.reload.approver_groups.count }.by(-1)
end
end
......@@ -46,8 +46,8 @@ describe Projects::ApproverGroupsController do
allow(controller).to receive(:authorize_admin_project!).and_return(true)
expect { go_delete(project, id: approver_group.id) }.
to change { project.approver_groups.count }.by(-1)
expect { go_delete(project, id: approver_group.id) }
.to change { project.approver_groups.count }.by(-1)
end
end
......
......@@ -25,8 +25,8 @@ describe Projects::ApproversController do
allow(controller).to receive(:authorize_create_merge_request!)
expect { go_delete(project, merge_request_id: merge.to_param, id: approver.id) }.
to change { merge.reload.approvers.count }.by(-1)
expect { go_delete(project, merge_request_id: merge.to_param, id: approver.id) }
.to change { merge.reload.approvers.count }.by(-1)
end
end
......@@ -46,8 +46,8 @@ describe Projects::ApproversController do
allow(controller).to receive(:authorize_admin_project!).and_return(true)
expect { go_delete(project, id: approver.id) }.
to change { project.approvers.count }.by(-1)
expect { go_delete(project, id: approver.id) }
.to change { project.approvers.count }.by(-1)
end
end
......
......@@ -148,7 +148,7 @@ describe Projects::MergeRequestsController do
context 'approvals' do
def json_response
JSON.load(response.body)
JSON.parse(response.body)
end
let(:approver) { create(:user) }
......
......@@ -116,7 +116,7 @@ describe Projects::MirrorsController do
def do_put(project, options)
attrs = { namespace_id: project.namespace.to_param, project_id: project.to_param }
attrs.merge!(project: options)
attrs[:project] = options
put :update, attrs
end
......
......@@ -92,8 +92,8 @@ describe Projects::SnippetsController do
context 'when the snippet is public' do
it 'creates the snippet' do
expect { create_snippet(private_project, visibility_level: Snippet::PUBLIC) }.
to change { Snippet.count }.by(1)
expect { create_snippet(private_project, visibility_level: Snippet::PUBLIC) }
.to change { Snippet.count }.by(1)
end
end
end
......@@ -108,14 +108,14 @@ describe Projects::SnippetsController do
context 'when the snippet is public' do
it 'rejects the shippet' do
expect { create_snippet(project, visibility_level: Snippet::PUBLIC) }.
not_to change { Snippet.count }
expect { create_snippet(project, visibility_level: Snippet::PUBLIC) }
.not_to change { Snippet.count }
expect(response).to render_template(:new)
end
it 'creates a spam log' do
expect { create_snippet(project, visibility_level: Snippet::PUBLIC) }.
to change { SpamLog.count }.by(1)
expect { create_snippet(project, visibility_level: Snippet::PUBLIC) }
.to change { SpamLog.count }.by(1)
end
end
end
......
......@@ -47,11 +47,11 @@ describe MergeRequestsHelper do
end
it "returns two items in the list" do
expect(render_items_list(["user", "user1"])).to eq("user and user1")
expect(render_items_list(%w(user user1))).to eq("user and user1")
end
it "returns three items in the list" do
expect(render_items_list(["user", "user1", "user2"])).to eq("user, user1 and user2")
expect(render_items_list(%w(user user1 user2))).to eq("user, user1 and user2")
end
end
......
......@@ -273,8 +273,8 @@ describe Banzai::Filter::MilestoneReferenceFilter, lib: true do
let!(:result) { reference_filter("See #{reference}") }
it 'points to referenced project milestone page' do
expect(result.css('a').first.attr('href')).to eq urls.
namespace_project_milestone_url(another_project.namespace,
expect(result.css('a').first.attr('href')).to eq urls
.namespace_project_milestone_url(another_project.namespace,
another_project,
milestone)
end
......
......@@ -98,14 +98,14 @@ describe Banzai::Filter::UploadLinkFilter, lib: true do
it 'rebuilds relative URL for a link' do
doc = filter(link('/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg'))
expect(doc.at_css('a')['href']).
to eq "#{geo_url}/#{project.path_with_namespace}/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg"
expect(doc.at_css('a')['href'])
.to eq "#{geo_url}/#{project.path_with_namespace}/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg"
end
it 'rebuilds relative URL for an image' do
doc = filter(link('/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg'))
expect(doc.at_css('a')['href']).
to eq "#{geo_url}/#{project.path_with_namespace}/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg"
expect(doc.at_css('a')['href'])
.to eq "#{geo_url}/#{project.path_with_namespace}/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg"
end
it 'does not modify absolute URL' do
......
......@@ -29,7 +29,7 @@ describe Gitlab::LDAP::Adapter, lib: true do
end
it 'returns a group object if search returns a result' do
entry = ldap_group_entry(['john', 'mary'], cn: 'group1')
entry = ldap_group_entry(%w(john mary), cn: 'group1')
allow(adapter).to receive(:ldap_search).and_return([entry])
results = adapter.groups('group1')
......
......@@ -66,7 +66,7 @@ describe EE::Gitlab::LDAP::Sync::Group, lib: true do
before do
allow(Gitlab::LDAP::Config)
.to receive(:providers).and_return(['main', 'secondary'])
.to receive(:providers).and_return(%w(main secondary))
allow(EE::Gitlab::LDAP::Sync::Proxy)
.to receive(:open).and_yield(double('proxy').as_null_object)
end
......
......@@ -56,16 +56,16 @@ describe Gitlab::Shell, lib: true do
describe 'mv_repository' do
it 'executes the command' do
expect(Gitlab::Utils).to receive(:system_silent).
with([projects_path, 'mv-project', 'storage/path', 'project/path.git', 'new/path.git'])
expect(Gitlab::Utils).to receive(:system_silent)
.with([projects_path, 'mv-project', 'storage/path', 'project/path.git', 'new/path.git'])
gitlab_shell.mv_repository('storage/path', 'project/path', 'new/path')
end
end
describe 'mv_storage' do
it 'executes the command' do
expect(Gitlab::Utils).to receive(:system_silent).
with([projects_path, 'mv-storage', 'current/storage', 'project/path.git', 'new/storage'])
expect(Gitlab::Utils).to receive(:system_silent)
.with([projects_path, 'mv-storage', 'current/storage', 'project/path.git', 'new/storage'])
gitlab_shell.mv_storage('current/storage', 'project/path', 'new/storage')
end
end
......
......@@ -54,11 +54,11 @@ describe Gitlab::SidekiqCluster::CLI do
it 'runs until one of the processes has been terminated' do
allow(cli).to receive(:sleep).with(a_kind_of(Numeric))
expect(Gitlab::SidekiqCluster).to receive(:all_alive?).
with(an_instance_of(Array)).and_return(false)
expect(Gitlab::SidekiqCluster).to receive(:all_alive?)
.with(an_instance_of(Array)).and_return(false)
expect(Gitlab::SidekiqCluster).to receive(:signal_processes).
with(an_instance_of(Array), :TERM)
expect(Gitlab::SidekiqCluster).to receive(:signal_processes)
.with(an_instance_of(Array), :TERM)
cli.start_loop
end
......
......@@ -12,8 +12,8 @@ describe Gitlab::SidekiqCluster do
describe '.trap_terminate' do
it 'traps the termination signals' do
expect(described_class).to receive(:trap_signals).
with(described_class::TERMINATE_SIGNALS)
expect(described_class).to receive(:trap_signals)
.with(described_class::TERMINATE_SIGNALS)
described_class.trap_terminate { }
end
......@@ -21,8 +21,8 @@ describe Gitlab::SidekiqCluster do
describe '.trap_forward' do
it 'traps the signals to forward' do
expect(described_class).to receive(:trap_signals).
with(described_class::FORWARD_SIGNALS)
expect(described_class).to receive(:trap_signals)
.with(described_class::FORWARD_SIGNALS)
described_class.trap_forward { }
end
......@@ -50,18 +50,18 @@ describe Gitlab::SidekiqCluster do
describe '.parse_queues' do
it 'returns an Array containing the parsed queues' do
expect(described_class.parse_queues(%w(foo bar,baz))).
to eq([%w(foo), %w(bar baz)])
expect(described_class.parse_queues(%w(foo bar,baz)))
.to eq([%w(foo), %w(bar baz)])
end
end
describe '.start' do
it 'starts Sidekiq with the given queues and environment' do
expect(described_class).to receive(:start_sidekiq).
ordered.with(%w(foo), :production, 'foo/bar')
expect(described_class).to receive(:start_sidekiq)
.ordered.with(%w(foo), :production, 'foo/bar')
expect(described_class).to receive(:start_sidekiq).
ordered.with(%w(bar baz), :production, 'foo/bar')
expect(described_class).to receive(:start_sidekiq)
.ordered.with(%w(bar baz), :production, 'foo/bar')
described_class.start([%w(foo), %w(bar baz)], :production, 'foo/bar')
end
......
......@@ -50,15 +50,14 @@ describe Note, elastic: true do
it "returns json with all needed elements" do
note = create :note
expected_hash_keys = [
'id',
'note',
'project_id',
'created_at',
'updated_at',
'issue'
]
expected_hash_keys = %w(
id
note
project_id
created_at
updated_at
issue
)
expect(note.as_indexed_json.keys).to eq(expected_hash_keys)
end
......
......@@ -21,8 +21,8 @@ describe Ci::Build, models: true do
end
it do
expect(build.project).to receive(:shared_runners_minutes_limit_enabled?).
and_return(true)
expect(build.project).to receive(:shared_runners_minutes_limit_enabled?)
.and_return(true)
is_expected.to be_truthy
end
......@@ -46,8 +46,8 @@ describe Ci::Build, models: true do
%w(success drop cancel).each do |event|
it "for event #{event}" do
expect(UpdateBuildMinutesService).
to receive(:new).and_call_original
expect(UpdateBuildMinutesService)
.to receive(:new).and_call_original
build.public_send(event)
end
......
......@@ -73,8 +73,8 @@ describe Project, models: true do
subject { project.shared_runners_minutes_limit_enabled? }
before do
allow(project.namespace).to receive(:shared_runners_minutes_limit_enabled?).
and_return(true)
allow(project.namespace).to receive(:shared_runners_minutes_limit_enabled?)
.and_return(true)
end
context 'with shared runners enabled' do
......
......@@ -1696,14 +1696,14 @@ describe Project, models: true do
let(:mirror) { false }
before do
allow_any_instance_of(Gitlab::Shell).to receive(:import_repository).
with(project.repository_storage_path, project.path_with_namespace, project.import_url).
and_return(true)
allow_any_instance_of(Gitlab::Shell).to receive(:import_repository)
.with(project.repository_storage_path, project.path_with_namespace, project.import_url)
.and_return(true)
allow(project).to receive(:repository_exists?).and_return(true)
expect_any_instance_of(Repository).to receive(:after_import).
and_call_original
expect_any_instance_of(Repository).to receive(:after_import)
.and_call_original
end
it 'imports a project' do
......
......@@ -1797,8 +1797,8 @@ describe Repository, models: true do
describe '#push_remote_branches' do
it 'push branches to the remote repo' do
expect_any_instance_of(Gitlab::Shell).to receive(:push_remote_branches).
with(repository.storage_path, repository.path_with_namespace, 'remote_name', ['branch'])
expect_any_instance_of(Gitlab::Shell).to receive(:push_remote_branches)
.with(repository.storage_path, repository.path_with_namespace, 'remote_name', ['branch'])
repository.push_remote_branches('remote_name', ['branch'])
end
......@@ -1806,8 +1806,8 @@ describe Repository, models: true do
describe '#delete_remote_branches' do
it 'delete branches to the remote repo' do
expect_any_instance_of(Gitlab::Shell).to receive(:delete_remote_branches).
with(repository.storage_path, repository.path_with_namespace, 'remote_name', ['branch'])
expect_any_instance_of(Gitlab::Shell).to receive(:delete_remote_branches)
.with(repository.storage_path, repository.path_with_namespace, 'remote_name', ['branch'])
repository.delete_remote_branches('remote_name', ['branch'])
end
......@@ -1825,9 +1825,9 @@ describe Repository, models: true do
it 'gets the remote tags' do
masterrev = repository.find_branch('master').dereferenced_target.id
expect_any_instance_of(Gitlab::Shell).to receive(:list_remote_tags).
with(repository.storage_path, repository.path_with_namespace, 'upstream').
and_return({ 'v0.0.1' => masterrev })
expect_any_instance_of(Gitlab::Shell).to receive(:list_remote_tags)
.with(repository.storage_path, repository.path_with_namespace, 'upstream')
.and_return({ 'v0.0.1' => masterrev })
tags = repository.remote_tags('upstream')
......
......@@ -9,8 +9,8 @@ describe 'OmniAuth Kerberos SPNEGO', lib: true do
# In production user_kerberos_spnego_omniauth_callback_path is defined
# dynamically early when the app boots. Because this is hard to set up
# during testing we stub out this path helper on the controller.
allow_any_instance_of(controller_class).to receive(:user_kerberos_spnego_omniauth_callback_path).
and_return(OmniAuth::Strategies::KerberosSpnego.new(:app).callback_path)
allow_any_instance_of(controller_class).to receive(:user_kerberos_spnego_omniauth_callback_path)
.and_return(OmniAuth::Strategies::KerberosSpnego.new(:app).callback_path)
end
it 'asks for an SPNEGO token' do
......@@ -22,8 +22,8 @@ describe 'OmniAuth Kerberos SPNEGO', lib: true do
context 'when an SPNEGO token is provided' do
it 'passes the token to spnego_negotiate!' do
expect_any_instance_of(controller_class).to receive(:spnego_credentials!).
with('fake spnego token')
expect_any_instance_of(controller_class).to receive(:spnego_credentials!)
.with('fake spnego token')
get path, {}, spnego_header
end
......@@ -31,8 +31,8 @@ describe 'OmniAuth Kerberos SPNEGO', lib: true do
context 'when the final SPNEGO token is provided' do
before do
expect_any_instance_of(controller_class).to receive(:spnego_credentials!).
with('fake spnego token').and_return('janedoe@EXAMPLE.COM')
expect_any_instance_of(controller_class).to receive(:spnego_credentials!)
.with('fake spnego token').and_return('janedoe@EXAMPLE.COM')
end
it 'redirects to the omniauth callback' do
......@@ -48,8 +48,8 @@ describe 'OmniAuth Kerberos SPNEGO', lib: true do
end
it 'send the final SPNEGO response' do
allow_any_instance_of(controller_class).to receive(:spnego_response_token).
and_return("it's the final token")
allow_any_instance_of(controller_class).to receive(:spnego_response_token)
.and_return("it's the final token")
get path, {}, spnego_header
......
require 'spec_helper'
describe Geo::RepositoryBackfillService, services: true do
SYSTEM_HOOKS_HEADER = { 'Content-Type' => 'application/json', 'X-Gitlab-Event' => 'System Hook' }
SYSTEM_HOOKS_HEADER = { 'Content-Type' => 'application/json', 'X-Gitlab-Event' => 'System Hook' }.freeze
let(:project) { create(:project) }
let(:geo_node) { create(:geo_node) }
......
......@@ -30,8 +30,8 @@ describe Projects::UpdateMirrorService do
it "only invokes GitTagPushService for tags pointing to commits" do
stub_fetch_mirror(project)
expect(GitTagPushService).to receive(:new).
with(project, project.owner, hash_including(ref: 'refs/tags/new-tag')).and_return(double(execute: true))
expect(GitTagPushService).to receive(:new)
.with(project, project.owner, hash_including(ref: 'refs/tags/new-tag')).and_return(double(execute: true))
described_class.new(project, project.owner).execute
end
......
......@@ -28,11 +28,11 @@ describe Projects::UpdateRepositoryStorageService, services: true do
context 'when the move succeeds' do
it 'moves the repository to the new storage and unmarks the repository as read only' do
expect(gitlab_shell).to receive(:mv_storage).
with('tmp/tests/storage_a', project.path_with_namespace, 'tmp/tests/storage_b').
and_return(true)
expect(GitlabShellWorker).to receive(:perform_async).
with(:mv_repository,
expect(gitlab_shell).to receive(:mv_storage)
.with('tmp/tests/storage_a', project.path_with_namespace, 'tmp/tests/storage_b')
.and_return(true)
expect(GitlabShellWorker).to receive(:perform_async)
.with(:mv_repository,
'tmp/tests/storage_a',
project.path_with_namespace,
"#{project.path_with_namespace}+#{project.id}+moved+#{time.to_i}")
......@@ -46,9 +46,9 @@ describe Projects::UpdateRepositoryStorageService, services: true do
context 'when the move fails' do
it 'unmarks the repository as read-only without updating the repository storage' do
expect(gitlab_shell).to receive(:mv_storage).
with('tmp/tests/storage_a', project.path_with_namespace, 'tmp/tests/storage_b').
and_return(false)
expect(gitlab_shell).to receive(:mv_storage)
.with('tmp/tests/storage_a', project.path_with_namespace, 'tmp/tests/storage_b')
.and_return(false)
expect(GitlabShellWorker).not_to receive(:perform_async)
subject.execute('b')
......@@ -66,20 +66,20 @@ describe Projects::UpdateRepositoryStorageService, services: true do
context 'when the move succeeds' do
it 'moves the repository and its wiki to the new storage and unmarks the repository as read only' do
expect(gitlab_shell).to receive(:mv_storage).
with('tmp/tests/storage_a', project.path_with_namespace, 'tmp/tests/storage_b').
and_return(true)
expect(GitlabShellWorker).to receive(:perform_async).
with(:mv_repository,
expect(gitlab_shell).to receive(:mv_storage)
.with('tmp/tests/storage_a', project.path_with_namespace, 'tmp/tests/storage_b')
.and_return(true)
expect(GitlabShellWorker).to receive(:perform_async)
.with(:mv_repository,
'tmp/tests/storage_a',
project.path_with_namespace,
"#{project.path_with_namespace}+#{project.id}+moved+#{time.to_i}")
expect(gitlab_shell).to receive(:mv_storage).
with('tmp/tests/storage_a', "#{project.path_with_namespace}.wiki", 'tmp/tests/storage_b').
and_return(true)
expect(GitlabShellWorker).to receive(:perform_async).
with(:mv_repository,
expect(gitlab_shell).to receive(:mv_storage)
.with('tmp/tests/storage_a', "#{project.path_with_namespace}.wiki", 'tmp/tests/storage_b')
.and_return(true)
expect(GitlabShellWorker).to receive(:perform_async)
.with(:mv_repository,
'tmp/tests/storage_a',
"#{project.path_with_namespace}.wiki",
"#{project.path_with_namespace}+#{project.id}+moved+#{time.to_i}.wiki")
......@@ -93,12 +93,12 @@ describe Projects::UpdateRepositoryStorageService, services: true do
context 'when the move of the wiki fails' do
it 'unmarks the repository as read-only without updating the repository storage' do
expect(gitlab_shell).to receive(:mv_storage).
with('tmp/tests/storage_a', project.path_with_namespace, 'tmp/tests/storage_b').
and_return(true)
expect(gitlab_shell).to receive(:mv_storage).
with('tmp/tests/storage_a', "#{project.path_with_namespace}.wiki", 'tmp/tests/storage_b').
and_return(false)
expect(gitlab_shell).to receive(:mv_storage)
.with('tmp/tests/storage_a', project.path_with_namespace, 'tmp/tests/storage_b')
.and_return(true)
expect(gitlab_shell).to receive(:mv_storage)
.with('tmp/tests/storage_a', "#{project.path_with_namespace}.wiki", 'tmp/tests/storage_b')
.and_return(false)
expect(GitlabShellWorker).not_to receive(:perform_async)
subject.execute('b')
......
......@@ -19,11 +19,11 @@ describe UpdateBuildMinutesService, services: true do
it "creates a statistics and sets duration" do
subject
expect(project.statistics.reload.shared_runners_seconds).
to eq(build.duration.to_i)
expect(project.statistics.reload.shared_runners_seconds)
.to eq(build.duration.to_i)
expect(namespace.namespace_statistics.reload.shared_runners_seconds).
to eq(build.duration.to_i)
expect(namespace.namespace_statistics.reload.shared_runners_seconds)
.to eq(build.duration.to_i)
end
context 'when statistics are created' do
......@@ -35,11 +35,11 @@ describe UpdateBuildMinutesService, services: true do
it "updates statistics and adds duration" do
subject
expect(project.statistics.reload.shared_runners_seconds).
to eq(100 + build.duration.to_i)
expect(project.statistics.reload.shared_runners_seconds)
.to eq(100 + build.duration.to_i)
expect(namespace.namespace_statistics.reload.shared_runners_seconds).
to eq(100 + build.duration.to_i)
expect(namespace.namespace_statistics.reload.shared_runners_seconds)
.to eq(100 + build.duration.to_i)
end
end
end
......
......@@ -5,8 +5,8 @@ describe ClearSharedRunnersMinutesWorker do
describe '#perform' do
before do
expect_any_instance_of(described_class).
to receive(:try_obtain_lease).and_return(true)
expect_any_instance_of(described_class)
.to receive(:try_obtain_lease).and_return(true)
end
subject { worker.perform }
......
......@@ -6,8 +6,8 @@ describe GitlabUsagePingWorker do
it "sends POST request" do
stub_application_setting(usage_ping_enabled: true)
stub_request(:post, "https://version.gitlab.com/usage_data").
to_return(status: 200, body: '', headers: {})
stub_request(:post, "https://version.gitlab.com/usage_data")
.to_return(status: 200, body: '', headers: {})
expect(Gitlab::UsageData).to receive(:to_json).with({ force_refresh: true }).and_call_original
expect(subject).to receive(:try_obtain_lease).and_return(true)
......
......@@ -52,8 +52,8 @@ describe ProjectCacheWorker do
end
it 'updates only non database cache' do
expect_any_instance_of(Repository).to receive(:refresh_method_caches).
and_call_original
expect_any_instance_of(Repository).to receive(:refresh_method_caches)
.and_call_original
expect_any_instance_of(Project).not_to receive(:update_repository_size)
expect_any_instance_of(Project).not_to receive(:update_commit_count)
......
......@@ -7,8 +7,8 @@ describe ProjectUpdateRepositoryStorageWorker do
describe "#perform" do
it "should call the update repository storage service" do
expect_any_instance_of(Projects::UpdateRepositoryStorageService).
to receive(:execute).with('new_storage')
expect_any_instance_of(Projects::UpdateRepositoryStorageService)
.to receive(:execute).with('new_storage')
subject.perform(project.id, 'new_storage')
end
......
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