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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YjIwMjgyMDM4ZmYzODU0NzdiMzhlYjc2MTFhNDkyMzNkYzc3NzBhNA==
4
+ MGQ0NGRmZWEwNjRkNTRkZmE1MTE2NTE5YjlmZDliMTc5MjZhY2M2NA==
5
5
  data.tar.gz: !binary |-
6
- ZjBjODhhN2NmMjM0Mzc2MDMyZjg0MTVlMzNiZGEwMjA4MzVmMjM3Yg==
6
+ NGUzM2I0YTU2MDkyNTIxNDE4N2VjOGE1ZmQ4YTliNWIzYmNiNzg5Yg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NmE0NzU3YzY1YTZiMGI1ZTkwNmRkZDcxYTVjZTc2NzkxNjE0OTAwNGZkMThm
10
- ZmZhOTFhOWU3YmQ2ZTVkOGVkZGUxZTg2MTc3MmY3OTIwZmU5ZjJkYzg4ZDdl
11
- OTZlOWU3MjRhNzBhNmI3MWQwZmUyYzE4M2U2MDhjMGNjMWU3OGU=
9
+ MWZjMmRjMDE0MDRkN2U4NmUzNjVhYjRmMzk2NmJiNWYxY2I4NmFlMWU4NGZm
10
+ MzQxZjYxMzkzZTJlODkxZmJhOTBjMTFiZGExY2VhYTRkYjliY2ViNzZlOWJm
11
+ NTY1N2M3ODkxMGI4MzRhZjEzMDQzN2IzN2UzM2ZjNzY2YjNkMmU=
12
12
  data.tar.gz: !binary |-
13
- NmQxNGNiYTU1OGUxNTQ2ZjQzODVjZTExNWI2ZDc2YWRkODBmNzA1OWEyZWI5
14
- NTk1Y2Y5NjRjMTI1MjA2NzE3Y2IyMzA5NmE2NWViMTA4NTUxMTRiZDVkMzNh
15
- ZDhiZTkyYzg1ODM4NjRhNDAzOTM2OWQ1MmQ5ZmMwZThjN2M3MmQ=
13
+ ZDkyMGQyNWI5NTQ5Y2M3NGU2MjJiMjU3Y2IyOTcxYzcxOGNjYjhkYTNiYjJj
14
+ ZmYzZWRhMTAwMGI5NTc2YTAxZTQ1YWYzY2JmMTQ1NjA5NDY5NjlhODAxNzNh
15
+ OGFiYTg1MWJjZjM1ZWM1Njc4ZTk5NDcxOWY3NjExMzU4ZmJlY2Q=
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- validates_serialized (0.0.3)
4
+ validates_serialized (0.0.5)
5
5
  activemodel (>= 3.0, < 5.0)
6
6
 
7
7
  GEM
@@ -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
- @value
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 < Hash
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
- # Delegate all methods to access the hash
13
- @hash[method]
8
+ if @object.keys.include?(method)
9
+ @object[method]
10
+ else
11
+ super
12
+ end
14
13
  end
15
14
  end
@@ -10,5 +10,6 @@ class ValidateableObject
10
10
  private
11
11
  def method_missing(method, *args, &block)
12
12
  @object.send(method, *args, &block)
13
+ rescue NoMethodError => e
13
14
  end
14
15
  end
@@ -1,3 +1,3 @@
1
1
  module ValidatesSerialized
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -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'
@@ -103,9 +103,9 @@ describe ValidatesSerialized do
103
103
  model.should be_valid
104
104
  end
105
105
 
106
- it "raises error without Serialized author" do
106
+ it "is invalid without Serialized author" do
107
107
  model = Blog.new(ratings: [1, 3, 1], comments: { admin: "This is great!" })
108
- expect { model.valid? }.to raise_error
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
- it "returns itself on :value method" do
18
- subject.value.should eq(1)
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? }.to raise_error(NoMethodError)
77
+ expect { subject.valid? }.not_to raise_error
70
78
  end
71
79
  end
72
80
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validates_serialized
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - brycesenz