Commit f924273d authored by Andrew Fontaine's avatar Andrew Fontaine

Merge branch 'id-bump-rails-to-6-1' into 'master'

Bump Rails to 6.1 [RUN ALL RSPEC] [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!59107
parents dab6ec44 5399deaa
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
source 'https://rubygems.org' source 'https://rubygems.org'
gem 'rails', '~> 6.0.3.7' gem 'rails', '~> 6.1.3.2'
gem 'bootsnap', '~> 1.4.6' gem 'bootsnap', '~> 1.4.6'
......
...@@ -12,64 +12,68 @@ GEM ...@@ -12,64 +12,68 @@ GEM
abstract_type (0.0.7) abstract_type (0.0.7)
acme-client (2.0.6) acme-client (2.0.6)
faraday (>= 0.17, < 2.0.0) faraday (>= 0.17, < 2.0.0)
actioncable (6.0.3.7) actioncable (6.1.3.2)
actionpack (= 6.0.3.7) actionpack (= 6.1.3.2)
activesupport (= 6.1.3.2)
nio4r (~> 2.0) nio4r (~> 2.0)
websocket-driver (>= 0.6.1) websocket-driver (>= 0.6.1)
actionmailbox (6.0.3.7) actionmailbox (6.1.3.2)
actionpack (= 6.0.3.7) actionpack (= 6.1.3.2)
activejob (= 6.0.3.7) activejob (= 6.1.3.2)
activerecord (= 6.0.3.7) activerecord (= 6.1.3.2)
activestorage (= 6.0.3.7) activestorage (= 6.1.3.2)
activesupport (= 6.0.3.7) activesupport (= 6.1.3.2)
mail (>= 2.7.1) mail (>= 2.7.1)
actionmailer (6.0.3.7) actionmailer (6.1.3.2)
actionpack (= 6.0.3.7) actionpack (= 6.1.3.2)
actionview (= 6.0.3.7) actionview (= 6.1.3.2)
activejob (= 6.0.3.7) activejob (= 6.1.3.2)
activesupport (= 6.1.3.2)
mail (~> 2.5, >= 2.5.4) mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0) rails-dom-testing (~> 2.0)
actionpack (6.0.3.7) actionpack (6.1.3.2)
actionview (= 6.0.3.7) actionview (= 6.1.3.2)
activesupport (= 6.0.3.7) activesupport (= 6.1.3.2)
rack (~> 2.0, >= 2.0.8) rack (~> 2.0, >= 2.0.9)
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.2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0)
actiontext (6.0.3.7) actiontext (6.1.3.2)
actionpack (= 6.0.3.7) actionpack (= 6.1.3.2)
activerecord (= 6.0.3.7) activerecord (= 6.1.3.2)
activestorage (= 6.0.3.7) activestorage (= 6.1.3.2)
activesupport (= 6.0.3.7) activesupport (= 6.1.3.2)
nokogiri (>= 1.8.5) nokogiri (>= 1.8.5)
actionview (6.0.3.7) actionview (6.1.3.2)
activesupport (= 6.0.3.7) activesupport (= 6.1.3.2)
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.1, >= 1.2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0)
activejob (6.0.3.7) activejob (6.1.3.2)
activesupport (= 6.0.3.7) activesupport (= 6.1.3.2)
globalid (>= 0.3.6) globalid (>= 0.3.6)
activemodel (6.0.3.7) activemodel (6.1.3.2)
activesupport (= 6.0.3.7) activesupport (= 6.1.3.2)
activerecord (6.0.3.7) activerecord (6.1.3.2)
activemodel (= 6.0.3.7) activemodel (= 6.1.3.2)
activesupport (= 6.0.3.7) activesupport (= 6.1.3.2)
activerecord-explain-analyze (0.1.0) activerecord-explain-analyze (0.1.0)
activerecord (>= 4) activerecord (>= 4)
pg pg
activestorage (6.0.3.7) activestorage (6.1.3.2)
actionpack (= 6.0.3.7) actionpack (= 6.1.3.2)
activejob (= 6.0.3.7) activejob (= 6.1.3.2)
activerecord (= 6.0.3.7) activerecord (= 6.1.3.2)
activesupport (= 6.1.3.2)
marcel (~> 1.0.0) marcel (~> 1.0.0)
activesupport (6.0.3.7) mini_mime (~> 1.0.2)
activesupport (6.1.3.2)
concurrent-ruby (~> 1.0, >= 1.0.2) concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2) i18n (>= 1.6, < 2)
minitest (~> 5.1) minitest (>= 5.1)
tzinfo (~> 1.1) tzinfo (~> 2.0)
zeitwerk (~> 2.2, >= 2.2.2) zeitwerk (~> 2.3)
acts-as-taggable-on (7.0.0) acts-as-taggable-on (7.0.0)
activerecord (>= 5.0, < 6.2) activerecord (>= 5.0, < 6.2)
adamantium (0.2.0) adamantium (0.2.0)
...@@ -744,7 +748,7 @@ GEM ...@@ -744,7 +748,7 @@ GEM
mime-types-data (3.2020.0512) mime-types-data (3.2020.0512)
mini_histogram (0.3.1) mini_histogram (0.3.1)
mini_magick (4.10.1) mini_magick (4.10.1)
mini_mime (1.1.0) mini_mime (1.0.2)
mini_portile2 (2.5.0) mini_portile2 (2.5.0)
minitest (5.11.3) minitest (5.11.3)
mixlib-cli (2.1.8) mixlib-cli (2.1.8)
...@@ -963,20 +967,20 @@ GEM ...@@ -963,20 +967,20 @@ GEM
rack-test (1.1.0) rack-test (1.1.0)
rack (>= 1.0, < 3) rack (>= 1.0, < 3)
rack-timeout (0.5.2) rack-timeout (0.5.2)
rails (6.0.3.7) rails (6.1.3.2)
actioncable (= 6.0.3.7) actioncable (= 6.1.3.2)
actionmailbox (= 6.0.3.7) actionmailbox (= 6.1.3.2)
actionmailer (= 6.0.3.7) actionmailer (= 6.1.3.2)
actionpack (= 6.0.3.7) actionpack (= 6.1.3.2)
actiontext (= 6.0.3.7) actiontext (= 6.1.3.2)
actionview (= 6.0.3.7) actionview (= 6.1.3.2)
activejob (= 6.0.3.7) activejob (= 6.1.3.2)
activemodel (= 6.0.3.7) activemodel (= 6.1.3.2)
activerecord (= 6.0.3.7) activerecord (= 6.1.3.2)
activestorage (= 6.0.3.7) activestorage (= 6.1.3.2)
activesupport (= 6.0.3.7) activesupport (= 6.1.3.2)
bundler (>= 1.3.0) bundler (>= 1.15.0)
railties (= 6.0.3.7) railties (= 6.1.3.2)
sprockets-rails (>= 2.0.0) sprockets-rails (>= 2.0.0)
rails-controller-testing (1.0.5) rails-controller-testing (1.0.5)
actionpack (>= 5.0.1.rc1) actionpack (>= 5.0.1.rc1)
...@@ -990,12 +994,12 @@ GEM ...@@ -990,12 +994,12 @@ GEM
rails-i18n (6.0.0) rails-i18n (6.0.0)
i18n (>= 0.7, < 2) i18n (>= 0.7, < 2)
railties (>= 6.0.0, < 7) railties (>= 6.0.0, < 7)
railties (6.0.3.7) railties (6.1.3.2)
actionpack (= 6.0.3.7) actionpack (= 6.1.3.2)
activesupport (= 6.0.3.7) activesupport (= 6.1.3.2)
method_source method_source
rake (>= 0.8.7) rake (>= 0.8.7)
thor (>= 0.20.3, < 2.0) thor (~> 1.0)
rainbow (3.0.0) rainbow (3.0.0)
raindrops (0.19.1) raindrops (0.19.1)
rake (13.0.3) rake (13.0.3)
...@@ -1306,8 +1310,8 @@ GEM ...@@ -1306,8 +1310,8 @@ GEM
tty-screen (~> 0.8) tty-screen (~> 0.8)
wisper (~> 2.0) wisper (~> 2.0)
tty-screen (0.8.1) tty-screen (0.8.1)
tzinfo (1.2.9) tzinfo (2.0.4)
thread_safe (~> 0.1) concurrent-ruby (~> 1.0)
u2f (0.2.1) u2f (0.2.1)
uber (0.1.0) uber (0.1.0)
unf (0.1.4) unf (0.1.4)
...@@ -1585,7 +1589,7 @@ DEPENDENCIES ...@@ -1585,7 +1589,7 @@ DEPENDENCIES
rack-oauth2 (~> 1.16.0) rack-oauth2 (~> 1.16.0)
rack-proxy (~> 0.6.0) rack-proxy (~> 0.6.0)
rack-timeout (~> 0.5.1) rack-timeout (~> 0.5.1)
rails (~> 6.0.3.7) rails (~> 6.1.3.2)
rails-controller-testing rails-controller-testing
rails-i18n (~> 6.0) rails-i18n (~> 6.0)
rainbow (~> 3.0) rainbow (~> 3.0)
......
...@@ -123,7 +123,21 @@ module TabHelper ...@@ -123,7 +123,21 @@ module TabHelper
def route_matches_pages?(pages) def route_matches_pages?(pages)
Array(pages).compact.any? do |single_page| Array(pages).compact.any? do |single_page|
current_page?(single_page) # We need to distinguish between Hash argument and other types of
# arguments (for example String) in order to fix deprecation kwargs
# warning.
#
# This can be refactored to
#
# current_page?(single_page)
#
# When we migrate to Ruby 3 or the Rails version contains the following:
# https://github.com/rails/rails/commit/81d90d81d0ee1fc1a649ab705119a71f2d04c8a2
if single_page.is_a?(Hash)
current_page?(**single_page)
else
current_page?(single_page)
end
end end
end end
......
...@@ -141,6 +141,12 @@ module BulkInsertSafe ...@@ -141,6 +141,12 @@ module BulkInsertSafe
raise ArgumentError, "returns needs to be :ids or nil" raise ArgumentError, "returns needs to be :ids or nil"
end end
# Handle insertions for tables with a composite primary key
primary_keys = connection.schema_cache.primary_keys(table_name)
if unique_by.blank? && primary_key != primary_keys
unique_by = primary_keys
end
transaction do transaction do
items.each_slice(batch_size).flat_map do |item_batch| items.each_slice(batch_size).flat_map do |item_batch|
attributes = _bulk_insert_item_attributes( attributes = _bulk_insert_item_attributes(
......
...@@ -11,14 +11,6 @@ module EnumWithNil ...@@ -11,14 +11,6 @@ module EnumWithNil
# override auto-defined methods only for the # override auto-defined methods only for the
# key which uses nil value # key which uses nil value
definitions.each do |name, values| definitions.each do |name, values|
next unless key_with_nil = values.key(nil)
# E.g. for enum_with_nil failure_reason: { unknown_failure: nil }
# this overrides auto-generated method `unknown_failure?`
define_method("#{key_with_nil}?") do
self[name].nil?
end
# E.g. for enum_with_nil failure_reason: { unknown_failure: nil } # E.g. for enum_with_nil failure_reason: { unknown_failure: nil }
# this overrides auto-generated method `failure_reason` # this overrides auto-generated method `failure_reason`
define_method(name) do define_method(name) do
......
...@@ -29,6 +29,15 @@ class ProjectAuthorization < ApplicationRecord ...@@ -29,6 +29,15 @@ class ProjectAuthorization < ApplicationRecord
EOF EOF
end end
end end
# This method overrides its ActiveRecord's version in order to work correctly
# with composite primary keys and fix the tests for Rails 6.1
#
# Consider using BulkInsertSafe module instead since we plan to refactor it in
# https://gitlab.com/gitlab-org/gitlab/-/issues/331264
def self.insert_all(attributes)
super(attributes, unique_by: connection.schema_cache.primary_keys(table_name))
end
end end
ProjectAuthorization.prepend_mod_with('ProjectAuthorization') ProjectAuthorization.prepend_mod_with('ProjectAuthorization')
...@@ -5,6 +5,6 @@ Rails.application.eager_load! ...@@ -5,6 +5,6 @@ Rails.application.eager_load!
ACTION_CABLE_SERVER = true ACTION_CABLE_SERVER = true
use ActionDispatch::RequestId use ActionDispatch::RequestId, header: Rails.application.config.action_dispatch.request_id_header
run ActionCable.server run ActionCable.server
...@@ -3,22 +3,6 @@ ...@@ -3,22 +3,6 @@
# partial backport of https://github.com/rails/rails/pull/38169 # partial backport of https://github.com/rails/rails/pull/38169
# this is in order to be able to re-order rack middlewares. # this is in order to be able to re-order rack middlewares.
if ActionDispatch::MiddlewareStack.method_defined?(:move)
warn "`move` is now defined in in ActionDispatch itself: https://github.com/rails/rails/pull/38169, please remove this patch from #{__FILE__}"
else
module ActionDispatch
class MiddlewareStack
def move(target, source)
source_index = assert_index(source, :before)
source_middleware = middlewares.delete_at(source_index)
target_index = assert_index(target, :before)
middlewares.insert(target_index, source_middleware)
end
end
end
end
unless Rails::Configuration::MiddlewareStackProxy.method_defined?(:move) unless Rails::Configuration::MiddlewareStackProxy.method_defined?(:move)
module Rails module Rails
module Configuration module Configuration
......
...@@ -114,7 +114,7 @@ module Gitlab ...@@ -114,7 +114,7 @@ module Gitlab
['up', version, '********** NO FILE **********'] ['up', version, '********** NO FILE **********']
end end
# output # output
puts "\ndatabase: #{ActiveRecord::Base.connection_config[:database]}\n\n" puts "\ndatabase: #{ActiveRecord::Base.connection_db_config.database}\n\n"
puts "#{'Status'.center(8)} #{'Migration ID'.ljust(14)} Migration Name" puts "#{'Status'.center(8)} #{'Migration ID'.ljust(14)} Migration Name"
puts "-" * 50 puts "-" * 50
(db_list + file_list).sort_by { |_, version, _| version }.each do |status, version, name| (db_list + file_list).sort_by { |_, version, _| version }.each do |status, version, name|
......
...@@ -61,7 +61,7 @@ RSpec.describe Admin::AuditLogReportsController do ...@@ -61,7 +61,7 @@ RSpec.describe Admin::AuditLogReportsController do
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(response.headers["Content-Length"]).to be_nil expect(response.headers["Content-Length"]).to be_nil
expect(response.headers["Cache-Control"]).to eq('no-cache, no-store') expect(response.headers["Cache-Control"]).to eq('no-store')
expect(response.headers['Content-Type']).to eq('text/csv; charset=utf-8; header=present') expect(response.headers['Content-Type']).to eq('text/csv; charset=utf-8; header=present')
expect(response.headers['X-Accel-Buffering']).to eq('no') expect(response.headers['X-Accel-Buffering']).to eq('no')
expect(response.headers['Last-Modified']).to eq('0') expect(response.headers['Last-Modified']).to eq('0')
......
...@@ -23,15 +23,15 @@ RSpec.describe Resolvers::VulnerabilitiesHistoryResolver do ...@@ -23,15 +23,15 @@ RSpec.describe Resolvers::VulnerabilitiesHistoryResolver do
ordered_history = subject.sort_by { |count| [count['day'], count['severity']] } ordered_history = subject.sort_by { |count| [count['day'], count['severity']] }
expect(ordered_history.to_json).to eq([ expect(ordered_history.to_json).to eq([
{ 'id' => nil, 'severity' => 'critical', 'day' => '2019-10-16', 'count' => 1 }, { 'day' => '2019-10-16', 'severity' => 'critical', 'count' => 1, 'id' => nil },
{ 'id' => nil, 'severity' => 'high', 'day' => '2019-10-16', 'count' => 1 }, { 'day' => '2019-10-16', 'severity' => 'high', 'count' => 1, 'id' => nil },
{ 'id' => nil, 'severity' => 'critical', 'day' => '2019-10-17', 'count' => 2 }, { 'day' => '2019-10-17', 'severity' => 'critical', 'count' => 2, 'id' => nil },
{ 'id' => nil, 'severity' => 'high', 'day' => '2019-10-17', 'count' => 1 }, { 'day' => '2019-10-17', 'severity' => 'high', 'count' => 1, 'id' => nil },
{ 'id' => nil, 'severity' => 'critical', 'day' => '2019-10-18', 'count' => 2 }, { 'day' => '2019-10-18', 'severity' => 'critical', 'count' => 2, 'id' => nil },
{ 'id' => nil, 'severity' => 'high', 'day' => '2019-10-18', 'count' => 1 }, { 'day' => '2019-10-18', 'severity' => 'high', 'count' => 1, 'id' => nil },
{ 'id' => nil, 'severity' => 'critical', 'day' => '2019-10-19', 'count' => 1 }, { 'day' => '2019-10-19', 'severity' => 'critical', 'count' => 1, 'id' => nil },
{ 'id' => nil, 'severity' => 'high', 'day' => '2019-10-19', 'count' => 1 }, { 'day' => '2019-10-19', 'severity' => 'high', 'count' => 1, 'id' => nil },
{ 'id' => nil, 'severity' => 'critical', 'day' => '2019-10-20', 'count' => 1 } { 'day' => '2019-10-20', 'severity' => 'critical', 'count' => 1, 'id' => nil }
].to_json) ].to_json)
end end
end end
......
...@@ -635,7 +635,7 @@ RSpec.describe User do ...@@ -635,7 +635,7 @@ RSpec.describe User do
SELECT "users".* FROM "users" SELECT "users".* FROM "users"
WHERE ("users"."state" IN ('active')) WHERE ("users"."state" IN ('active'))
AND AND
("users"."user_type" IS NULL OR "users"."user_type" IN (NULL, 6, 4)) ("users"."user_type" IS NULL OR "users"."user_type" IN (6, 4))
AND AND
("users"."user_type" IS NULL OR "users"."user_type" NOT IN (2, 6, 1, 3, 7, 8)) ("users"."user_type" IS NULL OR "users"."user_type" NOT IN (2, 6, 1, 3, 7, 8))
SQL SQL
...@@ -663,7 +663,7 @@ RSpec.describe User do ...@@ -663,7 +663,7 @@ RSpec.describe User do
SELECT "users".* FROM "users" SELECT "users".* FROM "users"
WHERE ("users"."state" IN ('active')) WHERE ("users"."state" IN ('active'))
AND AND
("users"."user_type" IS NULL OR "users"."user_type" IN (NULL, 6, 4)) ("users"."user_type" IS NULL OR "users"."user_type" IN (6, 4))
AND AND
("users"."user_type" IS NULL OR "users"."user_type" NOT IN (2, 6, 1, 3, 7, 8)) ("users"."user_type" IS NULL OR "users"."user_type" NOT IN (2, 6, 1, 3, 7, 8))
AND AND
......
...@@ -476,12 +476,12 @@ RSpec.describe Vulnerability do ...@@ -476,12 +476,12 @@ RSpec.describe Vulnerability do
context 'when there are less than 10 days between the from and to dates' do context 'when there are less than 10 days between the from and to dates' do
it 'returns the count of unresolved, undismissed vulnerabilities for each severity for each day from the start date to the end date' do it 'returns the count of unresolved, undismissed vulnerabilities for each severity for each day from the start date to the end date' do
expect(counts_by_day_and_severity.order(:day, :severity).to_json).to eq([ expect(counts_by_day_and_severity.order(:day, :severity).to_json).to eq([
{ 'id' => nil, 'severity' => 'high', 'day' => '2019-10-26', 'count' => 1 }, { 'day' => '2019-10-26', 'severity' => 'high', 'count' => 1, 'id' => nil },
{ 'id' => nil, 'severity' => 'critical', 'day' => '2019-10-26', 'count' => 1 }, { 'day' => '2019-10-26', 'severity' => 'critical', 'count' => 1, 'id' => nil },
{ 'id' => nil, 'severity' => 'high', 'day' => '2019-10-27', 'count' => 1 }, { 'day' => '2019-10-27', 'severity' => 'high', 'count' => 1, 'id' => nil },
{ 'id' => nil, 'severity' => 'critical', 'day' => '2019-10-27', 'count' => 2 }, { 'day' => '2019-10-27', 'severity' => 'critical', 'count' => 2, 'id' => nil },
{ 'id' => nil, 'severity' => 'high', 'day' => '2019-10-28', 'count' => 1 }, { 'day' => '2019-10-28', 'severity' => 'high', 'count' => 1, 'id' => nil },
{ 'id' => nil, 'severity' => 'critical', 'day' => '2019-10-28', 'count' => 2 } { 'day' => '2019-10-28', 'severity' => 'critical', 'count' => 2, 'id' => nil }
].to_json) ].to_json)
end end
end end
......
...@@ -18,13 +18,13 @@ RSpec.describe GroupSaml::Identity::DestroyService do ...@@ -18,13 +18,13 @@ RSpec.describe GroupSaml::Identity::DestroyService do
end end
it "does not use a transaction" do it "does not use a transaction" do
expect(::Identity).to receive(:transaction).and_yield.once expect(::Identity).not_to receive(:transaction)
subject.execute subject.execute
end end
it "uses a transaction when transactional is set" do it "uses a transaction when transactional is set" do
expect(::Identity).to receive(:transaction).and_yield.twice expect(::Identity).to receive(:transaction).and_yield.once
subject.execute(transactional: true) subject.execute(transactional: true)
end end
......
...@@ -61,7 +61,7 @@ module Gitlab ...@@ -61,7 +61,7 @@ module Gitlab
end end
def self.config def self.config
default_config_hash = ActiveRecord::Base.configurations.find_db_config(Rails.env)&.config || {} default_config_hash = ActiveRecord::Base.configurations.find_db_config(Rails.env)&.configuration_hash || {}
default_config_hash.with_indifferent_access.tap do |hash| default_config_hash.with_indifferent_access.tap do |hash|
# Match config/initializers/database_config.rb # Match config/initializers/database_config.rb
......
...@@ -45,8 +45,8 @@ module Gitlab ...@@ -45,8 +45,8 @@ module Gitlab
def labels_for_class(klass) def labels_for_class(klass)
{ {
host: klass.connection_config[:host], host: klass.connection_db_config.host,
port: klass.connection_config[:port], port: klass.connection_db_config.configuration_hash[:port],
class: klass.to_s class: klass.to_s
} }
end end
......
...@@ -46,7 +46,10 @@ module ReleaseHighlights ...@@ -46,7 +46,10 @@ module ReleaseHighlights
def add_line_numbers_to_errors! def add_line_numbers_to_errors!
errors.messages.each do |attribute, messages| errors.messages.each do |attribute, messages|
messages.map! { |m| "#{m} (line #{line_number_for(attribute)})" } extended_messages = messages.map { |m| "#{m} (line #{line_number_for(attribute)})" }
errors.delete(attribute)
extended_messages.each { |extended_message| errors.add(attribute, extended_message) }
end end
end end
......
...@@ -43,7 +43,7 @@ module QA ...@@ -43,7 +43,7 @@ module QA
it 'tests contributions', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/527' do it 'tests contributions', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/527' do
EE::Page::Group::ContributionAnalytics.perform do |contribution_analytics| EE::Page::Group::ContributionAnalytics.perform do |contribution_analytics|
expect(contribution_analytics).to have_push_element('3 pushes, more than 4.0 commits by 1 person contributors.') expect(contribution_analytics).to have_push_element('3 pushes, more than 4 commits by 1 person contributors.')
expect(contribution_analytics).to have_mr_element('1 created, 1 merged.') expect(contribution_analytics).to have_mr_element('1 created, 1 merged.')
expect(contribution_analytics).to have_issue_element('1 created, 1 closed.') expect(contribution_analytics).to have_issue_element('1 created, 1 closed.')
end end
......
...@@ -704,7 +704,7 @@ RSpec.describe ApplicationController do ...@@ -704,7 +704,7 @@ RSpec.describe ApplicationController do
get :index get :index
expect(response.headers['Cache-Control']).to eq 'max-age=0, private, must-revalidate, no-store' expect(response.headers['Cache-Control']).to eq 'no-store'
expect(response.headers['Pragma']).to eq 'no-cache' expect(response.headers['Pragma']).to eq 'no-cache'
end end
...@@ -740,7 +740,7 @@ RSpec.describe ApplicationController do ...@@ -740,7 +740,7 @@ RSpec.describe ApplicationController do
it 'sets no-cache headers', :aggregate_failures do it 'sets no-cache headers', :aggregate_failures do
subject subject
expect(response.headers['Cache-Control']).to eq 'no-cache, no-store' expect(response.headers['Cache-Control']).to eq 'no-store'
expect(response.headers['Pragma']).to eq 'no-cache' expect(response.headers['Pragma']).to eq 'no-cache'
expect(response.headers['Expires']).to eq 'Fri, 01 Jan 1990 00:00:00 GMT' expect(response.headers['Expires']).to eq 'Fri, 01 Jan 1990 00:00:00 GMT'
end end
......
...@@ -258,7 +258,7 @@ RSpec.describe SearchController do ...@@ -258,7 +258,7 @@ RSpec.describe SearchController do
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(response.headers['Cache-Control']).to include('max-age=60, private') expect(response.headers['Cache-Control']).to eq('no-store')
end end
end end
......
...@@ -269,7 +269,7 @@ RSpec.describe 'Database schema' do ...@@ -269,7 +269,7 @@ RSpec.describe 'Database schema' do
sql = <<~SQL sql = <<~SQL
SELECT table_name, column_name, data_type SELECT table_name, column_name, data_type
FROM information_schema.columns FROM information_schema.columns
WHERE table_catalog = '#{ApplicationRecord.connection_config[:database]}' WHERE table_catalog = '#{ApplicationRecord.connection_db_config.database}'
AND table_schema = 'public' AND table_schema = 'public'
AND table_name NOT LIKE 'pg_%' AND table_name NOT LIKE 'pg_%'
AND data_type = 'jsonb' AND data_type = 'jsonb'
......
...@@ -68,7 +68,7 @@ RSpec.describe 'Pipeline Badge' do ...@@ -68,7 +68,7 @@ RSpec.describe 'Pipeline Badge' do
visit pipeline_project_badges_path(project, ref: ref, format: :svg) visit pipeline_project_badges_path(project, ref: ref, format: :svg)
expect(page.status_code).to eq(200) expect(page.status_code).to eq(200)
expect(page.response_headers['Cache-Control']).to include 'no-cache' expect(page.response_headers['Cache-Control']).to eq('no-store')
end end
end end
......
...@@ -3,8 +3,7 @@ ...@@ -3,8 +3,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Gitlab::Database::LoadBalancing::LoadBalancer, :request_store do RSpec.describe Gitlab::Database::LoadBalancing::LoadBalancer, :request_store do
let(:pool_spec) { ActiveRecord::Base.connection_pool.spec } let(:pool) { Gitlab::Database.create_connection_pool(2) }
let(:pool) { ActiveRecord::ConnectionAdapters::ConnectionPool.new(pool_spec) }
let(:conflict_error) { Class.new(RuntimeError) } let(:conflict_error) { Class.new(RuntimeError) }
let(:lb) { described_class.new(%w(localhost localhost)) } let(:lb) { described_class.new(%w(localhost localhost)) }
......
...@@ -580,7 +580,7 @@ RSpec.describe Gitlab::Database::PartitioningMigrationHelpers::TableManagementHe ...@@ -580,7 +580,7 @@ RSpec.describe Gitlab::Database::PartitioningMigrationHelpers::TableManagementHe
it 'idempotently cleans up after failed background migrations' do it 'idempotently cleans up after failed background migrations' do
expect(partitioned_model.count).to eq(0) expect(partitioned_model.count).to eq(0)
partitioned_model.insert!(record2.attributes) partitioned_model.insert(record2.attributes, unique_by: [:id, :created_at])
expect_next_instance_of(Gitlab::Database::PartitioningMigrationHelpers::BackfillPartitionedTable) do |backfill| expect_next_instance_of(Gitlab::Database::PartitioningMigrationHelpers::BackfillPartitionedTable) do |backfill|
allow(backfill).to receive(:transaction_open?).and_return(false) allow(backfill).to receive(:transaction_open?).and_return(false)
......
...@@ -242,10 +242,10 @@ RSpec.describe Gitlab::Database::WithLockRetries do ...@@ -242,10 +242,10 @@ RSpec.describe Gitlab::Database::WithLockRetries do
let(:timing_configuration) { [[0.015.seconds, 0.025.seconds], [0.015.seconds, 0.025.seconds]] } # 15ms, 25ms let(:timing_configuration) { [[0.015.seconds, 0.025.seconds], [0.015.seconds, 0.025.seconds]] } # 15ms, 25ms
it 'executes `SET LOCAL lock_timeout` using the configured timeout value in milliseconds' do it 'executes `SET LOCAL lock_timeout` using the configured timeout value in milliseconds' do
expect(ActiveRecord::Base.connection).to receive(:execute).with("SAVEPOINT active_record_1").and_call_original expect(ActiveRecord::Base.connection).to receive(:execute).with("RESET idle_in_transaction_session_timeout; RESET lock_timeout").and_call_original
expect(ActiveRecord::Base.connection).to receive(:execute).with('RESET idle_in_transaction_session_timeout; RESET lock_timeout').and_call_original expect(ActiveRecord::Base.connection).to receive(:execute).with("SAVEPOINT active_record_1", "TRANSACTION").and_call_original
expect(ActiveRecord::Base.connection).to receive(:execute).with("SET LOCAL lock_timeout TO '15ms'").and_call_original expect(ActiveRecord::Base.connection).to receive(:execute).with("SET LOCAL lock_timeout TO '15ms'").and_call_original
expect(ActiveRecord::Base.connection).to receive(:execute).with("RELEASE SAVEPOINT active_record_1").and_call_original expect(ActiveRecord::Base.connection).to receive(:execute).with("RELEASE SAVEPOINT active_record_1", "TRANSACTION").and_call_original
subject.run { } subject.run { }
end end
......
...@@ -329,7 +329,7 @@ RSpec.describe Gitlab::Database do ...@@ -329,7 +329,7 @@ RSpec.describe Gitlab::Database do
expect(pool) expect(pool)
.to be_kind_of(ActiveRecord::ConnectionAdapters::ConnectionPool) .to be_kind_of(ActiveRecord::ConnectionAdapters::ConnectionPool)
expect(pool.spec.config[:pool]).to eq(5) expect(pool.db_config.pool).to eq(5)
ensure ensure
pool.disconnect! pool.disconnect!
end end
...@@ -339,7 +339,7 @@ RSpec.describe Gitlab::Database do ...@@ -339,7 +339,7 @@ RSpec.describe Gitlab::Database do
pool = described_class.create_connection_pool(5, '127.0.0.1') pool = described_class.create_connection_pool(5, '127.0.0.1')
begin begin
expect(pool.spec.config[:host]).to eq('127.0.0.1') expect(pool.db_config.host).to eq('127.0.0.1')
ensure ensure
pool.disconnect! pool.disconnect!
end end
...@@ -349,8 +349,8 @@ RSpec.describe Gitlab::Database do ...@@ -349,8 +349,8 @@ RSpec.describe Gitlab::Database do
pool = described_class.create_connection_pool(5, '127.0.0.1', 5432) pool = described_class.create_connection_pool(5, '127.0.0.1', 5432)
begin begin
expect(pool.spec.config[:host]).to eq('127.0.0.1') expect(pool.db_config.host).to eq('127.0.0.1')
expect(pool.spec.config[:port]).to eq(5432) expect(pool.db_config.configuration_hash[:port]).to eq(5432)
ensure ensure
pool.disconnect! pool.disconnect!
end end
......
...@@ -43,7 +43,7 @@ RSpec.describe Gitlab::ImportExport::ImportFailureService do ...@@ -43,7 +43,7 @@ RSpec.describe Gitlab::ImportExport::ImportFailureService do
let(:importable) { create(:merge_request) } let(:importable) { create(:merge_request) }
it 'raise exception' do it 'raise exception' do
expect { subject }.to raise_exception(ActiveRecord::AssociationNotFoundError, "Association named 'import_failures' was not found on MergeRequest; perhaps you misspelled it?") expect { subject }.to raise_exception(ActiveRecord::AssociationNotFoundError, /Association named 'import_failures' was not found on MergeRequest/)
end end
end end
end end
......
...@@ -20,6 +20,13 @@ RSpec.describe BulkInsertSafe do ...@@ -20,6 +20,13 @@ RSpec.describe BulkInsertSafe do
t.index :name, unique: true t.index :name, unique: true
end end
create_table :bulk_insert_items_with_composite_pk, id: false, force: true do |t|
t.integer :id, null: true
t.string :name, null: true
end
execute("ALTER TABLE bulk_insert_items_with_composite_pk ADD PRIMARY KEY (id,name);")
end end
end end
...@@ -27,6 +34,7 @@ RSpec.describe BulkInsertSafe do ...@@ -27,6 +34,7 @@ RSpec.describe BulkInsertSafe do
ActiveRecord::Schema.define do ActiveRecord::Schema.define do
drop_table :bulk_insert_items, force: true drop_table :bulk_insert_items, force: true
drop_table :bulk_insert_parent_items, force: true drop_table :bulk_insert_parent_items, force: true
drop_table :bulk_insert_items_with_composite_pk, force: true
end end
end end
...@@ -227,5 +235,28 @@ RSpec.describe BulkInsertSafe do ...@@ -227,5 +235,28 @@ RSpec.describe BulkInsertSafe do
end end
end end
end end
context 'when a model with composite primary key is inserted' do
let_it_be(:bulk_insert_items_with_composite_pk_class) do
Class.new(ActiveRecord::Base) do
self.table_name = 'bulk_insert_items_with_composite_pk'
include BulkInsertSafe
end
end
let(:new_object) { bulk_insert_items_with_composite_pk_class.new(id: 1, name: 'composite') }
it 'successfully inserts an item' do
expect(ActiveRecord::InsertAll).to receive(:new)
.with(
bulk_insert_items_with_composite_pk_class, [new_object.as_json], on_duplicate: :raise, returning: false, unique_by: %w[id name]
).and_call_original
expect { bulk_insert_items_with_composite_pk_class.bulk_insert!([new_object]) }.to(
change(bulk_insert_items_with_composite_pk_class, :count).from(0).to(1)
)
end
end
end end
end end
...@@ -558,8 +558,7 @@ RSpec.describe API::Files do ...@@ -558,8 +558,7 @@ RSpec.describe API::Files do
get api(url, current_user), params: params get api(url, current_user), params: params
expect(response.headers["Cache-Control"]).to include("no-store") expect(response.headers["Cache-Control"]).to eq("max-age=0, private, must-revalidate, no-store, no-cache")
expect(response.headers["Cache-Control"]).to include("no-cache")
expect(response.headers["Pragma"]).to eq("no-cache") expect(response.headers["Pragma"]).to eq("no-cache")
expect(response.headers["Expires"]).to eq("Fri, 01 Jan 1990 00:00:00 GMT") expect(response.headers["Expires"]).to eq("Fri, 01 Jan 1990 00:00:00 GMT")
end end
......
...@@ -178,10 +178,12 @@ RSpec.describe API::Repositories do ...@@ -178,10 +178,12 @@ RSpec.describe API::Repositories do
expect(headers['Content-Disposition']).to eq 'inline' expect(headers['Content-Disposition']).to eq 'inline'
end end
it_behaves_like 'uncached response' do it 'defines an uncached header response' do
before do get api(route, current_user)
get api(route, current_user)
end expect(response.headers["Cache-Control"]).to eq("max-age=0, private, must-revalidate, no-store, no-cache")
expect(response.headers["Pragma"]).to eq("no-cache")
expect(response.headers["Expires"]).to eq("Fri, 01 Jan 1990 00:00:00 GMT")
end end
context 'when sha does not exist' do context 'when sha does not exist' do
......
...@@ -35,8 +35,6 @@ RSpec.configure do |config| ...@@ -35,8 +35,6 @@ RSpec.configure do |config|
puts "Recreating the database" puts "Recreating the database"
start = Gitlab::Metrics::System.monotonic_time start = Gitlab::Metrics::System.monotonic_time
ActiveRecord::AdvisoryLockBase.clear_all_connections!
ActiveRecord::Tasks::DatabaseTasks.drop_current ActiveRecord::Tasks::DatabaseTasks.drop_current
ActiveRecord::Tasks::DatabaseTasks.create_current ActiveRecord::Tasks::DatabaseTasks.create_current
ActiveRecord::Tasks::DatabaseTasks.load_schema_current ActiveRecord::Tasks::DatabaseTasks.load_schema_current
......
...@@ -298,7 +298,7 @@ RSpec.shared_examples 'wiki controller actions' do ...@@ -298,7 +298,7 @@ RSpec.shared_examples 'wiki controller actions' do
expect(response.headers['Content-Disposition']).to match(/^inline/) expect(response.headers['Content-Disposition']).to match(/^inline/)
expect(response.headers[Gitlab::Workhorse::DETECT_HEADER]).to eq('true') expect(response.headers[Gitlab::Workhorse::DETECT_HEADER]).to eq('true')
expect(response.cache_control[:public]).to be(false) expect(response.cache_control[:public]).to be(false)
expect(response.cache_control[:extras]).to include('no-store') expect(response.headers['Cache-Control']).to eq('no-store')
end end
end end
end end
......
# frozen_string_literal: true
#
# Pairs with lib/gitlab/no_cache_headers.rb
#
RSpec.shared_examples 'uncached response' do
it 'defines an uncached header response' do
expect(response.headers["Cache-Control"]).to include("no-store", "no-cache")
expect(response.headers["Pragma"]).to eq("no-cache")
expect(response.headers["Expires"]).to eq("Fri, 01 Jan 1990 00:00:00 GMT")
end
end
...@@ -25,13 +25,11 @@ RSpec.describe 'shared/nav/_sidebar.html.haml' do ...@@ -25,13 +25,11 @@ RSpec.describe 'shared/nav/_sidebar.html.haml' do
context 'when sidebar does not have a scope menu' do context 'when sidebar does not have a scope menu' do
let(:scope_menu_view_path) { 'shared/nav/' } let(:scope_menu_view_path) { 'shared/nav/' }
let(:scope_menu_view_name) { 'scope_menu.html.haml' } let(:scope_menu_view_name) { 'scope_menu.html.haml' }
let(:scope_menu_view) { "#{scope_menu_view_path}#{scope_menu_view_name}" }
let(:scope_menu_partial) { "#{scope_menu_view_path}_#{scope_menu_view_name}" } let(:scope_menu_partial) { "#{scope_menu_view_path}_#{scope_menu_view_name}" }
let(:content) { 'Custom test content' } let(:content) { 'Custom test content' }
context 'when sidebar has a custom scope menu partial defined' do context 'when sidebar has a custom scope menu partial defined' do
it 'renders the custom partial' do it 'renders the custom partial' do
allow(sidebar).to receive(:render_raw_scope_menu_partial).and_return(scope_menu_view)
allow(view).to receive(:scope_menu).and_return(nil) allow(view).to receive(:scope_menu).and_return(nil)
stub_template(scope_menu_partial => content) stub_template(scope_menu_partial => content)
......
...@@ -1176,15 +1176,15 @@ ...@@ -1176,15 +1176,15 @@
resolved "https://registry.yarnpkg.com/@popperjs/core/-/core-2.9.2.tgz#adea7b6953cbb34651766b0548468e743c6a2353" resolved "https://registry.yarnpkg.com/@popperjs/core/-/core-2.9.2.tgz#adea7b6953cbb34651766b0548468e743c6a2353"
integrity sha512-VZMYa7+fXHdwIq1TDhSXoVmSPEGM/aa+6Aiq3nVVJ9bXr24zScr+NlKFKC3iPljA7ho/GAZr+d2jOf5GIRC30Q== integrity sha512-VZMYa7+fXHdwIq1TDhSXoVmSPEGM/aa+6Aiq3nVVJ9bXr24zScr+NlKFKC3iPljA7ho/GAZr+d2jOf5GIRC30Q==
"@rails/actioncable@^6.0.3-4": "@rails/actioncable@6.1.3-2":
version "6.1.0" version "6.1.3-2"
resolved "https://registry.yarnpkg.com/@rails/actioncable/-/actioncable-6.1.0.tgz#f336f25450b1bc43b99bc60557a70b6e6bb1d3d2" resolved "https://registry.yarnpkg.com/@rails/actioncable/-/actioncable-6.1.3-2.tgz#de22e2d7474dcca051f7060829450412a17ecc04"
integrity sha512-eDgy+vcKN9RIzxmMBfSAe77rTj2cp6kJALiVQyKrW2O9EK2MdostOmP+99At/Dit3ur5+77NVnruxD7y14ZYFA== integrity sha512-3mBLDwM85oj0Ot+wgC3c0wsfx5qvf8XJwSbkJk4ZqW4bA7ctn8BFW+cRQxrnQau+NDfmJvSECY8mmNIANcpULA==
"@rails/ujs@^6.0.3-4": "@rails/ujs@6.1.3-2":
version "6.1.0" version "6.1.3-2"
resolved "https://registry.yarnpkg.com/@rails/ujs/-/ujs-6.1.0.tgz#9a48df6511cb2b472c9f596c1f37dc0af022e751" resolved "https://registry.yarnpkg.com/@rails/ujs/-/ujs-6.1.3-2.tgz#5d7e161e7061654e738a116a7ec8b58b51721a11"
integrity sha512-kQNKyM4ePAc4u9eR1c4OqrbAHH+3SJXt++8izIjeaZeg+P7yBtgoF/dogMD/JPPowNC74ACFpM/4op0Ggp/fPw== integrity sha512-Nd0Im4cW8tIX8ZR3jE/dS3wnJrN46RJSdCfU59Cji2puctIWohq63LjKFMufUwm21bCasISNGoLdkr3S7nwONw==
"@sentry/browser@^5.22.3": "@sentry/browser@^5.22.3":
version "5.30.0" version "5.30.0"
......
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