hashie 3.5.7 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +281 -195
  3. data/CONTRIBUTING.md +13 -6
  4. data/LICENSE +1 -1
  5. data/README.md +320 -60
  6. data/Rakefile +2 -2
  7. data/UPGRADING.md +121 -7
  8. data/hashie.gemspec +13 -7
  9. data/lib/hashie/clash.rb +12 -1
  10. data/lib/hashie/dash.rb +56 -35
  11. data/lib/hashie/extensions/active_support/core_ext/hash.rb +14 -0
  12. data/lib/hashie/extensions/coercion.rb +26 -19
  13. data/lib/hashie/extensions/dash/indifferent_access.rb +29 -1
  14. data/lib/hashie/extensions/dash/predefined_values.rb +88 -0
  15. data/lib/hashie/extensions/dash/property_translation.rb +59 -28
  16. data/lib/hashie/extensions/deep_fetch.rb +5 -3
  17. data/lib/hashie/extensions/deep_find.rb +14 -5
  18. data/lib/hashie/extensions/deep_locate.rb +22 -8
  19. data/lib/hashie/extensions/deep_merge.rb +26 -10
  20. data/lib/hashie/extensions/ignore_undeclared.rb +4 -5
  21. data/lib/hashie/extensions/indifferent_access.rb +43 -10
  22. data/lib/hashie/extensions/key_conflict_warning.rb +55 -0
  23. data/lib/hashie/extensions/mash/define_accessors.rb +90 -0
  24. data/lib/hashie/extensions/mash/keep_original_keys.rb +4 -5
  25. data/lib/hashie/extensions/mash/permissive_respond_to.rb +61 -0
  26. data/lib/hashie/extensions/mash/safe_assignment.rb +3 -1
  27. data/lib/hashie/extensions/mash/symbolize_keys.rb +6 -6
  28. data/lib/hashie/extensions/method_access.rb +47 -14
  29. data/lib/hashie/extensions/parsers/yaml_erb_parser.rb +28 -4
  30. data/lib/hashie/extensions/ruby_version_check.rb +5 -1
  31. data/lib/hashie/extensions/strict_key_access.rb +16 -13
  32. data/lib/hashie/extensions/stringify_keys.rb +1 -1
  33. data/lib/hashie/extensions/symbolize_keys.rb +13 -2
  34. data/lib/hashie/hash.rb +18 -11
  35. data/lib/hashie/mash.rb +147 -81
  36. data/lib/hashie/railtie.rb +7 -0
  37. data/lib/hashie/rash.rb +6 -6
  38. data/lib/hashie/utils.rb +28 -0
  39. data/lib/hashie/version.rb +1 -1
  40. data/lib/hashie.rb +22 -19
  41. metadata +23 -131
  42. data/spec/hashie/array_spec.rb +0 -29
  43. data/spec/hashie/clash_spec.rb +0 -70
  44. data/spec/hashie/dash_spec.rb +0 -573
  45. data/spec/hashie/extensions/autoload_spec.rb +0 -24
  46. data/spec/hashie/extensions/coercion_spec.rb +0 -631
  47. data/spec/hashie/extensions/dash/coercion_spec.rb +0 -13
  48. data/spec/hashie/extensions/dash/indifferent_access_spec.rb +0 -84
  49. data/spec/hashie/extensions/deep_fetch_spec.rb +0 -97
  50. data/spec/hashie/extensions/deep_find_spec.rb +0 -138
  51. data/spec/hashie/extensions/deep_locate_spec.rb +0 -137
  52. data/spec/hashie/extensions/deep_merge_spec.rb +0 -70
  53. data/spec/hashie/extensions/ignore_undeclared_spec.rb +0 -47
  54. data/spec/hashie/extensions/indifferent_access_spec.rb +0 -282
  55. data/spec/hashie/extensions/indifferent_access_with_rails_hwia_spec.rb +0 -208
  56. data/spec/hashie/extensions/key_conversion_spec.rb +0 -12
  57. data/spec/hashie/extensions/mash/keep_original_keys_spec.rb +0 -46
  58. data/spec/hashie/extensions/mash/safe_assignment_spec.rb +0 -50
  59. data/spec/hashie/extensions/mash/symbolize_keys_spec.rb +0 -39
  60. data/spec/hashie/extensions/merge_initializer_spec.rb +0 -23
  61. data/spec/hashie/extensions/method_access_spec.rb +0 -188
  62. data/spec/hashie/extensions/strict_key_access_spec.rb +0 -110
  63. data/spec/hashie/extensions/stringify_keys_spec.rb +0 -124
  64. data/spec/hashie/extensions/symbolize_keys_spec.rb +0 -129
  65. data/spec/hashie/hash_spec.rb +0 -84
  66. data/spec/hashie/mash_spec.rb +0 -763
  67. data/spec/hashie/parsers/yaml_erb_parser_spec.rb +0 -46
  68. data/spec/hashie/rash_spec.rb +0 -83
  69. data/spec/hashie/trash_spec.rb +0 -268
  70. data/spec/hashie/utils_spec.rb +0 -25
  71. data/spec/hashie/version_spec.rb +0 -7
  72. data/spec/hashie_spec.rb +0 -13
  73. data/spec/integration/omniauth/app.rb +0 -11
  74. data/spec/integration/omniauth/integration_spec.rb +0 -38
  75. data/spec/integration/omniauth-oauth2/app.rb +0 -53
  76. data/spec/integration/omniauth-oauth2/integration_spec.rb +0 -26
  77. data/spec/integration/omniauth-oauth2/some_site.rb +0 -38
  78. data/spec/integration/rails/app.rb +0 -48
  79. data/spec/integration/rails/integration_spec.rb +0 -26
  80. data/spec/integration/rails-without-dependency/integration_spec.rb +0 -15
  81. data/spec/spec_helper.rb +0 -23
  82. data/spec/support/integration_specs.rb +0 -36
  83. data/spec/support/logger.rb +0 -24
  84. data/spec/support/module_context.rb +0 -11
  85. data/spec/support/ruby_version_check.rb +0 -6
