standalone_validator 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/standalone_validator/version.rb +1 -1
- data/lib/standalone_validator/violation.rb +8 -6
- data/spec/integration_spec.rb +2 -2
- data/spec/named_validations/validates_numericality_of_spec.rb +6 -6
- data/spec/named_validations/validates_presence_of_spec.rb +8 -8
- data/standalone_validator.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4868f5c6e7fb2d79339602a81cdbe6dd952605c8
|
4
|
+
data.tar.gz: c2e756efc4ec3a2b02f72231946369d663e378b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 962ddadc9c26f336502212fa747114a50200d08e90f5af05076eb64f605c2d1ea1b0df3fd32d6b77eb216ac888d1066b450a3bb38fd87ece2d61b61dfad62b43
|
7
|
+
data.tar.gz: 2f03ddb81348c6b48ba55c0d1b5e92ee434ec8a39eb4fd4fe760450e0b3d8626285bab29d41b797e0e84dcf8b635703f0611caead9e5847fcb70edf1d493588e
|
@@ -2,13 +2,15 @@ require 'virtus'
|
|
2
2
|
|
3
3
|
class StandaloneValidator
|
4
4
|
class Violation
|
5
|
-
include Virtus
|
5
|
+
include Virtus.value_object
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
values do
|
8
|
+
attribute :source_object, Object
|
9
|
+
attribute :attribute, Symbol, :default => :base
|
10
|
+
attribute :type, Symbol, :default => :invalid
|
11
|
+
attribute :message, String, :default => nil
|
12
|
+
attribute :options, Hash, :default => {}
|
13
|
+
end
|
12
14
|
|
13
15
|
def add_to(errors_object)
|
14
16
|
errors_object.add(attribute, message || type, options)
|
data/spec/integration_spec.rb
CHANGED
@@ -2,8 +2,8 @@ require 'spec_helper'
|
|
2
2
|
require 'standalone_validator'
|
3
3
|
|
4
4
|
describe "core features" do
|
5
|
-
let(:valid_object) {
|
6
|
-
let(:invalid_object) {
|
5
|
+
let(:valid_object) { double(:valid? => true) }
|
6
|
+
let(:invalid_object) { double(:valid? => false) }
|
7
7
|
|
8
8
|
it "accepts inline lambdas via 'include_validation'" do
|
9
9
|
validator_class = StandaloneValidator.create do
|
@@ -64,7 +64,7 @@ module StandaloneValidator::NamedValidations
|
|
64
64
|
let(:validator) { ValidatesNumericalityOf.new(:foo, :allow_blank => true) }
|
65
65
|
|
66
66
|
it "ignores 'blank' values" do
|
67
|
-
object.foo =
|
67
|
+
object.foo = double(:blank? => true, :to_f => 0)
|
68
68
|
violations = validator.violations_of(object).on_attribute(:foo)
|
69
69
|
expect(violations).to be_empty
|
70
70
|
end
|
@@ -74,7 +74,7 @@ module StandaloneValidator::NamedValidations
|
|
74
74
|
let(:validator) { ValidatesNumericalityOf.new(:foo) }
|
75
75
|
|
76
76
|
it "does not ignore 'blank' values" do
|
77
|
-
object.foo =
|
77
|
+
object.foo = double(:blank? => true, :to_f => 0)
|
78
78
|
violations = validator.violations_of(object).on_attribute(:foo)
|
79
79
|
expect(violations.of_type(:not_a_number)).to_not be_empty
|
80
80
|
end
|
@@ -140,8 +140,8 @@ module StandaloneValidator::NamedValidations
|
|
140
140
|
it "accepts an :if condition that can block the validation" do
|
141
141
|
validator = ValidatesNumericalityOf.new :foo, :if => :bar
|
142
142
|
|
143
|
-
triggers =
|
144
|
-
doesnt_trigger =
|
143
|
+
triggers = double(:foo => "not a number", :bar => true)
|
144
|
+
doesnt_trigger = double(:foo => "not a number", :bar => false)
|
145
145
|
|
146
146
|
result = validator.violations_of(triggers)
|
147
147
|
expect(result).to_not be_ok
|
@@ -153,8 +153,8 @@ module StandaloneValidator::NamedValidations
|
|
153
153
|
it "accepts an :unless condition that can block the validation" do
|
154
154
|
validator = ValidatesNumericalityOf.new :foo, :unless => :bar
|
155
155
|
|
156
|
-
triggers =
|
157
|
-
doesnt_trigger =
|
156
|
+
triggers = double(:foo => "not a number", :bar => false)
|
157
|
+
doesnt_trigger = double(:foo => "not a number", :bar => true)
|
158
158
|
|
159
159
|
result = validator.violations_of(triggers)
|
160
160
|
expect(result).to_not be_ok
|
@@ -3,26 +3,26 @@ require "standalone_validator"
|
|
3
3
|
|
4
4
|
module StandaloneValidator::NamedValidations
|
5
5
|
describe "validates_presence_of" do
|
6
|
-
let(:blank_value) {
|
7
|
-
let(:non_blank_value) {
|
6
|
+
let(:blank_value) { double(:blank? => true) }
|
7
|
+
let(:non_blank_value) { double(:blank? => false) }
|
8
8
|
|
9
9
|
it "adds a 'blank' violation if the attribute is blank" do
|
10
10
|
validator = ValidatesPresenceOf.new(:foo)
|
11
|
-
result = validator.violations_of(
|
11
|
+
result = validator.violations_of(double(:foo => blank_value))
|
12
12
|
expect(result).to_not be_ok
|
13
13
|
end
|
14
14
|
|
15
15
|
it "doesn't add the violation if the attribute isn't blank" do
|
16
16
|
validator = ValidatesPresenceOf.new(:foo)
|
17
|
-
result = validator.violations_of(
|
17
|
+
result = validator.violations_of(double(:foo => non_blank_value))
|
18
18
|
expect(result).to be_ok
|
19
19
|
end
|
20
20
|
|
21
21
|
it "accepts an :if condition that can block the validation" do
|
22
22
|
validator = ValidatesPresenceOf.new :foo, :if => :bar
|
23
23
|
|
24
|
-
triggers =
|
25
|
-
doesnt_trigger =
|
24
|
+
triggers = double(:foo => blank_value, :bar => true)
|
25
|
+
doesnt_trigger = double(:foo => blank_value, :bar => false)
|
26
26
|
|
27
27
|
result = validator.violations_of(triggers)
|
28
28
|
expect(result).to_not be_ok
|
@@ -34,8 +34,8 @@ module StandaloneValidator::NamedValidations
|
|
34
34
|
it "accepts an :unless condition that can block the validation" do
|
35
35
|
validator = ValidatesPresenceOf.new :foo, :unless => :bar
|
36
36
|
|
37
|
-
triggers =
|
38
|
-
doesnt_trigger =
|
37
|
+
triggers = double(:foo => blank_value, :bar => false)
|
38
|
+
doesnt_trigger = double(:foo => blank_value, :bar => true)
|
39
39
|
|
40
40
|
result = validator.violations_of(triggers)
|
41
41
|
expect(result).to_not be_ok
|
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
|
25
25
|
spec.add_dependency "backports"
|
26
26
|
spec.add_dependency "hamster", "~> 0.4"
|
27
|
-
spec.add_dependency "virtus", "~> 0
|
27
|
+
spec.add_dependency "virtus", "~> 1.0"
|
28
28
|
|
29
29
|
spec.add_development_dependency "bundler", "~> 1.3"
|
30
30
|
spec.add_development_dependency "rspec", "~> 2.13"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: standalone_validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Renato Zannon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: backports
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0
|
47
|
+
version: '1.0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0
|
54
|
+
version: '1.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|