standalone_validator 0.0.2 → 0.1.0

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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 43bfee850787c7744539eb0695223feae9bce1d5
4
- data.tar.gz: dbf0df8cce8600097a85a8aefef28633febc0fae
3
+ metadata.gz: 4868f5c6e7fb2d79339602a81cdbe6dd952605c8
4
+ data.tar.gz: c2e756efc4ec3a2b02f72231946369d663e378b1
5
5
  SHA512:
6
- metadata.gz: e6e66ab4b98ec778fd1e8f8aaaecb30446ac6c2582ee3f5fdc92418cda5ba147733c6814a094c0460430b142d30539f73452be950068ccb046563ed9b070976a
7
- data.tar.gz: 3abd3dd8ed13f2b94b3e91d639c23525c025203b239e679b315b98a9851df4de931d92674cd35df4bfd0d9f74928b22322a285d3ff6ca2c2de88cb3050cab743
6
+ metadata.gz: 962ddadc9c26f336502212fa747114a50200d08e90f5af05076eb64f605c2d1ea1b0df3fd32d6b77eb216ac888d1066b450a3bb38fd87ece2d61b61dfad62b43
7
+ data.tar.gz: 2f03ddb81348c6b48ba55c0d1b5e92ee434ec8a39eb4fd4fe760450e0b3d8626285bab29d41b797e0e84dcf8b635703f0611caead9e5847fcb70edf1d493588e
@@ -1,3 +1,3 @@
1
1
  class StandaloneValidator
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -2,13 +2,15 @@ require 'virtus'
2
2
 
3
3
  class StandaloneValidator
4
4
  class Violation
5
- include Virtus::ValueObject
5
+ include Virtus.value_object
6
6
 
7
- attribute :source_object, Object
8
- attribute :attribute, Symbol, :default => :base
9
- attribute :type, Symbol, :default => :invalid
10
- attribute :message, String, :default => nil
11
- attribute :options, Hash, :default => {}
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)
@@ -2,8 +2,8 @@ require 'spec_helper'
2
2
  require 'standalone_validator'
3
3
 
4
4
  describe "core features" do
5
- let(:valid_object) { stub(:valid? => true) }
6
- let(:invalid_object) { stub(:valid? => false) }
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 = stub(:blank? => true, :to_f => 0)
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 = stub(:blank? => true, :to_f => 0)
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 = stub(:foo => "not a number", :bar => true)
144
- doesnt_trigger = stub(:foo => "not a number", :bar => false)
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 = stub(:foo => "not a number", :bar => false)
157
- doesnt_trigger = stub(:foo => "not a number", :bar => true)
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) { stub(:blank? => true) }
7
- let(:non_blank_value) { stub(:blank? => false) }
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(stub(:foo => blank_value))
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(stub(:foo => non_blank_value))
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 = stub(:foo => blank_value, :bar => true)
25
- doesnt_trigger = stub(:foo => blank_value, :bar => false)
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 = stub(:foo => blank_value, :bar => false)
38
- doesnt_trigger = stub(:foo => blank_value, :bar => true)
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.5"
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.2
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-05-08 00:00:00.000000000 Z
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.5'
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.5'
54
+ version: '1.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement