hashme 0.2.2 → 0.2.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 +4 -4
- data/README.md +5 -1
- data/lib/hashme/casted_array.rb +1 -1
- data/lib/hashme/validations/casted_attribute_validator.rb +2 -1
- data/lib/hashme/version.rb +1 -1
- data/spec/hashme/validations_spec.rb +9 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eeb34cad001a9e72ba6e9bd7a7f1ea26df382bc0
|
4
|
+
data.tar.gz: 84add3cad188a7a7ef18966416a1a5e5bbd96230
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3169335c642413fc0ab103c962419e2c3c2ae6bd5202a5aae0cd8995b86fe23df891bc39ec0be59f7475321b0160697c0297a353c249c1769905f335c9ec31d4
|
7
|
+
data.tar.gz: 57d07bc8e59fad1f67315c2276d654a371c76076699140f65c8edd971f7458e298032f228704b291063a042b91bb425570c7d59b2bc5e452a5d3340d2077500f
|
data/README.md
CHANGED
@@ -118,7 +118,11 @@ u.errors.first # [:email, "can't be blank"]
|
|
118
118
|
|
119
119
|
## History
|
120
120
|
|
121
|
-
### 0.2.
|
121
|
+
### 0.2.3 - 2016-06-03
|
122
|
+
|
123
|
+
* Fixing bug with validation on CastedArrays
|
124
|
+
|
125
|
+
### 0.2.2 - 2016-06-03
|
122
126
|
|
123
127
|
* Removing support for setting attributes without a property.
|
124
128
|
* Adding a `attributes=` method.
|
data/lib/hashme/casted_array.rb
CHANGED
@@ -15,7 +15,7 @@ module Hashme
|
|
15
15
|
def_delegators :@_array,
|
16
16
|
:to_a, :==, :eql?, :size,
|
17
17
|
:first, :last, :at, :length,
|
18
|
-
:each, :reject, :empty?, :map,
|
18
|
+
:each, :reject, :empty?, :map, :collect,
|
19
19
|
:clear, :pop, :shift, :delete, :delete_at,
|
20
20
|
:encode_json, :as_json, :to_json,
|
21
21
|
:inspect, :any?
|
@@ -3,7 +3,8 @@ module Hashme
|
|
3
3
|
class CastedAttributeValidator < ActiveModel::EachValidator
|
4
4
|
|
5
5
|
def validate_each(document, attribute, value)
|
6
|
-
|
6
|
+
is_array = value.is_a?(Array) || value.is_a?(CastedArray)
|
7
|
+
values = is_array ? value : [value]
|
7
8
|
return if values.collect {|attr| attr.nil? || attr.valid? }.all?
|
8
9
|
document.errors.add(attribute)
|
9
10
|
end
|
data/lib/hashme/version.rb
CHANGED
@@ -37,6 +37,7 @@ describe Hashme::Validations do
|
|
37
37
|
include Hashme
|
38
38
|
def self.name; "Example"; end
|
39
39
|
property :sub, submod
|
40
|
+
property :subs, [submod]
|
40
41
|
end
|
41
42
|
end
|
42
43
|
|
@@ -58,6 +59,14 @@ describe Hashme::Validations do
|
|
58
59
|
expect(obj.sub.errors[:email]).to_not be_empty
|
59
60
|
end
|
60
61
|
|
62
|
+
it "should valid attributes with casted array" do
|
63
|
+
obj = subject.new(subs: [{}])
|
64
|
+
expect(obj).to_not be_valid
|
65
|
+
expect(obj.errors[:subs]).to_not be_empty
|
66
|
+
expect(obj.subs.first.errors).to_not be_empty
|
67
|
+
expect(obj.subs.first.errors[:email]).to_not be_empty
|
68
|
+
end
|
69
|
+
|
61
70
|
end
|
62
71
|
|
63
72
|
end
|