validates_serialized 0.0.5 → 0.0.6
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 +8 -8
- data/Gemfile.lock +1 -1
- data/lib/validates_serialized/validateable_array_value.rb +2 -10
- data/lib/validates_serialized/validateable_hash.rb +6 -7
- data/lib/validates_serialized/validateable_object.rb +1 -0
- data/lib/validates_serialized/version.rb +1 -1
- data/lib/validates_serialized.rb +1 -1
- data/spec/acceptance_spec.rb +2 -2
- data/spec/validateable_array_value_spec.rb +12 -2
- data/spec/validateable_hash_spec.rb +8 -0
- data/spec/validateable_object_spec.rb +9 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MGQ0NGRmZWEwNjRkNTRkZmE1MTE2NTE5YjlmZDliMTc5MjZhY2M2NA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NGUzM2I0YTU2MDkyNTIxNDE4N2VjOGE1ZmQ4YTliNWIzYmNiNzg5Yg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MWZjMmRjMDE0MDRkN2U4NmUzNjVhYjRmMzk2NmJiNWYxY2I4NmFlMWU4NGZm
|
10
|
+
MzQxZjYxMzkzZTJlODkxZmJhOTBjMTFiZGExY2VhYTRkYjliY2ViNzZlOWJm
|
11
|
+
NTY1N2M3ODkxMGI4MzRhZjEzMDQzN2IzN2UzM2ZjNzY2YjNkMmU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZDkyMGQyNWI5NTQ5Y2M3NGU2MjJiMjU3Y2IyOTcxYzcxOGNjYjhkYTNiYjJj
|
14
|
+
ZmYzZWRhMTAwMGI5NTc2YTAxZTQ1YWYzY2JmMTQ1NjA5NDY5NjlhODAxNzNh
|
15
|
+
OGFiYTg1MWJjZjM1ZWM1Njc4ZTk5NDcxOWY3NjExMzU4ZmJlY2Q=
|
data/Gemfile.lock
CHANGED
@@ -1,17 +1,9 @@
|
|
1
1
|
require 'active_model'
|
2
2
|
|
3
|
-
class ValidateableArrayValue
|
3
|
+
class ValidateableArrayValue < ValidateableObject
|
4
4
|
include ::ActiveModel::Validations
|
5
5
|
|
6
|
-
def initialize(value)
|
7
|
-
@value = value
|
8
|
-
end
|
9
|
-
|
10
6
|
def value
|
11
|
-
@
|
12
|
-
end
|
13
|
-
|
14
|
-
def method_missing(sym, *args, &block)
|
15
|
-
@value.send sym, *args, &block
|
7
|
+
@object
|
16
8
|
end
|
17
9
|
end
|
@@ -1,15 +1,14 @@
|
|
1
1
|
require 'active_model'
|
2
2
|
|
3
|
-
class ValidateableHash <
|
3
|
+
class ValidateableHash < ValidateableObject
|
4
4
|
include ::ActiveModel::Validations
|
5
5
|
|
6
|
-
def initialize(hash)
|
7
|
-
@hash = hash
|
8
|
-
end
|
9
|
-
|
10
6
|
private
|
11
7
|
def method_missing(method, *args, &block)
|
12
|
-
|
13
|
-
|
8
|
+
if @object.keys.include?(method)
|
9
|
+
@object[method]
|
10
|
+
else
|
11
|
+
super
|
12
|
+
end
|
14
13
|
end
|
15
14
|
end
|
data/lib/validates_serialized.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'validates_serialized/version'
|
2
|
+
require 'validates_serialized/validateable_object'
|
2
3
|
require 'validates_serialized/validateable_array_value'
|
3
4
|
require 'validates_serialized/validateable_hash'
|
4
|
-
require 'validates_serialized/validateable_object'
|
5
5
|
require 'validates_serialized/each_validator'
|
6
6
|
require 'validates_serialized/validators/serialized_validator'
|
7
7
|
require 'validates_serialized/validators/array_validator'
|
data/spec/acceptance_spec.rb
CHANGED
@@ -103,9 +103,9 @@ describe ValidatesSerialized do
|
|
103
103
|
model.should be_valid
|
104
104
|
end
|
105
105
|
|
106
|
-
it "
|
106
|
+
it "is invalid without Serialized author" do
|
107
107
|
model = Blog.new(ratings: [1, 3, 1], comments: { admin: "This is great!" })
|
108
|
-
|
108
|
+
model.should_not be_valid
|
109
109
|
end
|
110
110
|
|
111
111
|
it "is invalid without author name" do
|
@@ -14,7 +14,17 @@ describe ValidateableArrayValue do
|
|
14
14
|
subject.errors.should be_empty
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
|
17
|
+
describe "delegating attributes" do
|
18
|
+
it "returns itself on :value method" do
|
19
|
+
subject.value.should eq(1)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "delegates object methods without error" do
|
23
|
+
expect { subject.object_id }.not_to raise_error
|
24
|
+
end
|
25
|
+
|
26
|
+
it "does not raise error for non-existent methods" do
|
27
|
+
expect { subject.arglebargle }.not_to raise_error
|
28
|
+
end
|
19
29
|
end
|
20
30
|
end
|
@@ -25,6 +25,14 @@ describe ValidateableHash do
|
|
25
25
|
it "returns nil for non-existent key_3" do
|
26
26
|
subject.key_3.should be_nil
|
27
27
|
end
|
28
|
+
|
29
|
+
it "delegates object methods without error" do
|
30
|
+
expect { subject.object_id }.not_to raise_error
|
31
|
+
end
|
32
|
+
|
33
|
+
it "does not raises error for non-existent methods" do
|
34
|
+
expect { subject.arglebargle }.not_to raise_error
|
35
|
+
end
|
28
36
|
end
|
29
37
|
|
30
38
|
describe "validation block" do
|
@@ -43,6 +43,14 @@ describe ValidateableObject do
|
|
43
43
|
it "delegates name attribute" do
|
44
44
|
subject.name.should eq("Thomas")
|
45
45
|
end
|
46
|
+
|
47
|
+
it "delegates object methods without error" do
|
48
|
+
expect { subject.object_id }.not_to raise_error
|
49
|
+
end
|
50
|
+
|
51
|
+
it "does not raise error for non-existent methods" do
|
52
|
+
expect { subject.arglebargle }.not_to raise_error
|
53
|
+
end
|
46
54
|
end
|
47
55
|
|
48
56
|
describe "validation block" do
|
@@ -66,7 +74,7 @@ describe ValidateableObject do
|
|
66
74
|
subject.class_eval do
|
67
75
|
validates :other_property, inclusion: { in: [ 'a', 'b', 'c' ] }
|
68
76
|
end
|
69
|
-
expect { subject.valid? }.
|
77
|
+
expect { subject.valid? }.not_to raise_error
|
70
78
|
end
|
71
79
|
end
|
72
80
|
end
|