easy_validator 0.1.1 → 0.1.2

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.
@@ -1,3 +1,5 @@
1
+ require 'active_model/validations'
2
+
1
3
  module ActiveModel
2
4
  module Validations
3
5
  class AbsenceValidator < ActiveModel::EachValidator
@@ -5,5 +7,11 @@ module ActiveModel
5
7
  record.errors.add(attribute, :invalid, options) unless value.blank?
6
8
  end
7
9
  end
10
+
11
+ module HelperMethods
12
+ def validates_absence_of(*attr_names)
13
+ validates_with AbsenceValidator, _merge_attributes(attr_names)
14
+ end
15
+ end
8
16
  end
9
17
  end
@@ -1,3 +1,3 @@
1
1
  module EasyValidator
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -0,0 +1,64 @@
1
+ require 'active_model/naming'
2
+ require 'active_model/translation'
3
+ require 'active_model/validations'
4
+ require 'active_model/conversion'
5
+
6
+ require "easy_validator"
7
+
8
+ describe "ValidatesAbsenceOf" do
9
+ before(:all) do
10
+ class Product
11
+ extend ActiveModel::Naming
12
+ extend ActiveModel::Translation
13
+ include ActiveModel::Validations
14
+ include ActiveModel::Conversion
15
+
16
+ attr_accessor :name
17
+
18
+ def initialize(attributes = {})
19
+ attributes.each do |name, value|
20
+ send("#{name}=", value)
21
+ end
22
+ end
23
+
24
+ def persisted?
25
+ false
26
+ end
27
+ end
28
+ end
29
+ context "#validates" do
30
+ before do
31
+ Product.class_eval do
32
+ validates :name, absence: true
33
+ end
34
+ end
35
+
36
+ it "success" do
37
+ p = Product.new
38
+ p.valid?.should == true
39
+ end
40
+
41
+ it "fail" do
42
+ p = Product.new(name: "name")
43
+ p.valid?.should == false
44
+ end
45
+ end
46
+
47
+ context "#validates_absence_of" do
48
+ before do
49
+ Product.class_eval do
50
+ validates_absence_of :name
51
+ end
52
+ end
53
+
54
+ it "success" do
55
+ p = Product.new
56
+ p.valid?.should == true
57
+ end
58
+
59
+ it "fail" do
60
+ p = Product.new(name: "name")
61
+ p.valid?.should == false
62
+ end
63
+ end
64
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-08 00:00:00.000000000 Z
12
+ date: 2013-10-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: validates_email_format_of
@@ -43,7 +43,7 @@ files:
43
43
  - lib/active_model/validates/absence_validator.rb
44
44
  - lib/easy_validator.rb
45
45
  - lib/easy_validator/version.rb
46
- - spec/absence_validator_spec.rb
46
+ - spec/easy_validator/absence_validator_spec.rb
47
47
  homepage: ''
48
48
  licenses: []
49
49
  post_install_message:
@@ -69,5 +69,5 @@ signing_key:
69
69
  specification_version: 3
70
70
  summary: Easy Validator
71
71
  test_files:
72
- - spec/absence_validator_spec.rb
72
+ - spec/easy_validator/absence_validator_spec.rb
73
73
  has_rdoc:
@@ -1,41 +0,0 @@
1
- require 'active_model/naming'
2
- require 'active_model/translation'
3
- require 'active_model/validations'
4
- require 'active_model/conversion'
5
-
6
- require "easy_validator"
7
-
8
- describe "ValidatesAbsenceOf" do
9
- before do
10
- class Product
11
- extend ActiveModel::Naming
12
- extend ActiveModel::Translation
13
- include ActiveModel::Validations
14
- include ActiveModel::Conversion
15
-
16
- attr_accessor :name
17
-
18
- validates :name, absence: true
19
-
20
- def initialize(attributes = {})
21
- attributes.each do |name, value|
22
- send("#{name}=", value)
23
- end
24
- end
25
-
26
- def persisted?
27
- false
28
- end
29
- end
30
- end
31
-
32
- it "success" do
33
- p = Product.new
34
- p.valid?.should == true
35
- end
36
-
37
- it "fail" do
38
- p = Product.new(name: "name")
39
- p.valid?.should == false
40
- end
41
- end