activerecord_hstore_boolean 0.0.2 → 0.0.3
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 070fab65620353977cb8c0d3202a27e3707c4ea7
|
4
|
+
data.tar.gz: 38dd0430a3f10575d10dd5dfbc439704f3ef905a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cced38428ed113357f87d96e8e21264dfd667edf5d36ef6a8c612477bcb2dc8dfc8df22e4d6ecacd6da605f6ea2ef4d9c81c371c0092e9d80347621f0de70f7d
|
7
|
+
data.tar.gz: 87a2bb45a463e67b489c0071546f4018470763020707c502f7e9c702cf4d96937ebac1c4aa4355f98ff24939dce4163e34098d84b1b934d83400e2b166d13823
|
@@ -9,18 +9,18 @@ module ActiverecordHstoreBoolean
|
|
9
9
|
|
10
10
|
module ClassMethods
|
11
11
|
def hstore_boolean_values(attr_name, *keys)
|
12
|
-
keys.map!(&:
|
12
|
+
keys.map!(&:to_s)
|
13
13
|
before_save "normalize_#{attr_name}_boolean_values"
|
14
14
|
|
15
15
|
define_method("normalize_#{attr_name}_boolean_values") do
|
16
|
-
self[attr_name].
|
17
|
-
self[attr_name][key] = TRUE_VALUES.include?(value) ? STORED_TRUE_VALUE : STORED_FALSE_VALUE if keys.include?(key)
|
16
|
+
self[attr_name].each do |key, value|
|
17
|
+
self[attr_name][key] = TRUE_VALUES.include?(value) ? STORED_TRUE_VALUE : STORED_FALSE_VALUE if keys.include?(key.to_s)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
define_method(attr_name) do
|
22
|
-
self[attr_name].
|
23
|
-
self[attr_name][key] = value == STORED_TRUE_VALUE if keys.include?(key)
|
22
|
+
self[attr_name].each do |key, value|
|
23
|
+
self[attr_name][key] = value == STORED_TRUE_VALUE if keys.include?(key.to_s)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -9,8 +9,8 @@ describe ActiverecordHstoreBoolean do
|
|
9
9
|
it 'normalize true value' do
|
10
10
|
product = Product.create(properties: { popular: true_value, color: 'white' })
|
11
11
|
product.reload
|
12
|
-
expect(product.properties[
|
13
|
-
expect(product.properties[
|
12
|
+
expect(product.properties['popular']).to be_true
|
13
|
+
expect(product.properties['color']).to eq 'white'
|
14
14
|
end
|
15
15
|
|
16
16
|
end
|
@@ -18,7 +18,7 @@ describe ActiverecordHstoreBoolean do
|
|
18
18
|
it 'normalize falue value' do
|
19
19
|
product = Product.create(properties: { popular: 'false', color: 'white' })
|
20
20
|
product.reload
|
21
|
-
expect(product.properties[
|
22
|
-
expect(product.properties[
|
21
|
+
expect(product.properties['popular']).to be_false
|
22
|
+
expect(product.properties['color']).to eq 'white'
|
23
23
|
end
|
24
24
|
end
|