validates_cpf 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -16,7 +16,7 @@ end
16
16
 
17
17
  == Test
18
18
 
19
- Only Rspec supported at the moment and has shoulda-matchers as dependecy.
19
+ Only Rspec supported at the moment. The gem already have macros for shoulda-macros and remarkable.
20
20
 
21
21
  === How?
22
22
 
@@ -24,4 +24,4 @@ You should use validates_as_cpf(:attribute) just like any other shoulda matcher.
24
24
 
25
25
  == Special Thanks
26
26
 
27
- This project is based on brcpfcnpj gem and his intention it to mantain a cleaner code to validate CPF and macros for test it.
27
+ This project is based on brcpfcnpj gem and his intention it to mantain a cleaner code to validate CPF and easy macros to test it.
@@ -0,0 +1,34 @@
1
+ require 'remarkable/active_record'
2
+
3
+ module Remarkable
4
+ module ActiveRecord
5
+ module Matchers
6
+ class ValidateAsCpfMatcher < Remarkable::ActiveRecord::Base
7
+ arguments :as => :cpf
8
+
9
+ collection_assertions :cpf_valid?, :allow_nil?, :formatted_number?
10
+
11
+ protected
12
+
13
+ def cpf_valid?
14
+ @subject.cpf = '123456'
15
+ @subject.valid?.errors[:cpf].should == ['is invalid']
16
+ end
17
+
18
+ def allow_nil?
19
+ @subject.cpf = nil
20
+ @subject.valid?.errors[:cpf].should == []
21
+ end
22
+
23
+ def formatted_number?
24
+ @subject.cpf = '55658208394'
25
+ @subject.valid?.cpf.should == '556.582.083-94'
26
+ end
27
+ end
28
+
29
+ def validates_as_cpf(*args, &block)
30
+ ValidateAsCpfMatcher.new(*args, &block).spec(self)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,3 +1,5 @@
1
+ require "shoulda-matchers"
2
+
1
3
  module Shoulda
2
4
  module Matchers
3
5
  module ActiveModel
@@ -1,3 +1,3 @@
1
1
  module ValidatesCpf
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/validates_cpf.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require "active_model"
2
- require "validates_cpf/version"
3
2
  require "validates_cpf/cpf"
4
- require "shoulda-matchers/validate_as_cpf_matcher"
3
+ require "shoulda-matchers/validate_as_cpf_matcher" if defined?(Shoulda)
4
+ require "remarkable/validate_as_cpf_matcher" if defined?(Remarkable)
5
5
 
6
6
  class CpfValidator < ActiveModel::EachValidator
7
7
  def validate_each(record, attribute, value)
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+ require 'remarkable/active_record'
3
+
4
+ describe Remarkable::ActiveRecord::Matchers::ValidateAsCpfMatcher do
5
+ context "on a attribute which validates cpf" do
6
+ it "should require a valid CPF" do
7
+ @user = User.new(:cpf => '123456')
8
+ @user.should validate_as_cpf(:cpf)
9
+ end
10
+
11
+ it "should allow a nil value" do
12
+ @user = User.new(:cpf => nil)
13
+ @user.should validate_as_cpf(:cpf)
14
+ end
15
+ end
16
+
17
+ context "on a attribute which not validates cpf" do
18
+ before do
19
+ @user = Admin.new(:cpf => '123456')
20
+ end
21
+
22
+ it "should not require a valid CPF" do
23
+ @user.should_not validate_as_cpf(:cpf)
24
+ end
25
+ end
26
+ end
@@ -1,25 +1,26 @@
1
1
  require 'spec_helper'
2
+ require 'shoulda-matchers'
2
3
 
3
4
  describe Shoulda::Matchers::ActiveModel::ValidateAsCpfMatcher do
4
5
  context "on a attribute which validates cpf" do
5
- it "should require a valid CPF" do
6
- @user = User.new(:cpf => '123456')
7
- @user.should validate_as_cpf(:cpf)
8
- end
6
+ it "should require a valid CPF" do
7
+ @user = User.new(:cpf => '123456')
8
+ @user.should validate_as_cpf(:cpf)
9
+ end
9
10
 
10
- it "should accept a nil CPF" do
11
- @user = User.new(:cpf => nil)
12
- @user.should validate_as_cpf(:cpf)
13
- end
11
+ it "should allow a nil value" do
12
+ @user = User.new(:cpf => nil)
13
+ @user.should validate_as_cpf(:cpf)
14
+ end
14
15
  end
15
16
 
16
17
  context "on a attribute which not validates cpf" do
17
- before do
18
- @user = Admin.new(:cpf => '123456')
19
- end
18
+ before do
19
+ @user = Admin.new(:cpf => '123456')
20
+ end
20
21
 
