Read about our upcoming Code of Conduct on this issue

Commit 6b7586c0 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu
Browse files

Upgrade to Rails 5.2

Updates changed method names and fixes spec failures
parent 8c5a9dddc494
source 'https://rubygems.org' source 'https://rubygems.org'
gem 'rails', '5.1.7' gem 'rails', '5.2.3'
# Improves copy-on-write performance for MRI # Improves copy-on-write performance for MRI
gem 'nakayoshi_fork', '~> 0.0.4' gem 'nakayoshi_fork', '~> 0.0.4'
......
...@@ -6,44 +6,48 @@ GEM ...@@ -6,44 +6,48 @@ GEM
ace-rails-ap (4.1.2) ace-rails-ap (4.1.2)
acme-client (2.0.2) acme-client (2.0.2)
faraday (~> 0.9, >= 0.9.1) faraday (~> 0.9, >= 0.9.1)
actioncable (5.1.7) actioncable (5.2.3)
actionpack (= 5.1.7) actionpack (= 5.2.3)
nio4r (~> 2.0) nio4r (~> 2.0)
websocket-driver (~> 0.6.1) websocket-driver (>= 0.6.1)
actionmailer (5.1.7) actionmailer (5.2.3)
actionpack (= 5.1.7) actionpack (= 5.2.3)
actionview (= 5.1.7) actionview (= 5.2.3)
activejob (= 5.1.7) activejob (= 5.2.3)
mail (~> 2.5, >= 2.5.4) mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0) rails-dom-testing (~> 2.0)
actionpack (5.1.7) actionpack (5.2.3)
actionview (= 5.1.7) actionview (= 5.2.3)
activesupport (= 5.1.7) activesupport (= 5.2.3)
rack (~> 2.0) rack (~> 2.0)
rack-test (>= 0.6.3) rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0) rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2) rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (5.1.7) actionview (5.2.3)
activesupport (= 5.1.7) activesupport (= 5.2.3)
builder (~> 3.1) builder (~> 3.1)
erubi (~> 1.4) erubi (~> 1.4)
rails-dom-testing (~> 2.0) rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3) rails-html-sanitizer (~> 1.0, >= 1.0.3)
activejob (5.1.7) activejob (5.2.3)
activesupport (= 5.1.7) activesupport (= 5.2.3)
globalid (>= 0.3.6) globalid (>= 0.3.6)
activemodel (5.1.7) activemodel (5.2.3)
activesupport (= 5.1.7) activesupport (= 5.2.3)
activerecord (5.1.7) activerecord (5.2.3)
activemodel (= 5.1.7) activemodel (= 5.2.3)
activesupport (= 5.1.7) activesupport (= 5.2.3)
arel (~> 8.0) arel (>= 9.0)
activerecord-explain-analyze (0.1.0) activerecord-explain-analyze (0.1.0)
activerecord (>= 4) activerecord (>= 4)
pg pg
activerecord_sane_schema_dumper (1.0) activerecord_sane_schema_dumper (1.0)
rails (>= 5, < 6) rails (>= 5, < 6)
activesupport (5.1.7) activestorage (5.2.3)
actionpack (= 5.2.3)
activerecord (= 5.2.3)
marcel (~> 0.3.1)
activesupport (5.2.3)
concurrent-ruby (~> 1.0, >= 1.0.2) concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2) i18n (>= 0.7, < 2)
minitest (~> 5.1) minitest (~> 5.1)
...@@ -60,7 +64,7 @@ GEM ...@@ -60,7 +64,7 @@ GEM
apollo_upload_server (2.0.0.beta.3) apollo_upload_server (2.0.0.beta.3)
graphql (>= 1.8) graphql (>= 1.8)
rails (>= 4.2) rails (>= 4.2)
arel (8.0.0) arel (9.0.0)
asana (0.8.1) asana (0.8.1)
faraday (~> 0.9) faraday (~> 0.9)
faraday_middleware (~> 0.9) faraday_middleware (~> 0.9)
...@@ -504,6 +508,8 @@ GEM ...@@ -504,6 +508,8 @@ GEM
mail (2.7.1) mail (2.7.1)
mini_mime (>= 0.1.1) mini_mime (>= 0.1.1)
mail_room (0.9.1) mail_room (0.9.1)
marcel (0.3.3)
mimemagic (~> 0.3.2)
mdl (0.5.0) mdl (0.5.0)
kramdown (~> 1.12, >= 1.12.0) kramdown (~> 1.12, >= 1.12.0)
mixlib-cli (~> 1.7, >= 1.7.0) mixlib-cli (~> 1.7, >= 1.7.0)
...@@ -706,17 +712,18 @@ GEM ...@@ -706,17 +712,18 @@ GEM
rack-test (1.1.0) rack-test (1.1.0)
rack (>= 1.0, < 3) rack (>= 1.0, < 3)
rack-timeout (0.5.1) rack-timeout (0.5.1)
rails (5.1.7) rails (5.2.3)
actioncable (= 5.1.7) actioncable (= 5.2.3)
actionmailer (= 5.1.7) actionmailer (= 5.2.3)
actionpack (= 5.1.7) actionpack (= 5.2.3)
actionview (= 5.1.7) actionview (= 5.2.3)
activejob (= 5.1.7) activejob (= 5.2.3)
activemodel (= 5.1.7) activemodel (= 5.2.3)
activerecord (= 5.1.7) activerecord (= 5.2.3)
activesupport (= 5.1.7) activestorage (= 5.2.3)
activesupport (= 5.2.3)
bundler (>= 1.3.0) bundler (>= 1.3.0)
railties (= 5.1.7) railties (= 5.2.3)
sprockets-rails (>= 2.0.0) sprockets-rails (>= 2.0.0)
rails-controller-testing (1.0.2) rails-controller-testing (1.0.2)
actionpack (~> 5.x, >= 5.0.1) actionpack (~> 5.x, >= 5.0.1)
...@@ -730,12 +737,12 @@ GEM ...@@ -730,12 +737,12 @@ GEM
rails-i18n (5.1.1) rails-i18n (5.1.1)
i18n (>= 0.7, < 2) i18n (>= 0.7, < 2)
railties (>= 5.0, < 6) railties (>= 5.0, < 6)
railties (5.1.7) railties (5.2.3)
actionpack (= 5.1.7) actionpack (= 5.2.3)
activesupport (= 5.1.7) activesupport (= 5.2.3)
method_source method_source
rake (>= 0.8.7) rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0) thor (>= 0.19.0, < 2.0)
rainbow (3.0.0) rainbow (3.0.0)
raindrops (0.19.0) raindrops (0.19.0)
rake (12.3.2) rake (12.3.2)
...@@ -1019,7 +1026,7 @@ GEM ...@@ -1019,7 +1026,7 @@ GEM
hashdiff hashdiff
webpack-rails (0.9.11) webpack-rails (0.9.11)
railties (>= 3.2.0) railties (>= 3.2.0)
websocket-driver (0.6.5) websocket-driver (0.7.0)
websocket-extensions (>= 0.1.0) websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.3) websocket-extensions (0.1.3)
wikicloth (0.8.1) wikicloth (0.8.1)
...@@ -1206,7 +1213,7 @@ DEPENDENCIES ...@@ -1206,7 +1213,7 @@ DEPENDENCIES
rack-oauth2 (~> 1.9.3) rack-oauth2 (~> 1.9.3)
rack-proxy (~> 0.6.0) rack-proxy (~> 0.6.0)
rack-timeout rack-timeout
rails (= 5.1.7) rails (= 5.2.3)
rails-controller-testing rails-controller-testing
rails-i18n (~> 5.1) rails-i18n (~> 5.1)
rainbow (~> 3.0) rainbow (~> 3.0)
......
...@@ -28,7 +28,7 @@ def ip_whitelist ...@@ -28,7 +28,7 @@ def ip_whitelist
def valid_token? def valid_token?
token = params[:token].presence || request.headers['TOKEN'] token = params[:token].presence || request.headers['TOKEN']
token.present? && token.present? &&
ActiveSupport::SecurityUtils.variable_size_secure_compare( ActiveSupport::SecurityUtils.secure_compare(
token, token,
Gitlab::CurrentSettings.health_check_access_token Gitlab::CurrentSettings.health_check_access_token
) )
......
...@@ -107,7 +107,7 @@ def update ...@@ -107,7 +107,7 @@ def update
if Groups::UpdateService.new(@group, current_user, group_params).execute if Groups::UpdateService.new(@group, current_user, group_params).execute
redirect_to edit_group_path(@group, anchor: params[:update_section]), notice: "Group '#{@group.name}' was successfully updated." redirect_to edit_group_path(@group, anchor: params[:update_section]), notice: "Group '#{@group.name}' was successfully updated."
else else
@group.restore_path! @group.path = @group.path_before_last_save || @group.path_was
render action: "edit" render action: "edit"
end end
......
...@@ -578,7 +578,7 @@ def needs_touch? ...@@ -578,7 +578,7 @@ def needs_touch?
end end
def valid_token?(token) def valid_token?(token)
self.token && ActiveSupport::SecurityUtils.variable_size_secure_compare(token, self.token) self.token && ActiveSupport::SecurityUtils.secure_compare(token, self.token)
end end
def has_tags? def has_tags?
......
...@@ -196,7 +196,7 @@ class Pipeline < ApplicationRecord ...@@ -196,7 +196,7 @@ class Pipeline < ApplicationRecord
sql = 'CASE ci_pipelines.source WHEN (?) THEN 0 ELSE 1 END, ci_pipelines.id DESC' sql = 'CASE ci_pipelines.source WHEN (?) THEN 0 ELSE 1 END, ci_pipelines.id DESC'
query = ApplicationRecord.send(:sanitize_sql_array, [sql, sources[:merge_request_event]]) # rubocop:disable GitlabSecurity/PublicSend query = ApplicationRecord.send(:sanitize_sql_array, [sql, sources[:merge_request_event]]) # rubocop:disable GitlabSecurity/PublicSend
order(query) order(Arel.sql(query))
end end
scope :for_user, -> (user) { where(user: user) } scope :for_user, -> (user) { where(user: user) }
......
...@@ -33,6 +33,7 @@ def status_sql ...@@ -33,6 +33,7 @@ def status_sql
canceled = scope_relevant.canceled.select('count(*)').to_sql canceled = scope_relevant.canceled.select('count(*)').to_sql
warnings = scope_warnings.select('count(*) > 0').to_sql.presence || 'false' warnings = scope_warnings.select('count(*) > 0').to_sql.presence || 'false'
Arel.sql(
"(CASE "(CASE
WHEN (#{builds})=(#{skipped}) AND (#{warnings}) THEN 'success' WHEN (#{builds})=(#{skipped}) AND (#{warnings}) THEN 'success'
WHEN (#{builds})=(#{skipped}) THEN 'skipped' WHEN (#{builds})=(#{skipped}) THEN 'skipped'
...@@ -49,6 +50,7 @@ def status_sql ...@@ -49,6 +50,7 @@ def status_sql
WHEN (#{created})>0 THEN 'running' WHEN (#{created})>0 THEN 'running'
ELSE 'failed' ELSE 'failed'
END)" END)"
)
end end
def status def status
...@@ -88,22 +90,22 @@ def completed_statuses ...@@ -88,22 +90,22 @@ def completed_statuses
state :scheduled, value: 'scheduled' state :scheduled, value: 'scheduled'
end end
scope :created, -> { where(status: 'created') } scope :created, -> { with_status(:created) }
scope :preparing, -> { where(status: 'preparing') } scope :preparing, -> { with_status(:preparing) }
scope :relevant, -> { where(status: AVAILABLE_STATUSES - ['created']) } scope :relevant, -> { without_status(:created) }
scope :running, -> { where(status: 'running') } scope :running, -> { with_status(:running) }
scope :pending, -> { where(status: 'pending') } scope :pending, -> { with_status(:pending) }
scope :success, -> { where(status: 'success') } scope :success, -> { with_status(:success) }
scope :failed, -> { where(status: 'failed') } scope :failed, -> { with_status(:failed) }
scope :canceled, -> { where(status: 'canceled') } scope :canceled, -> { with_status(:canceled) }
scope :skipped, -> { where(status: 'skipped') } scope :skipped, -> { with_status(:skipped) }
scope :manual, -> { where(status: 'manual') } scope :manual, -> { with_status(:manual) }
scope :scheduled, -> { where(status: 'scheduled') } scope :scheduled, -> { with_status(:scheduled) }
scope :alive, -> { where(status: [:created, :preparing, :pending, :running]) } scope :alive, -> { with_status(:created, :preparing, :pending, :running) }
scope :created_or_pending, -> { where(status: [:created, :pending]) } scope :created_or_pending, -> { with_status(:created, :pending) }
scope :running_or_pending, -> { where(status: [:running, :pending]) } scope :running_or_pending, -> { with_status(:running, :pending) }
scope :finished, -> { where(status: [:success, :failed, :canceled]) } scope :finished, -> { with_status(:success, :failed, :canceled) }
scope :failed_or_canceled, -> { where(status: [:failed, :canceled]) } scope :failed_or_canceled, -> { with_status(:failed, :canceled) }
scope :cancelable, -> do scope :cancelable, -> do
where(status: [:running, :preparing, :pending, :created, :scheduled]) where(status: [:running, :preparing, :pending, :created, :scheduled])
......
...@@ -179,7 +179,7 @@ def calculate_relative_position(calculation) ...@@ -179,7 +179,7 @@ def calculate_relative_position(calculation)
relation = yield relation if block_given? relation = yield relation if block_given?
relation relation
.pluck(self.class.parent_column, "#{calculation}(relative_position) AS position") .pluck(self.class.parent_column, Arel.sql("#{calculation}(relative_position) AS position"))
.first&. .first&.
last last
end end
......
...@@ -46,7 +46,7 @@ def find_by_full_path(path, follow_redirects: false) ...@@ -46,7 +46,7 @@ def find_by_full_path(path, follow_redirects: false)
# See https://gitlab.com/gitlab-org/gitlab-ce/issues/18603. Also note that # See https://gitlab.com/gitlab-org/gitlab-ce/issues/18603. Also note that
# our unique index is case-sensitive in Postgres. # our unique index is case-sensitive in Postgres.
binary = Gitlab::Database.mysql? ? 'BINARY' : '' binary = Gitlab::Database.mysql? ? 'BINARY' : ''
order_sql = "(CASE WHEN #{binary} routes.path = #{connection.quote(path)} THEN 0 ELSE 1 END)" order_sql = Arel.sql("(CASE WHEN #{binary} routes.path = #{connection.quote(path)} THEN 0 ELSE 1 END)")
found = where_full_path_in([path]).reorder(order_sql).take found = where_full_path_in([path]).reorder(order_sql).take
return found if found return found if found
......
...@@ -52,7 +52,7 @@ def add_authentication_token_field(token_field, options = {}) ...@@ -52,7 +52,7 @@ def add_authentication_token_field(token_field, options = {})
mod.define_method("#{token_field}_matches?") do |other_token| mod.define_method("#{token_field}_matches?") do |other_token|
token = read_attribute(token_field) token = read_attribute(token_field)
token.present? && ActiveSupport::SecurityUtils.variable_size_secure_compare(other_token, token) token.present? && ActiveSupport::SecurityUtils.secure_compare(other_token, token)
end end
end end
......
...@@ -4,9 +4,8 @@ class Email < ApplicationRecord ...@@ -4,9 +4,8 @@ class Email < ApplicationRecord
include Sortable include Sortable
include Gitlab::SQL::Pattern include Gitlab::SQL::Pattern
belongs_to :user belongs_to :user, optional: false
validates :user_id, presence: true
validates :email, presence: true, uniqueness: true, devise_email: true validates :email, presence: true, uniqueness: true, devise_email: true
validate :unique_email, if: ->(email) { email.email_changed? } validate :unique_email, if: ->(email) { email.email_changed? }
......
...@@ -25,7 +25,7 @@ class MergeRequestsClosingIssues < ApplicationRecord ...@@ -25,7 +25,7 @@ class MergeRequestsClosingIssues < ApplicationRecord
class << self class << self
def count_for_collection(ids, current_user) def count_for_collection(ids, current_user)
closing_merge_requests(ids, current_user).group(:issue_id).pluck('issue_id', 'COUNT(*) as count') closing_merge_requests(ids, current_user).group(:issue_id).pluck('issue_id', Arel.sql('COUNT(*) as count'))
end end
def count_for_issue(id, current_user) def count_for_issue(id, current_user)
......
...@@ -357,7 +357,7 @@ class Project < ApplicationRecord ...@@ -357,7 +357,7 @@ class Project < ApplicationRecord
scope :with_unmigrated_storage, -> { where('storage_version < :version OR storage_version IS NULL', version: LATEST_STORAGE_VERSION) } scope :with_unmigrated_storage, -> { where('storage_version < :version OR storage_version IS NULL', version: LATEST_STORAGE_VERSION) }
# last_activity_at is throttled every minute, but last_repository_updated_at is updated with every push # last_activity_at is throttled every minute, but last_repository_updated_at is updated with every push
scope :sorted_by_activity, -> { reorder("GREATEST(COALESCE(last_activity_at, '1970-01-01'), COALESCE(last_repository_updated_at, '1970-01-01')) DESC") } scope :sorted_by_activity, -> { reorder(Arel.sql("GREATEST(COALESCE(last_activity_at, '1970-01-01'), COALESCE(last_repository_updated_at, '1970-01-01')) DESC")) }
scope :sorted_by_stars_desc, -> { reorder(star_count: :desc) } scope :sorted_by_stars_desc, -> { reorder(star_count: :desc) }
scope :sorted_by_stars_asc, -> { reorder(star_count: :asc) } scope :sorted_by_stars_asc, -> { reorder(star_count: :asc) }
...@@ -612,7 +612,7 @@ def ids_with_milestone_available_for(user) ...@@ -612,7 +612,7 @@ def ids_with_milestone_available_for(user)
end end
end end
def initialize(attributes = {}) def initialize(attributes = nil)
# We can't use default_value_for because the database has a default # We can't use default_value_for because the database has a default
# value of 0 for visibility_level. If someone attempts to create a # value of 0 for visibility_level. If someone attempts to create a
# private project, default_value_for will assume that the # private project, default_value_for will assume that the
...@@ -622,6 +622,8 @@ def initialize(attributes = {}) ...@@ -622,6 +622,8 @@ def initialize(attributes = {})
# #
# To fix the problem, we assign the actual default in the application if # To fix the problem, we assign the actual default in the application if
# no explicit visibility has been initialized. # no explicit visibility has been initialized.
attributes ||= {}
unless visibility_attribute_present?(attributes) unless visibility_attribute_present?(attributes)
attributes[:visibility_level] = Gitlab::CurrentSettings.default_project_visibility attributes[:visibility_level] = Gitlab::CurrentSettings.default_project_visibility
end end
...@@ -1557,7 +1559,7 @@ def any_runners?(&block) ...@@ -1557,7 +1559,7 @@ def any_runners?(&block)
end end
def valid_runners_token?(token) def valid_runners_token?(token)
self.runners_token && ActiveSupport::SecurityUtils.variable_size_secure_compare(token, self.runners_token) self.runners_token && ActiveSupport::SecurityUtils.secure_compare(token, self.runners_token)
end end
# rubocop: disable CodeReuse/ServiceClass # rubocop: disable CodeReuse/ServiceClass
......
...@@ -7,7 +7,7 @@ class CiService < Service ...@@ -7,7 +7,7 @@ class CiService < Service
default_value_for :category, 'ci' default_value_for :category, 'ci'
def valid_token?(token) def valid_token?(token)
self.respond_to?(:token) && self.token.present? && ActiveSupport::SecurityUtils.variable_size_secure_compare(token, self.token) self.respond_to?(:token) && self.token.present? && ActiveSupport::SecurityUtils.secure_compare(token, self.token)
end end
def self.supported_events def self.supported_events
......
...@@ -12,7 +12,7 @@ class SlashCommandsService < Service ...@@ -12,7 +12,7 @@ class SlashCommandsService < Service
def valid_token?(token) def valid_token?(token)
self.respond_to?(:token) && self.respond_to?(:token) &&
self.token.present? && self.token.present? &&
ActiveSupport::SecurityUtils.variable_size_secure_compare(token, self.token) ActiveSupport::SecurityUtils.secure_compare(token, self.token)
end end
def self.supported_events def self.supported_events
......
...@@ -44,7 +44,7 @@ def status_for_prior_stages(index) ...@@ -44,7 +44,7 @@ def status_for_prior_stages(index)
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def stage_indexes_of_created_processables def stage_indexes_of_created_processables
created_processables.order(:stage_idx).pluck('distinct stage_idx') created_processables.order(:stage_idx).pluck(Arel.sql('DISTINCT stage_idx'))
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
...@@ -68,7 +68,7 @@ def update_retried ...@@ -68,7 +68,7 @@ def update_retried
latest_statuses = pipeline.statuses.latest latest_statuses = pipeline.statuses.latest
.group(:name) .group(:name)
.having('count(*) > 1') .having('count(*) > 1')
.pluck('max(id)', 'name') .pluck(Arel.sql('MAX(id)'), 'name')
# mark builds that are retried # mark builds that are retried
pipeline.statuses.latest pipeline.statuses.latest
......
...@@ -27,8 +27,7 @@ def execute ...@@ -27,8 +27,7 @@ def execute
@group.build_chat_team(name: response['name'], team_id: response['id']) @group.build_chat_team(name: response['name'], team_id: response['id'])
end end
@group.save @group.add_owner(current_user) if @group.save
@group.add_owner(current_user)
@group @group
end end
......
#!/usr/bin/env ruby #!/usr/bin/env ruby
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
load Gem.bin_path('bundler', 'bundle') load Gem.bin_path('bundler', 'bundle')
#!/usr/bin/env ruby #!/usr/bin/env ruby
require 'fileutils'
require "pathname" include FileUtils
# path to your application root. # path to your application root.
APP_ROOT = Pathname.new File.expand_path("../../", __FILE__) APP_ROOT = File.expand_path('..', __dir__)
def system!(*args) def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==") system(*args) || abort("\n== Command #{args} failed ==")
end end
Dir.chdir APP_ROOT do chdir APP_ROOT do
# This script is a starting point to set up your application. # This script is a starting point to setup your application.
# Add necessary setup steps to this file: # Add necessary setup steps to this file.
puts '== Installing dependencies =='
system! 'gem install bundler --conservative'
system('bundle check') || system!('bundle install')
puts "== Installing dependencies ==" # Install JavaScript dependencies if using Yarn
system! "gem install bundler --conservative" # system('bin/yarn')
system("bundle check") || system!("bundle install")
# puts "\n== Copying sample files ==" # puts "\n== Copying sample files =="
# unless File.exist?("config/database.yml") # unless File.exist?('config/database.yml')
# cp "config/database.yml.sample", "config/database.yml" # cp 'config/database.yml.sample', 'config/database.yml'
# end # end
puts "\n== Preparing database ==" puts "\n== Preparing database =="
system! "bin/rails db:setup" system! 'bin/rails db:setup'
puts "\n== Removing old logs and tempfiles ==" puts "\n== Removing old logs and tempfiles =="
system! "bin/rails log:clear tmp:clear" system! 'bin/rails log:clear tmp:clear'
puts "\n== Restarting application server ==" puts "\n== Restarting application server =="
system! "bin/rails restart" system! 'bin/rails restart'
end end
#!/usr/bin/env ruby #!/usr/bin/env ruby
require 'pathname'
require 'fileutils' require 'fileutils'
include FileUtils include FileUtils
# path to your application root. # path to your application root.