@@ -1,573 +0,0 @@
1
- require 'spec_helper'
2
-
3
- Hashie::Hash.class_eval do
4
- def self.inherited(klass)
5
- klass.instance_variable_set('@inheritance_test', true)
6
- end
7
- end
8
-
9
- class DashTest < Hashie::Dash
10
- property :first_name, required: true
11
- property :email
12
- property :count, default: 0
13
- end
14
-
15
- class DashTestDefaultProc < Hashie::Dash
16
- property :fields, default: -> { [] }
17
- end
18
-
19
- class DashNoRequiredTest < Hashie::Dash
20
- property :first_name
21
- property :email
22
- property :count, default: 0
23
- end
24
-
25
- class DashWithCoercion < Hashie::Dash
26
- include Hashie::Extensions::Coercion
27
- property :person
28
- property :city
29
-
30
- coerce_key :person, ::DashNoRequiredTest
31
- end
32
-
33
- class PropertyBangTest < Hashie::Dash
34
- property :important!
35
- end
36
-
37
- class SubclassedTest < DashTest
38
- property :last_name, required: true
39
- end
40
-
41
- class RequiredMessageTest < DashTest
42
- property :first_name, required: true, message: 'must be set.'
43
- end
44
-
45
- class DashDefaultTest < Hashie::Dash
46
- property :aliases, default: ['Snake']
47
- end
48
-
49
- class DeferredTest < Hashie::Dash
50
- property :created_at, default: proc { Time.now }
51
- end
52
-
53
- class DeferredWithSelfTest < Hashie::Dash
54
- property :created_at, default: -> { Time.now }
55
- property :updated_at, default: ->(test) { test.created_at }
56
- end
57
-
58
- describe DashTestDefaultProc do
59
- it 'as_json behaves correctly with default proc' do
60
- object = described_class.new
61
- expect(object.as_json).to be == { 'fields' => [] }
62
- end
63
- end
64
-
65
- describe DashTest do
66
- def property_required_error(property)
67
- [ArgumentError, "The property '#{property}' is required for #{subject.class.name}."]
68
- end
69
-
70
- def property_required_custom_error(property)
71
- [ArgumentError, "The property '#{property}' must be set."]
72
- end
73
-
74
- def property_message_without_required_error
75
- [ArgumentError, 'The :message option should be used with :required option.']
76
- end
77
-
78
- def no_property_error(property)
79
- [NoMethodError, "The property '#{property}' is not defined for #{subject.class.name}."]
80
- end
81
-
82
- subject { DashTest.new(first_name: 'Bob', email: 'bob@example.com') }
83
- let(:required_message) { RequiredMessageTest.new(first_name: 'Bob') }
84
-
85
- it('subclasses Hashie::Hash') { should respond_to(:to_mash) }
86
-
87
- describe '#to_s' do
88
- subject { super().to_s }
89
- it { should eq '#<DashTest count=0 email="bob@example.com" first_name="Bob">' }
90
- end
91
-
92
- it 'lists all set properties in inspect' do
93
- subject.first_name = 'Bob'
94
- subject.email = 'bob@example.com'
95
- expect(subject.inspect).to eq '#<DashTest count=0 email="bob@example.com" first_name="Bob">'
96
- end
97
-
98
- describe '#count' do
99
- subject { super().count }
100
- it { should be_zero }
101
- end
102
-
103
- it { should respond_to(:first_name) }
104
- it { should respond_to(:first_name=) }
105
- it { should_not respond_to(:nonexistent) }
106
-
107
- it 'errors out for a non-existent property' do
108
- expect { subject['nonexistent'] }.to raise_error(*no_property_error('nonexistent'))
109
- end
110
-
111
- it 'errors out when attempting to set a required property to nil' do
112
- expect { subject.first_name = nil }.to raise_error(*property_required_error('first_name'))
113
- end
114
-
115
- it 'errors out when message added to not required property' do
116
- expect do
117
- class DashMessageOptionWithoutRequiredTest < Hashie::Dash
118
- property :first_name, message: 'is required.'
119
- end
120
- end.to raise_error(*property_message_without_required_error)
121
-
122
- expect do
123
- class DashMessageOptionWithoutRequiredTest < Hashie::Dash
124
- property :first_name, required: false, message: 'is required.'
125
- end
126
- end.to raise_error(*property_message_without_required_error)
127
- end
128
-
129
- context 'writing to properties' do
130
- it 'fails writing a required property to nil' do
131
- expect { subject.first_name = nil }.to raise_error(*property_required_error('first_name'))
132
- expect { required_message.first_name = nil }.to raise_error(*property_required_custom_error('first_name'))
133
- end
134
-
135
- it 'fails writing a required property to nil using []=' do
136
- expect { subject[:first_name] = nil }.to raise_error(*property_required_error('first_name'))
137
- expect { required_message[:first_name] = nil }.to raise_error(*property_required_custom_error('first_name'))
138
- end
139
-
140
- it 'fails writing to a non-existent property using []=' do
141
- expect { subject['nonexistent'] = 123 }.to raise_error(*no_property_error('nonexistent'))
142
- end
143
-
144
- it 'works for an existing property using []=' do
145
- subject[:first_name] = 'Bob'
146
- expect(subject[:first_name]).to eq 'Bob'
147
- expect { subject['first_name'] }.to raise_error(*no_property_error('first_name'))
148
- end
149
-
150
- it 'works for an existing property using a method call' do
151
- subject.first_name = 'Franklin'
152
- expect(subject.first_name).to eq 'Franklin'
153
- end
154
- end
155
-
156
- context 'reading from properties' do
157
- it 'fails reading from a non-existent property using []' do
158
- expect { subject['nonexistent'] }.to raise_error(*no_property_error('nonexistent'))
159
- end
160
-
161
- it 'is able to retrieve properties through blocks' do
162
- subject[:first_name] = 'Aiden'
163
- value = nil
164
- subject.[](:first_name) { |v| value = v }
165
- expect(value).to eq 'Aiden'
166
- end
167
-
168
- it 'is able to retrieve properties through blocks with method calls' do
169
- subject[:first_name] = 'Frodo'
170
- value = nil
171
- subject.first_name { |v| value = v }
172
- expect(value).to eq 'Frodo'
173
- end
174
- end
175
-
176
- context 'reading from deferred properties' do
177
- it 'evaluates proc after initial read' do
178
- expect(DeferredTest.new[:created_at]).to be_instance_of(Time)
179
- end
180
-
181
- it 'does not evalute proc after subsequent reads' do
182
- deferred = DeferredTest.new
183
- expect(deferred[:created_at].object_id).to eq deferred[:created_at].object_id
184
- end
185
- end
186
-
187
- context 'reading from a deferred property based on context' do
188
- it 'provides the current hash as context for evaluation' do
189
- deferred = DeferredWithSelfTest.new
190
- expect(deferred[:created_at].object_id).to eq deferred[:created_at].object_id
191
- expect(deferred[:updated_at].object_id).to eq deferred[:created_at].object_id
192
- end
193
- end
194
-
195
- context 'converting from a Mash' do
196
- class ConvertingFromMash < Hashie::Dash
197
- property :property, required: true
198
- end
199
-
200
- context 'without keeping the original keys' do
201
- let(:mash) { Hashie::Mash.new(property: 'test') }
202
-
203
- it 'does not pick up the property from the stringified key' do
204
- expect { ConvertingFromMash.new(mash) }.to raise_error(NoMethodError)
205
- end
206
- end
207
-
208
- context 'when keeping the original keys' do
209
- class KeepingMash < Hashie::Mash
210
- include Hashie::Extensions::Mash::KeepOriginalKeys
211
- end
212
-
213
- let(:mash) { KeepingMash.new(property: 'test') }
214
-
215
- it 'picks up the property from the original key' do
216
- expect { ConvertingFromMash.new(mash) }.not_to raise_error
217
- end
218
- end
219
- end
220
-
221
- describe '#new' do
222
- it 'fails with non-existent properties' do
223
- expect { described_class.new(bork: '') }.to raise_error(*no_property_error('bork'))
224
- end
225
-
226
- it 'sets properties that it is able to' do
227
- obj = described_class.new first_name: 'Michael'
228
- expect(obj.first_name).to eq 'Michael'
229
- end
230
-
231
- it 'accepts nil' do
232
- expect { DashNoRequiredTest.new(nil) }.not_to raise_error
233
- end
234
-
235
- it 'accepts block to define a global default' do
236
- obj = described_class.new { |_, key| key.to_s.upcase }
237
- expect(obj.first_name).to eq 'FIRST_NAME'
238
- expect(obj.count).to be_zero
239
- end
240
-
241
- it 'fails when required values are missing' do
242
- expect { DashTest.new }.to raise_error(*property_required_error('first_name'))
243
- end
244
-
245
- it 'does not overwrite default values' do
246
- obj1 = DashDefaultTest.new
247
- obj1.aliases << 'El Rey'
248
- obj2 = DashDefaultTest.new
249
- expect(obj2.aliases).not_to include 'El Rey'
250
- end
251
- end
252
-
253
- describe '#merge' do
254
- it 'creates a new instance of the Dash' do
255
- new_dash = subject.merge(first_name: 'Robert')
256
- expect(subject.object_id).not_to eq new_dash.object_id
257
- end
258
-
259
- it 'merges the given hash' do
260
- new_dash = subject.merge(first_name: 'Robert', email: 'robert@example.com')
261
- expect(new_dash.first_name).to eq 'Robert'
262
- expect(new_dash.email).to eq 'robert@example.com'
263
- end
264
-
265
- it 'fails with non-existent properties' do
266
- expect { subject.merge(middle_name: 'James') }.to raise_error(*no_property_error('middle_name'))
267
- end
268
-
269
- it 'errors out when attempting to set a required property to nil' do
270
- expect { subject.merge(first_name: nil) }.to raise_error(*property_required_error('first_name'))
271
- end
272
-
273
- context 'given a block' do
274
- it "sets merged key's values to the block's return value" do
275
- expect(subject.merge(first_name: 'Jim') do |key, oldval, newval|
276
- "#{key}: #{newval} #{oldval}"
277
- end.first_name).to eq 'first_name: Jim Bob'
278
- end
279
- end
280
- end
281
-
282
- describe '#merge!' do
283
- it 'modifies the existing instance of the Dash' do
284
- original_dash = subject.merge!(first_name: 'Robert')
285
- expect(subject.object_id).to eq original_dash.object_id
286
- end
287
-
288
- it 'merges the given hash' do
289
- subject.merge!(first_name: 'Robert', email: 'robert@example.com')
290
- expect(subject.first_name).to eq 'Robert'
291
- expect(subject.email).to eq 'robert@example.com'
292
- end
293
-
294
- it 'fails with non-existent properties' do
295
- expect { subject.merge!(middle_name: 'James') }.to raise_error(NoMethodError)
296
- end
297
-
298
- it 'errors out when attempting to set a required property to nil' do
299
- expect { subject.merge!(first_name: nil) }.to raise_error(ArgumentError)
300
- end
301
-
302
- context 'given a block' do
303
- it "sets merged key's values to the block's return value" do
304
- expect(subject.merge!(first_name: 'Jim') do |key, oldval, newval|
305
- "#{key}: #{newval} #{oldval}"
306
- end.first_name).to eq 'first_name: Jim Bob'
307
- end
308
- end
309
- end
310
-
311
- describe 'properties' do
312
- it 'lists defined properties' do
313
- expect(described_class.properties).to eq Set.new([:first_name, :email, :count])
314
- end
315
-
316
- it 'checks if a property exists' do
317
- expect(described_class.property?(:first_name)).to be_truthy
318
- expect(described_class.property?('first_name')).to be_falsy
319
- end
320
-
321
- it 'checks if a property is required' do
322
- expect(described_class.required?(:first_name)).to be_truthy
323
- expect(described_class.required?('first_name')).to be_falsy
324
- end
325
-
326
- it 'doesnt include property from subclass' do
327
- expect(described_class.property?(:last_name)).to be_falsy
328
- end
329
-
330
- it 'lists declared defaults' do
331
- expect(described_class.defaults).to eq(count: 0)
332
- end
333
-
334
- it 'allows properties that end in bang' do
335
- expect(PropertyBangTest.property?(:important!)).to be_truthy
336
- end
337
- end
338
-
339
- describe '#replace' do
340
- before { subject.replace(first_name: 'Cain') }
341
-
342
- it 'return self' do
343
- expect(subject.replace(email: 'bar').to_hash).to eq(email: 'bar', count: 0)
344
- end
345
-
346
- it 'sets all specified keys to their corresponding values' do
347
- expect(subject.first_name).to eq 'Cain'
348
- end
349
-
350
- it 'leaves only specified keys and keys with default values' do
351
- expect(subject.keys.sort_by(&:to_s)).to eq [:count, :first_name]
352
- expect(subject.email).to be_nil
353
- expect(subject.count).to eq 0
354
- end
355
-
356
- context 'when replacing keys with default values' do
357
- before { subject.replace(count: 3) }
358
-
359
- it 'sets all specified keys to their corresponding values' do
360
- expect(subject.count).to eq 3
361
- end
362
- end
363
- end
364
-
365
- describe '#update_attributes!(params)' do
366
- let(:params) { { first_name: 'Alice', email: 'alice@example.com' } }
367
-
368
- context 'when there is coercion' do
369
- let(:params_before) { { city: 'nyc', person: { first_name: 'Bob', email: 'bob@example.com' } } }
370
- let(:params_after) { { city: 'sfo', person: { first_name: 'Alice', email: 'alice@example.com' } } }
371
-
372
- subject { DashWithCoercion.new(params_before) }
373
-
374
- it 'update the attributes' do
375
- expect(subject.person.first_name).to eq params_before[:person][:first_name]
376
- subject.update_attributes!(params_after)
377
- expect(subject.person.first_name).to eq params_after[:person][:first_name]
378
- end
379
- end
380
-
381
- it 'update the attributes' do
382
- subject.update_attributes!(params)
383
- expect(subject.first_name).to eq params[:first_name]
384
- expect(subject.email).to eq params[:email]
385
- expect(subject.count).to eq subject.class.defaults[:count]
386
- end
387
-
388
- context 'when required property is update to nil' do
389
- let(:params) { { first_name: nil, email: 'alice@example.com' } }
390
-
391
- it 'raise an ArgumentError' do
392
- expect { subject.update_attributes!(params) }.to raise_error(ArgumentError)
393
- end
394
- end
395
-
396
- context 'when a default property is update to nil' do
397
- let(:params) { { count: nil, email: 'alice@example.com' } }
398
-
399
- it 'set the property back to the default value' do
400
- subject.update_attributes!(params)
401
- expect(subject.email).to eq params[:email]
402
- expect(subject.count).to eq subject.class.defaults[:count]
403
- end
404
- end
405
- end
406
- end
407
-
408
- describe Hashie::Dash, 'inheritance' do
409
- before do
410
- @top = Class.new(Hashie::Dash)
411
- @middle = Class.new(@top)
412
- @bottom = Class.new(@middle)
413
- end
414
-
415
- it 'reports empty properties when nothing defined' do
416
- expect(@top.properties).to be_empty
417
- expect(@top.defaults).to be_empty
418
- end
419
-
420
- it 'inherits properties downwards' do
421
- @top.property :echo
422
- expect(@middle.properties).to include(:echo)
423
- expect(@bottom.properties).to include(:echo)
424
- end
425
-
426
- it 'doesnt inherit properties upwards' do
427
- @middle.property :echo
428
- expect(@top.properties).not_to include(:echo)
429
- expect(@bottom.properties).to include(:echo)
430
- end
431
-
432
- it 'allows overriding a default on an existing property' do
433
- @top.property :echo
434
- @middle.property :echo, default: 123
435
- expect(@bottom.properties.to_a).to eq [:echo]
436
- expect(@bottom.new.echo).to eq 123
437
- end
438
-
439
- it 'allows clearing an existing default' do
440
- @top.property :echo
441
- @middle.property :echo, default: 123
442
- @bottom.property :echo
443
- expect(@bottom.properties.to_a).to eq [:echo]
444
- expect(@bottom.new.echo).to be_nil
445
- end
446
-
447
- it 'allows nil defaults' do
448
- @bottom.property :echo, default: nil
449
- expect(@bottom.new).to have_key(:echo)
450
- expect(@bottom.new).to_not have_key('echo')
451
- end
452
- end
453
-
454
- describe SubclassedTest do
455
- subject { SubclassedTest.new(first_name: 'Bob', last_name: 'McNob', email: 'bob@example.com') }
456
-
457
- describe '#count' do
458
- subject { super().count }
459
- it { should be_zero }
460
- end
461
-
462
- it { should respond_to(:first_name) }
463
- it { should respond_to(:first_name=) }
464
- it { should respond_to(:last_name) }
465
- it { should respond_to(:last_name=) }
466
-
467
- it 'has one additional property' do
468
- expect(described_class.property?(:last_name)).to be_truthy
469
- end
470
-
471
- it "didn't override superclass inheritance logic" do
472
- expect(described_class.instance_variable_get('@inheritance_test')).to be_truthy
473
- end
474
- end
475
-
476
- class ConditionallyRequiredTest < Hashie::Dash
477
- property :username
478
- property :password, required: -> { !username.nil? }, message: 'must be set, too.'
479
- end
480
-
481
- describe ConditionallyRequiredTest do
482
- it 'does not allow a conditionally required property to be set to nil if required' do
483
- expect { ConditionallyRequiredTest.new(username: 'bob.smith', password: nil) }.to raise_error(ArgumentError, "The property 'password' must be set, too.")
484
- end
485
-
486
- it 'allows a conditionally required property to be set to nil if not required' do
487
- expect { ConditionallyRequiredTest.new(username: nil, password: nil) }.not_to raise_error
488
- end
489
-
490
- it 'allows a conditionally required property to be set if required' do
491
- expect { ConditionallyRequiredTest.new(username: 'bob.smith', password: '$ecure!') }.not_to raise_error
492
- end
493
- end
494
-
495
- class MixedPropertiesTest < Hashie::Dash
496
- property :symbol
497
- property 'string'
498
- end
499
-
500
- describe MixedPropertiesTest do
501
- subject { MixedPropertiesTest.new('string' => 'string', symbol: 'symbol') }
502
-
503
- it { should respond_to('string') }
504
- it { should respond_to(:symbol) }
505
-
506
- it 'property?' do
507
- expect(described_class.property?('string')).to be_truthy
508
- expect(described_class.property?(:symbol)).to be_truthy
509
- end
510
-
511
- it 'fetch' do
512
- expect(subject['string']).to eq('string')
513
- expect { subject[:string] }.to raise_error(NoMethodError)
514
- expect(subject[:symbol]).to eq('symbol')
515
- expect { subject['symbol'] }.to raise_error(NoMethodError)
516
- end
517
-
518
- it 'double define' do
519
- klass = Class.new(MixedPropertiesTest) do
520
- property 'symbol'
521
- end
522
- instance = klass.new(symbol: 'one', 'symbol' => 'two')
523
- expect(instance[:symbol]).to eq('one')
524
- expect(instance['symbol']).to eq('two')
525
- end
526
-
527
- it 'assign' do
528
- subject['string'] = 'updated'
529
- expect(subject['string']).to eq('updated')
530
-
531
- expect { subject[:string] = 'updated' }.to raise_error(NoMethodError)
532
-
533
- subject[:symbol] = 'updated'
534
- expect(subject[:symbol]).to eq('updated')
535
-
536
- expect { subject['symbol'] = 'updated' }.to raise_error(NoMethodError)
537
- end
538
- end
539
-
540
- context 'Dynamic Dash Class' do
541
- it 'define property' do
542
- klass = Class.new(Hashie::Dash)
543
- my_property = 'my_property'
544
- my_orig = my_property.dup
545
-
546
- klass.property(my_property)
547
-
548
- expect(my_property).to eq(my_orig)
549
- end
550
- end
551
-
552
- context 'with method access' do
553
- class DashWithMethodAccess < Hashie::Dash
554
- include Hashie::Extensions::IndifferentAccess
555
- include Hashie::Extensions::MethodQuery
556
-
557
- property :test
558
- end
559
-
560
- subject(:dash) { DashWithMethodAccess.new(test: 'value') }
561
-
562
- describe '#test' do
563
- subject { dash.test }
564
-
565
- it { is_expected.to eq('value') }
566
- end
567
-
568
- describe '#test?' do
569
- subject { dash.test? }
570
-
571
- it { is_expected.to eq true }
572
- end
573
- end
@@ -1,24 +0,0 @@
1
- require 'spec_helper'
2
- require 'hashie'
3
-
4
- describe Hashie::Extensions do
5
- describe 'autloads constants' do
6
- it { is_expected.to be_const_defined(:MethodAccess) }
7
- it { is_expected.to be_const_defined(:Coercion) }
8
- it { is_expected.to be_const_defined(:DeepMerge) }
9
- it { is_expected.to be_const_defined(:IgnoreUndeclared) }
10
- it { is_expected.to be_const_defined(:IndifferentAccess) }
11
- it { is_expected.to be_const_defined(:MergeInitializer) }
12
- it { is_expected.to be_const_defined(:MethodAccess) }
13
- it { is_expected.to be_const_defined(:MethodQuery) }
14
- it { is_expected.to be_const_defined(:MethodReader) }
15
- it { is_expected.to be_const_defined(:MethodWriter) }
16
- it { is_expected.to be_const_defined(:StringifyKeys) }
17
- it { is_expected.to be_const_defined(:SymbolizeKeys) }
18
- it { is_expected.to be_const_defined(:DeepFetch) }
19
- it { is_expected.to be_const_defined(:DeepFind) }
20
- it { is_expected.to be_const_defined(:PrettyInspect) }
21
- it { is_expected.to be_const_defined(:KeyConversion) }
22
- it { is_expected.to be_const_defined(:MethodAccessWithOverride) }
23
- end
24
- end