From 3bf1cd5780fc6f08eac8046c8a6b475b8f7f30b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Mon, 10 Sep 2018 11:48:09 +0200 Subject: Ensure in-memory application settings are cleared before each test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rémy Coutable --- lib/gitlab/current_settings.rb | 4 ++++ spec/spec_helper.rb | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/lib/gitlab/current_settings.rb b/lib/gitlab/current_settings.rb index 9147ef401da..8eba8edb46d 100644 --- a/lib/gitlab/current_settings.rb +++ b/lib/gitlab/current_settings.rb @@ -13,6 +13,10 @@ module Gitlab Gitlab::FakeApplicationSettings.new(::ApplicationSetting.defaults.merge(attributes || {})) end + def clear_in_memory_application_settings! + instance_variable_set(:@in_memory_application_settings, nil) + end + def method_missing(name, *args, &block) current_application_settings.send(name, *args, &block) # rubocop:disable GitlabSecurity/PublicSend end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c4bb1c13f2e..d1337325973 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -135,6 +135,10 @@ RSpec.configure do |config| Fog.unmock! if Fog.mock? end + config.after(:example) do + Gitlab::CurrentSettings.clear_in_memory_application_settings! + end + config.before(:example, :mailer) do reset_delivered_emails! end -- cgit v1.2.1 From 183c94dd638ab4306948733b68eccf35a6372dd1 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Mon, 10 Sep 2018 14:01:20 -0700 Subject: Work around migration specs failing due to repository storages not being selected Migration specs may be missing a column necessary to create an ApplicationSetting object, which causes the FakeApplicationSetting to be initialized. However, the project selects a random repository storage via ApplicationSetting#pick_repository_storage, which isn't present in the OpenStruct. To workaround this issues, we add a pick_repository_storage method in FakeApplicationSetting. --- lib/gitlab/fake_application_settings.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/gitlab/fake_application_settings.rb b/lib/gitlab/fake_application_settings.rb index bb14a8cd9e7..753160cc562 100644 --- a/lib/gitlab/fake_application_settings.rb +++ b/lib/gitlab/fake_application_settings.rb @@ -11,6 +11,10 @@ module Gitlab FakeApplicationSettings.define_predicate_methods(options) end + def pick_repository_storage + repository_storages.sample + end + # Mimic ActiveRecord predicate methods for boolean values def self.define_predicate_methods(options) options.each do |key, value| -- cgit v1.2.1 From 855b23836168d1621a3dcb748e1a849d8833a7c3 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Mon, 10 Sep 2018 15:04:27 -0700 Subject: Simplify setting of in_memory_application_settings --- lib/gitlab/current_settings.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/gitlab/current_settings.rb b/lib/gitlab/current_settings.rb index 8eba8edb46d..c9dbd2d2e5f 100644 --- a/lib/gitlab/current_settings.rb +++ b/lib/gitlab/current_settings.rb @@ -14,7 +14,7 @@ module Gitlab end def clear_in_memory_application_settings! - instance_variable_set(:@in_memory_application_settings, nil) + @in_memory_application_settings = nil end def method_missing(name, *args, &block) -- cgit v1.2.1