validates_serialized 0.0.1.pre2
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 +15 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +46 -0
- data/README.md +151 -0
- data/lib/validates_serialized/each_validator.rb +20 -0
- data/lib/validates_serialized/validateable_array.rb +9 -0
- data/lib/validates_serialized/validateable_hash.rb +15 -0
- data/lib/validates_serialized/validateable_object.rb +14 -0
- data/lib/validates_serialized/validators/array_validator.rb +78 -0
- data/lib/validates_serialized/validators/hash_block_validator.rb +59 -0
- data/lib/validates_serialized/validators/hash_validator.rb +75 -0
- data/lib/validates_serialized/validators/object_block_validator.rb +58 -0
- data/lib/validates_serialized/validators/serialized_validator.rb +73 -0
- data/lib/validates_serialized/version.rb +3 -0
- data/lib/validates_serialized.rb +10 -0
- data/notes.md +5 -0
- data/spec/acceptance_spec.rb +95 -0
- data/spec/each_validator_spec.rb +47 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/validateable_array_spec.rb +15 -0
- data/spec/validateable_hash_spec.rb +54 -0
- data/spec/validateable_object_spec.rb +72 -0
- data/spec/validators/array_validator_spec.rb +182 -0
- data/spec/validators/hash_block_validator_spec.rb +98 -0
- data/spec/validators/hash_validator_spec.rb +183 -0
- data/spec/validators/object_block_validator_spec.rb +110 -0
- data/validates_serialized.gemspec +26 -0
- metadata +154 -0
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
describe ActiveModel::Validations::ObjectBlockValidator do
|
5
|
+
class Foo
|
6
|
+
def initialize(h={})
|
7
|
+
h.each {|k,v| send("#{k}=",v)}
|
8
|
+
end
|
9
|
+
|
10
|
+
def name
|
11
|
+
@name ||= nil
|
12
|
+
end
|
13
|
+
|
14
|
+
def name=(val)
|
15
|
+
@name = val
|
16
|
+
end
|
17
|
+
|
18
|
+
def age
|
19
|
+
@age ||= nil
|
20
|
+
end
|
21
|
+
|
22
|
+
def age=(val)
|
23
|
+
@age = val
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "#validates_serialized" do
|
28
|
+
class ValidatorBlockObjectTestOne
|
29
|
+
include ActiveModel::Validations
|
30
|
+
|
31
|
+
def initialize(h={})
|
32
|
+
h.each {|k,v| send("#{k}=",v)}
|
33
|
+
end
|
34
|
+
|
35
|
+
def my_attr
|
36
|
+
@my_attr ||= Foo.new
|
37
|
+
end
|
38
|
+
|
39
|
+
def my_attr=(val)
|
40
|
+
@my_attr = val
|
41
|
+
end
|
42
|
+
|
43
|
+
validates_serialized :my_attr do
|
44
|
+
validates :name, presence: true
|
45
|
+
validates :age, inclusion: { in: [1, 2, 3, 4] }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#validate" do
|
50
|
+
it "does not raise error for valid value" do
|
51
|
+
record = ValidatorBlockObjectTestOne.new(my_attr: Foo.new(name: "Tom", age: 4))
|
52
|
+
record.valid?
|
53
|
+
record.errors[:my_attr].should eq([])
|
54
|
+
end
|
55
|
+
|
56
|
+
it "adds error for invalid value" do
|
57
|
+
record = ValidatorBlockObjectTestOne.new(my_attr: Foo.new(name: nil, age: 4))
|
58
|
+
record.valid?
|
59
|
+
record.errors[:my_attr].should eq(["name can't be blank"])
|
60
|
+
end
|
61
|
+
|
62
|
+
it "adds multiple errors for multiple invalid value" do
|
63
|
+
record = ValidatorBlockObjectTestOne.new(my_attr: Foo.new(name: nil, age: 9))
|
64
|
+
record.valid?
|
65
|
+
record.errors[:my_attr].should eq(["name can't be blank", "age is not included in the list"])
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "#validates_serialized!" do
|
71
|
+
class ValidatorBlockObjectTestStrict
|
72
|
+
include ActiveModel::Validations
|
73
|
+
|
74
|
+
def initialize(h={})
|
75
|
+
h.each {|k,v| send("#{k}=",v)}
|
76
|
+
end
|
77
|
+
|
78
|
+
def my_attr
|
79
|
+
@my_attr ||= Foo.new
|
80
|
+
end
|
81
|
+
|
82
|
+
def my_attr=(val)
|
83
|
+
@my_attr = val
|
84
|
+
end
|
85
|
+
|
86
|
+
validates_serialized! :my_attr do
|
87
|
+
validates :name, presence: true
|
88
|
+
validates :age, inclusion: { in: [1, 2, 3, 4] }
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "#validate" do
|
93
|
+
it "does not raise error for valid value" do
|
94
|
+
record = ValidatorBlockObjectTestStrict.new(my_attr: Foo.new(name: "Jim", age: 3))
|
95
|
+
record.valid?
|
96
|
+
record.errors[:my_attr].should eq([])
|
97
|
+
end
|
98
|
+
|
99
|
+
it "raises error for invalid value" do
|
100
|
+
record = ValidatorBlockObjectTestStrict.new(my_attr: Foo.new(name: "Jim", age: 9))
|
101
|
+
expect { record.valid? }.to raise_error(ActiveModel::StrictValidationFailed, 'age is not included in the list')
|
102
|
+
end
|
103
|
+
|
104
|
+
it "raises error for multiple invalid value" do
|
105
|
+
record = ValidatorBlockObjectTestStrict.new(my_attr: Foo.new(name: nil, age: 9))
|
106
|
+
expect { record.valid? }.to raise_error(ActiveModel::StrictValidationFailed, "name can't be blank")
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'validates_serialized/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "validates_serialized"
|
8
|
+
spec.version = ValidatesSerialized::VERSION
|
9
|
+
spec.authors = ["brycesenz"]
|
10
|
+
spec.email = ["bryce.senz@gmail.com"]
|
11
|
+
spec.description = %q{Validation for serialized model objects}
|
12
|
+
spec.summary = %q{An ActiveModel enhancement that allows for better validation of serialized objects in Ruby}
|
13
|
+
spec.homepage = "https://github.com/brycesenz/validates_serialized"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "activemodel", ">= 4.0.0"
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
23
|
+
spec.add_development_dependency "sqlite3", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.1"
|
25
|
+
spec.add_development_dependency "rspec", "~> 2.6"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: validates_serialized
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.pre2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- brycesenz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activemodel
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sqlite3
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.1'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.1'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.6'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.6'
|
83
|
+
description: Validation for serialized model objects
|
84
|
+
email:
|
85
|
+
- bryce.senz@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- .rspec
|
91
|
+
- .ruby-gemset
|
92
|
+
- .ruby-version
|
93
|
+
- Gemfile
|
94
|
+
- Gemfile.lock
|
95
|
+
- README.md
|
96
|
+
- lib/validates_serialized.rb
|
97
|
+
- lib/validates_serialized/each_validator.rb
|
98
|
+
- lib/validates_serialized/validateable_array.rb
|
99
|
+
- lib/validates_serialized/validateable_hash.rb
|
100
|
+
- lib/validates_serialized/validateable_object.rb
|
101
|
+
- lib/validates_serialized/validators/array_validator.rb
|
102
|
+
- lib/validates_serialized/validators/hash_block_validator.rb
|
103
|
+
- lib/validates_serialized/validators/hash_validator.rb
|
104
|
+
- lib/validates_serialized/validators/object_block_validator.rb
|
105
|
+
- lib/validates_serialized/validators/serialized_validator.rb
|
106
|
+
- lib/validates_serialized/version.rb
|
107
|
+
- notes.md
|
108
|
+
- spec/acceptance_spec.rb
|
109
|
+
- spec/each_validator_spec.rb
|
110
|
+
- spec/spec_helper.rb
|
111
|
+
- spec/validateable_array_spec.rb
|
112
|
+
- spec/validateable_hash_spec.rb
|
113
|
+
- spec/validateable_object_spec.rb
|
114
|
+
- spec/validators/array_validator_spec.rb
|
115
|
+
- spec/validators/hash_block_validator_spec.rb
|
116
|
+
- spec/validators/hash_validator_spec.rb
|
117
|
+
- spec/validators/object_block_validator_spec.rb
|
118
|
+
- validates_serialized.gemspec
|
119
|
+
homepage: https://github.com/brycesenz/validates_serialized
|
120
|
+
licenses:
|
121
|
+
- MIT
|
122
|
+
metadata: {}
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ! '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ! '>'
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: 1.3.1
|
137
|
+
requirements: []
|
138
|
+
rubyforge_project:
|
139
|
+
rubygems_version: 2.2.2
|
140
|
+
signing_key:
|
141
|
+
specification_version: 4
|
142
|
+
summary: An ActiveModel enhancement that allows for better validation of serialized
|
143
|
+
objects in Ruby
|
144
|
+
test_files:
|
145
|
+
- spec/acceptance_spec.rb
|
146
|
+
- spec/each_validator_spec.rb
|
147
|
+
- spec/spec_helper.rb
|
148
|
+
- spec/validateable_array_spec.rb
|
149
|
+
- spec/validateable_hash_spec.rb
|
150
|
+
- spec/validateable_object_spec.rb
|
151
|
+
- spec/validators/array_validator_spec.rb
|
152
|
+
- spec/validators/hash_block_validator_spec.rb
|
153
|
+
- spec/validators/hash_validator_spec.rb
|
154
|
+
- spec/validators/object_block_validator_spec.rb
|