Skip to content

Commit d10881e

Browse files
committed
♻️ Update versioned default configs
This reorganizes the creation of `Config.version_defaults` to make it easier to cherry-pick backported config changes to stable branches: * Sets `Config[0.5]` as a diff from the previous versioned default, just like the other versioned defaults. * Sets `Config[:current] = Config[VERSION.to_f]`, so it will not need to be updated for any x.y.0 release. Likewise, sets `Config[:next]` and `Config[:future]` to `Config[VERSION.to_f + 0.1]` or `+ 0.2`, so they which will only rarely need to be changed. * Because `Config[:default]` and `Config[:current]` are now derived two different ways, both a warning and a test have been added to ensure they remain synchronized. * A few other `Config.version_defaults` tests were added or updated.
1 parent 21ef44c commit d10881e

File tree

2 files changed

+50
-12
lines changed

2 files changed

+50
-12
lines changed

lib/net/imap/config.rb

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -435,9 +435,8 @@ def defaults_hash
435435
@global = default.new
436436

437437
version_defaults[:default] = Config[default.send(:defaults_hash)]
438-
version_defaults[:current] = Config[:default]
439438

440-
version_defaults[0] = Config[:current].dup.update(
439+
version_defaults[0] = Config[:default].dup.update(
441440
sasl_ir: false,
442441
responses_without_block: :silence_deprecation_warning,
443442
enforce_logindisabled: false,
@@ -454,17 +453,36 @@ def defaults_hash
454453
parser_max_deprecated_uidplus_data_size: 1000,
455454
).freeze
456455

457-
version_defaults[0.5] = Config[:current]
456+
version_defaults[0.5] = Config[0.4].dup.update(
457+
enforce_logindisabled: true,
458+
responses_without_block: :warn,
459+
parser_use_deprecated_uidplus_data: :up_to_max_size,
460+
parser_max_deprecated_uidplus_data_size: 100,
461+
).freeze
458462

459463
version_defaults[0.6] = Config[0.5].dup.update(
460464
responses_without_block: :frozen_dup,
461465
parser_use_deprecated_uidplus_data: false,
462466
parser_max_deprecated_uidplus_data_size: 0,
463467
).freeze
464-
version_defaults[:next] = Config[0.6]
465-
version_defaults[:future] = Config[:next]
468+
469+
version_defaults[0.7] = Config[0.6].dup.update(
470+
).freeze
471+
472+
current = VERSION.to_f
473+
version_defaults[:original] = Config[0]
474+
version_defaults[:current] = Config[current]
475+
version_defaults[:next] = Config[current + 0.1]
476+
version_defaults[:future] = Config[current + 0.2]
466477

467478
version_defaults.freeze
479+
480+
if ($VERBOSE || $DEBUG) && self[:current].to_h != self[:default].to_h
481+
warn "Misconfigured Net::IMAP::Config[:current] => %p,\n" \
482+
" not equal to Net::IMAP::Config[:default] => %p" % [
483+
self[:current].to_h, self[:default].to_h
484+
]
485+
end
468486
end
469487
end
470488
end

test/net/imap/test_config.rb

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
class ConfigTest < Test::Unit::TestCase
77
Config = Net::IMAP::Config
8+
THIS_VERSION = Net::IMAP::VERSION.to_f
9+
NEXT_VERSION = THIS_VERSION + 0.1
10+
FUTURE_VERSION = THIS_VERSION + 0.2
811

912
setup do
1013
Config.global.reset
@@ -141,19 +144,36 @@ class ConfigTest < Test::Unit::TestCase
141144
assert_kind_of Config, config
142145
assert config.frozen?, "#{name} isn't frozen"
143146
assert config.inherited?(:debug), "#{name} doesn't inherit debug"
147+
keys = config.to_h.keys - [:debug]
148+
keys.each do |key|
149+
refute config.inherited?(key)
150+
end
144151
assert_same Config.global, config.parent
145152
end
146153
end
147154

155+
test "Config[:default] and Config[:current] both hold default config" do
156+
defaults = Config.default.to_h
157+
assert_equal(defaults, Config[:default].to_h)
158+
assert_equal(defaults, Config[:current].to_h)
159+
end
160+
161+
test ".[] for all version_defaults" do
162+
Config.version_defaults.each do |version, config|
163+
assert_same Config[version], config
164+
end
165+
end
166+
148167
test ".[] for all x.y versions" do
149168
original = Config[0]
150169
assert_kind_of Config, original
151170
assert_same original, Config[0.0]
152171
assert_same original, Config[0.1]
153172
assert_same original, Config[0.2]
154173
assert_same original, Config[0.3]
155-
assert_kind_of Config, Config[0.4]
156-
assert_kind_of Config, Config[0.5]
174+
((0.4r..FUTURE_VERSION.to_r) % 0.1r).each do |version|
175+
assert_kind_of Config, Config[version.to_f]
176+
end
157177
end
158178

159179
test ".[] range errors" do
@@ -169,10 +189,10 @@ class ConfigTest < Test::Unit::TestCase
169189
end
170190

171191
test ".[] with symbol names" do
172-
assert_same Config[0.5], Config[:current]
173-
assert_same Config[0.5], Config[:default]
174-
assert_same Config[0.6], Config[:next]
175-
assert_kind_of Config, Config[:future]
192+
assert_equal Config[THIS_VERSION].to_h, Config[:default].to_h
193+
assert_same Config[THIS_VERSION], Config[:current]
194+
assert_same Config[NEXT_VERSION], Config[:next]
195+
assert_same Config[FUTURE_VERSION], Config[:future]
176196
end
177197

178198
test ".[] with a hash" do
@@ -190,7 +210,7 @@ class ConfigTest < Test::Unit::TestCase
190210
assert_same Config.default, Config.new(Config.default).parent
191211
assert_same Config.global, Config.new(Config.global).parent
192212
assert_same Config[0.4], Config.new(0.4).parent
193-
assert_same Config[0.6], Config.new(:next).parent
213+
assert_same Config[NEXT_VERSION], Config.new(:next).parent
194214
assert_equal true, Config.new({debug: true}, debug: false).parent.debug?
195215
assert_equal true, Config.new({debug: true}, debug: false).parent.frozen?
196216
end

0 commit comments

Comments
 (0)