DEV: Fix `FakeLogger` spec issues (#12397)

* DEV: Add `#level` and `#level=` to `FakeLogger`

* DEV: Fix a leaky test
This commit is contained in:
Jarek Radosz 2021-03-15 05:36:10 +01:00 committed by GitHub
parent 5c84f702b0
commit 303d2227cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 11 deletions

View File

@ -657,20 +657,26 @@ HTML
end end
it 'warns when the theme has modified the setting type but data cannot be converted' do it 'warns when the theme has modified the setting type but data cannot be converted' do
Rails.logger = FakeLogger.new begin
theme.set_field(target: :settings, name: :yaml, value: "valid_json_schema_setting:\n default: \"\"\n type: \"list\"") @orig_logger = Rails.logger
theme.save! Rails.logger = FakeLogger.new
setting = theme.settings.find { |s| s.name == :valid_json_schema_setting } theme.set_field(target: :settings, name: :yaml, value: "valid_json_schema_setting:\n default: \"\"\n type: \"list\"")
setting.value = "red,globe" theme.save!
theme.save!
theme.set_field(target: :settings, name: :yaml, value: "valid_json_schema_setting:\n default: \"\"\n type: \"string\"") setting = theme.settings.find { |s| s.name == :valid_json_schema_setting }
theme.save! setting.value = "red,globe"
theme.save!
theme.convert_settings theme.set_field(target: :settings, name: :yaml, value: "valid_json_schema_setting:\n default: \"\"\n type: \"string\"")
expect(setting.value).to eq("red,globe") theme.save!
expect(Rails.logger.warnings[0]).to include("Theme setting type has changed but cannot be converted.")
theme.convert_settings
expect(setting.value).to eq("red,globe")
expect(Rails.logger.warnings[0]).to include("Theme setting type has changed but cannot be converted.")
ensure
Rails.logger = @orig_logger
end
end end
end end

View File

@ -2,6 +2,7 @@
class FakeLogger class FakeLogger
attr_reader :warnings, :errors, :infos, :fatals attr_reader :warnings, :errors, :infos, :fatals
attr_accessor :level
def initialize def initialize
@warnings = [] @warnings = []