hashie 2.1.0 → 2.1.1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/lib/hashie/hash.rb +13 -3
- data/lib/hashie/version.rb +1 -1
- data/spec/hashie/clash_spec.rb +11 -11
- data/spec/hashie/dash_spec.rb +69 -60
- data/spec/hashie/extensions/coercion_spec.rb +22 -22
- data/spec/hashie/extensions/deep_fetch_spec.rb +7 -7
- data/spec/hashie/extensions/deep_merge_spec.rb +2 -2
- data/spec/hashie/extensions/indifferent_access_spec.rb +24 -24
- data/spec/hashie/extensions/key_conversion_spec.rb +14 -14
- data/spec/hashie/extensions/merge_initializer_spec.rb +4 -4
- data/spec/hashie/extensions/method_access_spec.rb +22 -22
- data/spec/hashie/hash_spec.rb +19 -7
- data/spec/hashie/mash_spec.rb +122 -123
- data/spec/hashie/rash_spec.rb +13 -13
- data/spec/hashie/trash_spec.rb +30 -30
- data/spec/hashie/version_spec.rb +1 -1
- metadata +2 -2
data/spec/hashie/trash_spec.rb
CHANGED
@@ -9,35 +9,35 @@ describe Hashie::Trash do
|
|
9
9
|
|
10
10
|
describe 'translating properties' do
|
11
11
|
it 'adds the property to the list' do
|
12
|
-
TrashTest.properties.
|
12
|
+
expect(TrashTest.properties).to include(:first_name)
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'creates a method for reading the property' do
|
16
|
-
trash.
|
16
|
+
expect(trash).to respond_to(:first_name)
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'creates a method for writing the property' do
|
20
|
-
trash.
|
20
|
+
expect(trash).to respond_to(:first_name=)
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'creates a method for writing the translated property' do
|
24
|
-
trash.
|
24
|
+
expect(trash).to respond_to(:firstName=)
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'does not create a method for reading the translated property' do
|
28
|
-
trash.
|
28
|
+
expect(trash).not_to respond_to(:firstName)
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'maintains translations hash mapping from the original to the translated name' do
|
32
|
-
TrashTest.translations[:firstName].
|
32
|
+
expect(TrashTest.translations[:firstName]).to eq :first_name
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'maintains inverse translations hash mapping from the translated to the original name' do
|
36
|
-
TrashTest.inverse_translations[:first_name].
|
36
|
+
expect(TrashTest.inverse_translations[:first_name]).to eq :firstName
|
37
37
|
end
|
38
38
|
|
39
39
|
it '#permitted_input_keys contain the :from key of properties with translations' do
|
40
|
-
TrashTest.permitted_input_keys.
|
40
|
+
expect(TrashTest.permitted_input_keys).to include :firstName
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
@@ -47,61 +47,61 @@ describe Hashie::Trash do
|
|
47
47
|
end
|
48
48
|
|
49
49
|
it '#permitted_input_keys contain names of properties without translations' do
|
50
|
-
TrashTestPermitted.permitted_input_keys.
|
50
|
+
expect(TrashTestPermitted.permitted_input_keys).to include :id
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
54
|
describe 'writing to properties' do
|
55
55
|
it 'does not write to a non-existent property using []=' do
|
56
|
-
|
56
|
+
expect { trash['abc'] = 123 }.to raise_error(NoMethodError)
|
57
57
|
end
|
58
58
|
|
59
59
|
it 'writes to an existing property using []=' do
|
60
|
-
|
60
|
+
expect { trash['first_name'] = 'Bob' }.not_to raise_error
|
61
61
|
end
|
62
62
|
|
63
63
|
it 'writes to a translated property using []=' do
|
64
|
-
|
64
|
+
expect { trash['firstName'] = 'Bob' }.not_to raise_error
|
65
65
|
end
|
66
66
|
|
67
67
|
it 'reads/writes to an existing property using a method call' do
|
68
68
|
trash.first_name = 'Franklin'
|
69
|
-
trash.first_name.
|
69
|
+
expect(trash.first_name).to eq 'Franklin'
|
70
70
|
end
|
71
71
|
|
72
72
|
it 'writes to an translated property using a method call' do
|
73
73
|
trash.firstName = 'Franklin'
|
74
|
-
trash.first_name.
|
74
|
+
expect(trash.first_name).to eq 'Franklin'
|
75
75
|
end
|
76
76
|
|
77
77
|
it 'writes to a translated property using #replace' do
|
78
78
|
trash.replace(firstName: 'Franklin')
|
79
|
-
trash.first_name.
|
79
|
+
expect(trash.first_name).to eq 'Franklin'
|
80
80
|
end
|
81
81
|
|
82
82
|
it 'writes to a non-translated property using #replace' do
|
83
83
|
trash.replace(first_name: 'Franklin')
|
84
|
-
trash.first_name.
|
84
|
+
expect(trash.first_name).to eq 'Franklin'
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
88
|
describe ' initializing with a Hash' do
|
89
89
|
it 'does not initialize non-existent properties' do
|
90
|
-
|
90
|
+
expect { TrashTest.new(bork: 'abc') }.to raise_error(NoMethodError)
|
91
91
|
end
|
92
92
|
|
93
93
|
it 'sets the desired properties' do
|
94
|
-
TrashTest.new(first_name: 'Michael').first_name.
|
94
|
+
expect(TrashTest.new(first_name: 'Michael').first_name).to eq 'Michael'
|
95
95
|
end
|
96
96
|
|
97
97
|
context 'with both the translated property and the property' do
|
98
98
|
it 'sets the desired properties' do
|
99
|
-
TrashTest.new(first_name: 'Michael', firstName: 'Maeve').first_name.
|
99
|
+
expect(TrashTest.new(first_name: 'Michael', firstName: 'Maeve').first_name).to eq 'Michael'
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
103
103
|
it 'sets the translated properties' do
|
104
|
-
TrashTest.new(firstName: 'Michael').first_name.
|
104
|
+
expect(TrashTest.new(firstName: 'Michael').first_name).to eq 'Michael'
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
@@ -113,21 +113,21 @@ describe Hashie::Trash do
|
|
113
113
|
let(:lambda_trash) { TrashLambdaTest.new }
|
114
114
|
|
115
115
|
it 'translates the value given on initialization with the given lambda' do
|
116
|
-
TrashLambdaTest.new(firstName: 'Michael').first_name.
|
116
|
+
expect(TrashLambdaTest.new(firstName: 'Michael').first_name).to eq 'Michael'.reverse
|
117
117
|
end
|
118
118
|
|
119
119
|
it 'does not translate the value if given with the right property' do
|
120
|
-
TrashTest.new(first_name: 'Michael').first_name.
|
120
|
+
expect(TrashTest.new(first_name: 'Michael').first_name).to eq 'Michael'
|
121
121
|
end
|
122
122
|
|
123
123
|
it 'translates the value given as property with the given lambda' do
|
124
124
|
lambda_trash.firstName = 'Michael'
|
125
|
-
lambda_trash.first_name.
|
125
|
+
expect(lambda_trash.first_name).to eq 'Michael'.reverse
|
126
126
|
end
|
127
127
|
|
128
128
|
it 'does not translate the value given as right property' do
|
129
129
|
lambda_trash.first_name = 'Michael'
|
130
|
-
lambda_trash.first_name.
|
130
|
+
expect(lambda_trash.first_name).to eq 'Michael'
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
@@ -140,12 +140,12 @@ describe Hashie::Trash do
|
|
140
140
|
|
141
141
|
it 'translates the value given as property with the given lambda' do
|
142
142
|
lambda_trash.firstName = 'Michael'
|
143
|
-
lambda_trash.first_name.
|
143
|
+
expect(lambda_trash.first_name).to eq 'Michael'.reverse
|
144
144
|
end
|
145
145
|
|
146
146
|
it 'does not translate the value given as right property' do
|
147
147
|
lambda_trash.first_name = 'Michael'
|
148
|
-
lambda_trash.first_name.
|
148
|
+
expect(lambda_trash.first_name).to eq 'Michael'
|
149
149
|
end
|
150
150
|
end
|
151
151
|
|
@@ -158,11 +158,11 @@ describe Hashie::Trash do
|
|
158
158
|
|
159
159
|
it 'translates the value given as property with the given lambda' do
|
160
160
|
lambda_trash.first_name = 'Michael'
|
161
|
-
lambda_trash.first_name.
|
161
|
+
expect(lambda_trash.first_name).to eq 'Michael'.reverse
|
162
162
|
end
|
163
163
|
|
164
164
|
it 'transforms the value when given in constructor' do
|
165
|
-
TrashLambdaTestWithProperties.new(first_name: 'Michael').first_name.
|
165
|
+
expect(TrashLambdaTestWithProperties.new(first_name: 'Michael').first_name).to eq 'Michael'.reverse
|
166
166
|
end
|
167
167
|
|
168
168
|
context 'when :from option is given' do
|
@@ -171,13 +171,13 @@ describe Hashie::Trash do
|
|
171
171
|
end
|
172
172
|
|
173
173
|
it 'does not override the :from option in the constructor' do
|
174
|
-
TrashLambdaTest3.new(first_name: 'Michael').first_name.
|
174
|
+
expect(TrashLambdaTest3.new(first_name: 'Michael').first_name).to eq 'Michael'
|
175
175
|
end
|
176
176
|
|
177
177
|
it 'does not override the :from option when given as property' do
|
178
178
|
t = TrashLambdaTest3.new
|
179
179
|
t.first_name = 'Michael'
|
180
|
-
t.first_name.
|
180
|
+
expect(t.first_name).to eq 'Michael'
|
181
181
|
end
|
182
182
|
|
183
183
|
end
|
data/spec/hashie/version_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hashie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Bleigh
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-04-
|
12
|
+
date: 2014-04-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|