21
- it "should not require a valid CPF" do
22
- @user.should_not validate_as_cpf(:cpf)
23
- end
22
+ it "should not require a valid CPF" do
23
+ @user.should_not validate_as_cpf(:cpf)
24
24
  end
25
+ end
25
26
  end
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  require "rubygems"
2
2
  require "rspec"
3
3
  require "active_record"
4
- require "shoulda-matchers"
5
4
 
6
5
  Dir.glob(File.dirname(__FILE__) + "/../lib/**/*.rb").each { |file| require file }
7
6
  Dir.glob(File.dirname(__FILE__) + "/fake_app/**/*.rb").each { |file| require file }
@@ -9,10 +9,9 @@ Gem::Specification.new do |s|
9
9
  s.email = %q{plribeiro3000@gmail.com}
10
10
  s.homepage = ""
11
11
  s.summary = %q{CPF Validation GEM}
12
- s.description = %q{Validates CPF, the simple way.}
12
+ s.description = %q{Validates CPF and test it with macros in a simple way.}
13
13
 
14
14
  s.add_dependency("activerecord", ">= 3.0.0")
15
- s.add_dependency("shoulda-matchers")
16
15
 
17
16
  s.rubyforge_project = "validates_cpf"
18
17
 
@@ -21,6 +20,8 @@ Gem::Specification.new do |s|
21
20
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
21
  s.require_paths = %w(lib)
23
22
 
24
- s.add_development_dependency "rspec"
23
+ s.add_development_dependency "rspec", ">= 2.0.0"
24
+ s.add_development_dependency("shoulda-matchers", ">= 1.0.0")
25
+ s.add_development_dependency("remarkable_activerecord", "= 4.0.0.alpha4")
25
26
  s.add_development_dependency "sqlite3"
26
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validates_cpf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-20 00:00:00.000000000 Z
12
+ date: 2012-02-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: &15700020 !ruby/object:Gem::Requirement
16
+ requirement: &12718380 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,32 +21,43 @@ dependencies:
21
21
  version: 3.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *15700020
24
+ version_requirements: *12718380
25
25
  - !ruby/object:Gem::Dependency
26
- name: shoulda-matchers
27
- requirement: &15699520 !ruby/object:Gem::Requirement
26
+ name: rspec
27
+ requirement: &12715860 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
31
31
  - !ruby/object:Gem::Version
32
- version: '0'
33
- type: :runtime
32
+ version: 2.0.0
33
+ type: :development
34
34
  prerelease: false
35
- version_requirements: *15699520
35
+ version_requirements: *12715860
36
36
  - !ruby/object:Gem::Dependency
37
- name: rspec
38
- requirement: &15697740 !ruby/object:Gem::Requirement
37
+ name: shoulda-matchers
38
+ requirement: &12714040 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
42
42
  - !ruby/object:Gem::Version
43
- version: '0'
43
+ version: 1.0.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *12714040
47
+ - !ruby/object:Gem::Dependency
48
+ name: remarkable_activerecord
49
+ requirement: &12713040 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - =
53
+ - !ruby/object:Gem::Version
54
+ version: 4.0.0.alpha4
44
55
  type: :development
45
56
  prerelease: false
46
- version_requirements: *15697740
57
+ version_requirements: *12713040
47
58
  - !ruby/object:Gem::Dependency
48
59
  name: sqlite3
49
- requirement: &15614720 !ruby/object:Gem::Requirement
60
+ requirement: &12712400 !ruby/object:Gem::Requirement
50
61
  none: false
51
62
  requirements:
52
63
  - - ! '>='
@@ -54,8 +65,8 @@ dependencies:
54
65
  version: '0'
55
66
  type: :development
56
67
  prerelease: false
57
- version_requirements: *15614720
58
- description: Validates CPF, the simple way.
68
+ version_requirements: *12712400
69
+ description: Validates CPF and test it with macros in a simple way.
59
70
  email: plribeiro3000@gmail.com
60
71
  executables: []
61
72
  extensions: []
@@ -66,6 +77,7 @@ files:
66
77
  - Gemfile
67
78
  - README.rdoc
68
79
  - Rakefile
80
+ - lib/remarkable/validate_as_cpf_matcher.rb
69
81
  - lib/shoulda-matchers/validate_as_cpf_matcher.rb
70
82
  - lib/validates_cpf.rb
71
83
  - lib/validates_cpf/cpf.rb
@@ -74,6 +86,7 @@ files:
74
86
  - spec/fake_app/db/create_admins.rb
75
87
  - spec/fake_app/db/create_users.rb
76
88
  - spec/fake_app/user.rb
89
+ - spec/remarkable/validate_as_cpf_matcher_spec.rb
77
90
  - spec/shoulda-matchers/validate_as_cpf_matcher_spec.rb
78
91
  - spec/spec_helper.rb
79
92
  - spec/validates_cpf/cpf_spec.rb