validates_cpf 1.1.3 → 2.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,5 +1,19 @@
1
1
  *.gem
2
+ *.rbc
2
3
  .bundle
3
- .rvmrc
4
+ .config
5
+ .yardoc
6
+ .coveralls.yml
7
+ *.swp
4
8
  Gemfile.lock
5
- pkg/*
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ tmp
18
+ .*~
19
+ *~
data/.rspec CHANGED
@@ -1 +1 @@
1
- --colour --format documentation
1
+ --colour --format documentation --profile
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ validates_cpf
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 1.9.3
data/.travis.yml ADDED
@@ -0,0 +1,17 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - jruby
6
+ - ree
7
+ gemfile:
8
+ - gemfiles/Gemfile.rails3
9
+ - gemfiles/Gemfile.rails4
10
+ matrix:
11
+ exclude:
12
+ - rvm: 1.8.7
13
+ gemfile: gemfiles/Gemfile.rails4
14
+ - rvm: 1.9.2
15
+ gemfile: gemfiles/Gemfile.rails4
16
+ - rvm: ree
17
+ gemfile: gemfiles/Gemfile.rails4
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # ValidatesCPF
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/validates_cpf.png)](http://badge.fury.io/rb/validates_cpf) [![Build Status](https://secure.travis-ci.org/plribeiro3000/validates_cpf.png?branch=master)](http://travis-ci.org/plribeiro3000/validates_cpf) [![Dependency Status](https://gemnasium.com/plribeiro3000/validates_cpf.png)](https://gemnasium.com/plribeiro3000/validates_cpf) [![Coverage Status](https://coveralls.io/repos/plribeiro3000/validates_cpf/badge.png?branch=master)](https://coveralls.io/r/plribeiro3000/validates_cpf) [![Code Climate](https://codeclimate.com/github/plribeiro3000/validates_cpf.png)](https://codeclimate.com/github/plribeiro3000/validates_cpf)
4
+
5
+ Validates cpf and test it in a simple way
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'validates_cpf'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install validates_cpf
20
+
21
+ ## Usage
22
+
23
+ Just use as any other validator:
24
+
25
+ ```ruby
26
+ class User < ActiveRecord::Base
27
+ validates :cpf, :cpf => true
28
+ end
29
+ ```
30
+
31
+ ## Notes
32
+
33
+ It will load a macher to test automatically if the gem is below shoulda-matchers.
34
+
35
+ ## Mantainers
36
+ [@plribeiro3000](https://github.com/plribeiro3000)
37
+
38
+ ## Contributing
39
+
40
+ 1. Fork it
41
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
42
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
43
+ 4. Push to the branch (`git push origin my-new-feature`)
44
+ 5. Create new Pull Request
@@ -0,0 +1,5 @@
1
+ source :rubygems
2
+
3
+ gem 'activesupport', '3.2.14'
4
+
5
+ gemspec :path => '../'
@@ -0,0 +1,5 @@
1
+ source :rubygems
2
+
3
+ gem 'activesupport', '>= 4.0.0'
4
+
5
+ gemspec :path => '../'
@@ -0,0 +1,6 @@
1
+ class CpfValidator < ActiveModel::EachValidator
2
+ def validate_each(record, attribute, value)
3
+ key = :"activerecord.errors.models.#{record.class.name.underscore}.attributes.#{attribute}.invalid"
4
+ record.errors.add(attribute, I18n.t(key, :default => :'activerecord.errors.messages.invalid')) unless ValidatesCpf::Cpf.new(value).valid?
5
+ end
6
+ end
@@ -0,0 +1,23 @@
1
+ require 'shoulda-matchers'
2
+ require 'active_support/core_ext/array/wrap'
3
+
4
+ module Shoulda
5
+ module Matchers
6
+ module ActiveModel
7
+ def require_a_valid_cpf(attr = :cpf)
8
+ RequireAValidCpfMatcher.new(attr)
9
+ end
10
+
11
+ class RequireAValidCpfMatcher < ValidationMatcher
12
+ def description
13
+ 'require a valid CPF number'
14
+ end
15
+
16
+ def matches?(subject)
17
+ @subject = subject
18
+ disallows_value_of('123456') && allows_value_of('897.546.112-20')
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,52 +1,54 @@
1
- class CPF
2
- def initialize(number)
3
- number =~ /^(\d{3}\.?\d{3}\.?\d{3})-?(\d{2})$/
4
- @number = number
5
- @pure_number = $1
6
- @result = $2
7
- @cleaned_number = @pure_number.nil? ? nil : @number.gsub(/[\.-]/, "")
8
- format_number! if @pure_number
9
- end
10
-
11
- def valid?
12
- return true if @number.nil?
13
- return false unless @pure_number
14
- check_cpf
15
- end
16
-
17
- def number
18
- @number
19
- end
20
-
21
- private
22
-
23
- def check_cpf
24
- return false if @cleaned_number.length != 11 or @cleaned_number.scan(/\d/).uniq.length == 1
25
- @result == first_digit_verifier + second_digit_verifier
26
- end
27
-
28
- def first_digit_verifier
29
- sum = multiply_and_sum([10, 9, 8, 7, 6, 5, 4, 3, 2], @pure_number)
30
- digit_verifier(sum%11).to_s
31
- end
32
-
33
- def second_digit_verifier
34
- sum = multiply_and_sum([11, 10, 9, 8, 7, 6, 5, 4, 3, 2], @pure_number + first_digit_verifier)
35
- digit_verifier(sum%11).to_s
36
- end
37
-
38
- def multiply_and_sum(array, number)
39
- multiplied = []
40
- number.scan(/\d{1}/).each_with_index { |e, i| multiplied[i] = e.to_i * array[i] }
41
- multiplied.inject { |s,e| s + e }
42
- end
43
-
44
- def digit_verifier(rest)
45
- rest < 2 ? 0 : 11 - rest
46
- end
47
-
48
- def format_number!
49
- @cleaned_number =~ /(\d{3})(\d{3})(\d{3})(\d{2})/
50
- @number = "#{$1}.#{$2}.#{$3}-#{$4}"
1
+ module ValidatesCpf
2
+ class Cpf
3
+ def initialize(number)
4
+ number =~ /^(\d{3}\.?\d{3}\.?\d{3})-?(\d{2})$/
5
+ @number = number
6
+ @pure_number = $1
7
+ @result = $2
8
+ @cleaned_number = @pure_number.nil? ? nil : @number.gsub(/[\.-]/, "")
9
+ format_number! if @pure_number
10
+ end
11
+
12
+ def valid?
13
+ return true if @number.nil?
14
+ return false unless @pure_number
15
+ check_cpf
16
+ end
17
+
18
+ def number
19
+ @number
20
+ end
21
+
22
+ private
23
+
24
+ def check_cpf
25
+ return false if @cleaned_number.length != 11 or @cleaned_number.scan(/\d/).uniq.length == 1
26
+ @result == first_digit_verifier + second_digit_verifier
27
+ end
28
+
29
+ def first_digit_verifier
30
+ sum = multiply_and_sum([10, 9, 8, 7, 6, 5, 4, 3, 2], @pure_number)
31
+ digit_verifier(sum%11).to_s
32
+ end
33
+
34
+ def second_digit_verifier
35
+ sum = multiply_and_sum([11, 10, 9, 8, 7, 6, 5, 4, 3, 2], @pure_number + first_digit_verifier)
36
+ digit_verifier(sum%11).to_s
37
+ end
38
+
39
+ def multiply_and_sum(array, number)
40
+ multiplied = []
41
+ number.scan(/\d{1}/).each_with_index { |e, i| multiplied[i] = e.to_i * array[i] }
42
+ multiplied.inject { |s,e| s + e }
43
+ end
44
+
45
+ def digit_verifier(rest)
46
+ rest < 2 ? 0 : 11 - rest
47
+ end
48
+
49
+ def format_number!
50
+ @cleaned_number =~ /(\d{3})(\d{3})(\d{3})(\d{2})/
51
+ @number = "#{$1}.#{$2}.#{$3}-#{$4}"
52
+ end
51
53
  end
52
54
  end
@@ -1,3 +1,3 @@
1
1
  module ValidatesCpf
2
- VERSION = "1.1.3"
3
- end
2
+ VERSION = '2.0.0.rc1'
3
+ end
data/lib/validates_cpf.rb CHANGED
@@ -1,12 +1,6 @@
1
- require "validates_cpf/cpf"
1
+ require 'cpf_validator'
2
+ require 'require_a_valid_cpf_matcher' if defined?(::Shoulda)
2
3
 
3
- #Rspec Matchers
4
- require "validates_cpf/shoulda-matchers/require_a_valid_cpf_matcher" if defined?(::Shoulda)
5
- require "validates_cpf/remarkable/require_a_valid_cpf_matcher" if defined?(::Remarkable)
6
-
7
- class CpfValidator < ActiveModel::EachValidator
8
- def validate_each(record, attribute, value)
9
- key = :"activerecord.errors.models.#{record.class.name.downcase}.attributes.#{attribute.to_s}.invalid"
10
- record.errors[attribute] << I18n.t(key, :default => :"activerecord.errors.messages.invalid") unless CPF.new(value).valid?
11
- end
4
+ module ValidatesCpf
5
+ autoload :Cpf, 'validates_cpf/cpf'
12
6
  end
@@ -1,2 +1,3 @@
1
- class Admin < ActiveRecord::Base
1
+ class Admin
2
+ attr_accessor :cpf
2
3
  end
@@ -1,3 +1,15 @@
1
- class User < ActiveRecord::Base
1
+ class User
2
+ include ActiveModel::Validations
3
+ include ActiveModel::Conversion
4
+ extend ActiveModel::Naming
5
+
6
+ attr_accessor :cpf, :name
7
+
2
8
  validates :cpf, :cpf => true
9
+
10
+ def initialize(attributes = {})
11
+ attributes.each do |key, value|
12
+ instance_variable_set("@#{key}", value)
13
+ end
14
+ end
3
15
  end
@@ -6,15 +6,15 @@ describe Shoulda::Matchers::ActiveModel::RequireAValidCpfMatcher do
6
6
  @user = User.new
7
7
  end
8
8
 
9
- it "should accept on cpf" do
9
+ it 'should accept on cpf' do
10
10
  @user.should require_a_valid_cpf(:cpf)
11
11
  end
12
12
 
13
- it "should accept without a specified attribute" do
13
+ it 'should accept without a specified attribute' do
14
14
  @user.should require_a_valid_cpf
15
15
  end
16
16
 
17
- it "should reject on name" do
17
+ it 'should reject on name' do
18
18
  @user.should_not require_a_valid_cpf(:name)
19
19
  end
20
20
  end
data/spec/spec_helper.rb CHANGED
@@ -1,11 +1,8 @@
1
- require "rubygems"
2
- require "rspec"
3
- require "active_record"
1
+ require 'rspec'
2
+ require 'active_model'
3
+ require 'coveralls'
4
4
 
5
- Dir.glob(File.dirname(__FILE__) + "/../lib/**/*.rb").each { |file| require file }
6
- Dir.glob(File.dirname(__FILE__) + "/fake_app/**/*.rb").each { |file| require file }
5
+ Coveralls.wear!
7
6
 
8
- ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
9
-
10
- CreateUsers.migrate(:up)
11
- CreateAdmins.migrate(:up)
7
+ Dir.glob(File.dirname(__FILE__) + '/../lib/**/*.rb').each { |file| require file }
8
+ Dir.glob(File.dirname(__FILE__) + '/fake_app/*.rb').each { |file| require file }
@@ -1,95 +1,95 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe CPF do
3
+ describe ValidatesCpf::Cpf do
4
4
  context "should be invalid with" do
5
5
  it "blank number" do
6
- CPF.new('').should_not be_valid
6
+ ValidatesCpf::Cpf.new('').should_not be_valid
7
7
  end
8
8
 
9
9
  it "345.65.67.3 as number" do
10
- CPF.new('345.65.67.3').should_not be_valid
10
+ ValidatesCpf::Cpf.new('345.65.67.3').should_not be_valid
11
11
  end
12
12
 
13
13
  it "567.765-87698 as number" do
14
- CPF.new('567.765-87698').should_not be_valid
14
+ ValidatesCpf::Cpf.new('567.765-87698').should_not be_valid
15
15
  end
16
16
 
17
17
  it "345456-654-01 as number" do
18
- CPF.new('345456-654-01').should_not be_valid
18
+ ValidatesCpf::Cpf.new('345456-654-01').should_not be_valid
19
19
  end
20
20
 
21
21
  it "123456 as number" do
22
- CPF.new('123456').should_not be_valid
22
+ ValidatesCpf::Cpf.new('123456').should_not be_valid
23
23
  end
24
24
 
25
25
  it "23342345699 as number" do
26
- CPF.new('23342345699').should_not be_valid
26
+ ValidatesCpf::Cpf.new('23342345699').should_not be_valid
27
27
  end
28
28
 
29
29
  it "34.543.567-98 as number" do
30
- CPF.new('34.543.567-98').should_not be_valid
30
+ ValidatesCpf::Cpf.new('34.543.567-98').should_not be_valid
31
31
  end
32
32
 
33
33
  it "456.676456-87 as number" do
34
- CPF.new('456.676456-87').should_not be_valid
34
+ ValidatesCpf::Cpf.new('456.676456-87').should_not be_valid
35
35
  end
36
36
 
37
37
  it "333333333-33 as number" do
38
- CPF.new('333333333-33').should_not be_valid
38
+ ValidatesCpf::Cpf.new('333333333-33').should_not be_valid
39
39
  end
40
40
 
41
41
  it "00000000000 as number" do
42
- CPF.new('00000000000').should_not be_valid
42
+ ValidatesCpf::Cpf.new('00000000000').should_not be_valid
43
43
  end
44
44
 
45
45
  it "000.000.000-00 as number" do
46
- CPF.new('000.000.000-00').should_not be_valid
46
+ ValidatesCpf::Cpf.new('000.000.000-00').should_not be_valid
47
47
  end
48
48
 
49
49
  it "111.444.777-3500 as number" do
50
- CPF.new('111.444.777-3500').should_not be_valid
50
+ ValidatesCpf::Cpf.new('111.444.777-3500').should_not be_valid
51
51
  end
52
52
 
53
53
  it "11144477735AB as number" do
54
- CPF.new('11144477735AB').should_not be_valid
54
+ ValidatesCpf::Cpf.new('11144477735AB').should_not be_valid
55
55
  end
56
56
  end
57
57
 
58
58
  context "should be valid with" do
59
59
  it "nil as number" do
60
- CPF.new(nil).should be_valid
60
+ ValidatesCpf::Cpf.new(nil).should be_valid
61
61
  end
62
62
 
63
63
  it "111.444.777-35 as number" do
64
- CPF.new('111.444.777-35').should be_valid
64
+ ValidatesCpf::Cpf.new('111.444.777-35').should be_valid
65
65
  end
66
66
 
67
67
  it "11144477735 as number" do
68
- CPF.new('11144477735').should be_valid
68
+ ValidatesCpf::Cpf.new('11144477735').should be_valid
69
69
  end
70
70
 
71
71
  it "111.444777-35 as number" do
72
- CPF.new('111.444777-35').should be_valid
72
+ ValidatesCpf::Cpf.new('111.444777-35').should be_valid
73
73
  end
74
74
 
75
75
  it "111444.777-35 as number" do
76
- CPF.new('111444.777-35').should be_valid
76
+ ValidatesCpf::Cpf.new('111444.777-35').should be_valid
77
77
  end
78
78
 
79
79
  it "111.444.77735 as number" do
80
- CPF.new('111.444.77735').should be_valid
80
+ ValidatesCpf::Cpf.new('111.444.77735').should be_valid
81
81
  end
82
82
  end
83
83
 
84
84
  context "with a valid value" do
85
85
  it "should return it formatted" do
86
- CPF.new('11144477735').number.should == '111.444.777-35'
86
+ ValidatesCpf::Cpf.new('11144477735').number.should == '111.444.777-35'
87
87
  end
88
88
  end
89
89
 
90
90
  context "with an invalid value" do
91
91
  it "should return as it was" do
92
- CPF.new('123456').number.should == '123456'
92
+ ValidatesCpf::Cpf.new('123456').number.should == '123456'
93
93
  end
94
94
  end
95
95
  end
@@ -1,39 +1,41 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe CpfValidator do
4
- context "when cpf is invalid" do
5
- before :each do
6
- @user = User.new(:cpf => "12345")
7
- I18n.stub(:t).with(:"activerecord.errors.models.user.attributes.cpf.invalid",
8
- :default => :"activerecord.errors.messages.invalid").and_return("is invalid")
9
- end
4
+ context 'when cpf is invalid' do
5
+ context 'on a non namespaced model' do
6
+ before :each do
7
+ @user = User.new(:cpf => '12345')
8
+ I18n.stub(:t).with(:'activerecord.errors.models.user.attributes.cpf.invalid',
9
+ :default => :'activerecord.errors.messages.invalid').and_return('is invalid')
10
+ end
10
11
 
11
- it "should set object as invalid" do
12
- @user.valid?.should be_false
13
- end
12
+ it 'should set object as invalid' do
13
+ @user.valid?.should be_false
14
+ end
14
15
 
15
- it "should set an error message on attribute" do
16
- @user.valid?
17
- @user.errors[:cpf].should == ['is invalid']
16
+ it 'should set an error message on attribute' do
17
+ @user.valid?
18
+ @user.errors[:cpf].should == ['is invalid']
19
+ end
18
20
  end
19
21
  end
20
22
 
21
- context "when cpf is valid" do
23
+ context 'when cpf is valid' do
22
24
  before :each do
23
- @user = User.new(:cpf => "11144477735")
25
+ @user = User.new(:cpf => '11144477735')
24
26
  end
25
27
 
26
- it "should set object as valid" do
28
+ it 'should set object as valid' do
27
29
  @user.valid?.should be_true
28
30
  end
29
31
 
30
- it "should not set an error message on attribute" do
32
+ it 'should not set an error message on attribute' do
31
33
  @user.valid?
32
34
  @user.errors[:cpf].should be_blank
33
35
  end
34
36
  end
35
37
 
36
- it "should accept a nil value" do
38
+ it 'should accept a nil value' do
37
39
  @user = User.new(:cpf => nil)
38
40
  @user.valid?.should be_true
39
41
  end
@@ -1,26 +1,24 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "validates_cpf/version"
2
+ require File.expand_path('../lib/validates_cpf/version', __FILE__)
4
3
 
5
- Gem::Specification.new do |s|
6
- s.name = "validates_cpf"
7
- s.version = ValidatesCpf::VERSION
8
- s.authors = ["Paulo Henrique Lopes Ribeiro"]
9
- s.email = %q{plribeiro3000@gmail.com}
10
- s.homepage = ""
11
- s.summary = %q{CPF Validation GEM}
12
- s.description = %q{Validates CPF and test it with matchers in a simple way.}
4
+ Gem::Specification.new do |gem|
5
+ gem.name = 'validates_cpf'
6
+ gem.version = ValidatesCpf::VERSION
7
+ gem.authors = %q{Paulo Henrique Lopes Ribeiro}
8
+ gem.email = %q{plribeiro3000@gmail.com}
9
+ gem.summary = %q{Validates CPF and test it with matchers in a simple way.}
13
10
 
14
- s.files = `git ls-files`.split("\n")
15
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
- s.require_paths = %w(lib)
11
+ gem.files = `git ls-files`.split("\n")
12
+ gem.test_files = `git ls-files -- {test,spec,features,examples,gemfiles}/*`.split("\n")
13
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
14
+ gem.require_paths = %w(lib)
18
15
 
19
- s.add_dependency "activemodel", ">= 3.0.0"
20
- s.add_development_dependency "activerecord", ">= 3.0.0"
21
- s.add_development_dependency "rake"
22
- s.add_development_dependency "rspec", ">= 2.0.0"
23
- s.add_development_dependency "shoulda-matchers", ">= 1.2.0"
24
- s.add_development_dependency "remarkable_activerecord", ">= 4.0.0.alpha4"
25
- s.add_development_dependency "sqlite3"
26
- end
16
+ gem.license = 'MIT'
17
+
18
+ gem.add_development_dependency 'rake'
19
+ gem.add_development_dependency 'rspec'
20
+ gem.add_development_dependency 'shoulda-matchers', '2.0.0'
21
+ gem.add_development_dependency 'coveralls'
22
+
23
+ gem.add_runtime_dependency 'activemodel'
24
+ end
metadata CHANGED
@@ -1,48 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validates_cpf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
5
- prerelease:
4
+ version: 2.0.0.rc1
5
+ prerelease: 6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Paulo Henrique Lopes Ribeiro
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-26 00:00:00.000000000 Z
12
+ date: 2013-09-17 00:00:00.000000000 Z
13
13
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: activemodel
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: 3.0.0
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: 3.0.0
30
- - !ruby/object:Gem::Dependency
31
- name: activerecord
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ! '>='
36
- - !ruby/object:Gem::Version
37
- version: 3.0.0
38
- type: :development
39
- prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: 3.0.0
46
14
  - !ruby/object:Gem::Dependency
47
15
  name: rake
48
16
  requirement: !ruby/object:Gem::Requirement
@@ -66,7 +34,7 @@ dependencies:
66
34
  requirements:
67
35
  - - ! '>='
68
36
  - !ruby/object:Gem::Version
69
- version: 2.0.0
37
+ version: '0'
70
38
  type: :development
71
39
  prerelease: false
72
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -74,31 +42,31 @@ dependencies:
74
42
  requirements:
75
43
  - - ! '>='
76
44
  - !ruby/object:Gem::Version
77
- version: 2.0.0
45
+ version: '0'
78
46
  - !ruby/object:Gem::Dependency
79
47
  name: shoulda-matchers
80
48
  requirement: !ruby/object:Gem::Requirement
81
49
  none: false
82
50
  requirements:
83
- - - ! '>='
51
+ - - '='
84
52
  - !ruby/object:Gem::Version
85
- version: 1.2.0
53
+ version: 2.0.0
86
54
  type: :development
87
55
  prerelease: false
88
56
  version_requirements: !ruby/object:Gem::Requirement
89
57
  none: false
90
58
  requirements:
91
- - - ! '>='
59
+ - - '='
92
60
  - !ruby/object:Gem::Version
93
- version: 1.2.0
61
+ version: 2.0.0
94
62
  - !ruby/object:Gem::Dependency
95
- name: remarkable_activerecord
63
+ name: coveralls
96
64
  requirement: !ruby/object:Gem::Requirement
97
65
  none: false
98
66
  requirements:
99
67
  - - ! '>='
100
68
  - !ruby/object:Gem::Version
101
- version: 4.0.0.alpha4
69
+ version: '0'
102
70
  type: :development
103
71
  prerelease: false
104
72
  version_requirements: !ruby/object:Gem::Requirement
@@ -106,16 +74,16 @@ dependencies:
106
74
  requirements:
107
75
  - - ! '>='
108
76
  - !ruby/object:Gem::Version
109
- version: 4.0.0.alpha4
77
+ version: '0'
110
78
  - !ruby/object:Gem::Dependency
111
- name: sqlite3
79
+ name: activemodel
112
80
  requirement: !ruby/object:Gem::Requirement
113
81
  none: false
114
82
  requirements:
115
83
  - - ! '>='
116
84
  - !ruby/object:Gem::Version
117
85
  version: '0'
118
- type: :development
86
+ type: :runtime
119
87
  prerelease: false
120
88
  version_requirements: !ruby/object:Gem::Requirement
121
89
  none: false
@@ -123,7 +91,7 @@ dependencies:
123
91
  - - ! '>='
124
92
  - !ruby/object:Gem::Version
125
93
  version: '0'
126
- description: Validates CPF and test it with matchers in a simple way.
94
+ description:
127
95
  email: plribeiro3000@gmail.com
128
96
  executables: []
129
97
  extensions: []
@@ -131,27 +99,30 @@ extra_rdoc_files: []
131
99
  files:
132
100
  - .gitignore
133
101
  - .rspec
102
+ - .ruby-gemset
103
+ - .ruby-version
104
+ - .travis.yml
134
105
  - Gemfile
135
106
  - LICENSE
136
- - README.rdoc
107
+ - README.md
137
108
  - Rakefile
109
+ - gemfiles/Gemfile.rails3
110
+ - gemfiles/Gemfile.rails4
111
+ - lib/cpf_validator.rb
112
+ - lib/require_a_valid_cpf_matcher.rb
138
113
  - lib/validates_cpf.rb
139
114
  - lib/validates_cpf/cpf.rb
140
- - lib/validates_cpf/remarkable/require_a_valid_cpf_matcher.rb
141
- - lib/validates_cpf/shoulda-matchers/require_a_valid_cpf_matcher.rb
142
115
  - lib/validates_cpf/version.rb
143
116
  - spec/fake_app/admin.rb
144
- - spec/fake_app/db/create_admins.rb
145
- - spec/fake_app/db/create_users.rb
146
117
  - spec/fake_app/user.rb
118
+ - spec/require_a_valid_cpf_matcher_spec.rb
147
119
  - spec/spec_helper.rb
148
120
  - spec/validates_cpf/cpf_spec.rb
149
- - spec/validates_cpf/remarkable/require_a_valid_cpf_matcher_spec.rb
150
- - spec/validates_cpf/shoulda-matchers/require_a_valid_cpf_matcher_spec.rb
151
121
  - spec/validates_cpf_spec.rb
152
122
  - validates_cpf.gemspec
153
- homepage: ''
154
- licenses: []
123
+ homepage:
124
+ licenses:
125
+ - MIT
155
126
  post_install_message:
156
127
  rdoc_options: []
157
128
  require_paths:
@@ -165,13 +136,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
165
136
  required_rubygems_version: !ruby/object:Gem::Requirement
166
137
  none: false
167
138
  requirements:
168
- - - ! '>='
139
+ - - ! '>'
169
140
  - !ruby/object:Gem::Version
170
- version: '0'
141
+ version: 1.3.1
171
142
  requirements: []
172
143
  rubyforge_project:
173
- rubygems_version: 1.8.24
144
+ rubygems_version: 1.8.25
174
145
  signing_key:
175
146
  specification_version: 3
176
- summary: CPF Validation GEM
177
- test_files: []
147
+ summary: Validates CPF and test it with matchers in a simple way.
148
+ test_files:
149
+ - gemfiles/Gemfile.rails3
150
+ - gemfiles/Gemfile.rails4
151
+ - spec/fake_app/admin.rb
152
+ - spec/fake_app/user.rb
153
+ - spec/require_a_valid_cpf_matcher_spec.rb
154
+ - spec/spec_helper.rb
155
+ - spec/validates_cpf/cpf_spec.rb
156
+ - spec/validates_cpf_spec.rb
data/README.rdoc DELETED
@@ -1,29 +0,0 @@
1
- = ValidatesCPF {<img src="https://secure.travis-ci.org/plribeiro3000/validates_cpf.png" />}[http://travis-ci.org/plribeiro3000/validates_cpf]
2
-
3
- Rails gem to validate CPF. Don't forget to check {ValidatesCnpj}[https://github.com/plribeiro3000/validates_cnpj], {ValidatesTelephone}[https://github.com/plribeiro3000/validates_telephone] and {ValidatesHost}[https://github.com/plribeiro3000/validates_host].
4
-
5
- == Install
6
-
7
- gem install validates_cpf
8
-
9
- == Usage
10
-
11
- Lets say you have a model with "cpf" string column that you want to be a valid CPF. Just add this to your model:
12
-
13
- class User < ActiveRecord::Base
14
- validates :cpf, :cpf => true
15
- end
16
-
17
-
18
- == Test
19
-
20
- This gem has builtin matchers for shoulda-matchers and remarkable.
21
-
22
- == Notes
23
-
24
- Since version 1.0.0, it isn't necessary to load any file inside your spec_helper anymore.
25
-
26
-
27
- == Contribute
28
-
29
- Fork the project and send me a Pull Request. =D
@@ -1,29 +0,0 @@
1
- require 'remarkable/active_model'
2
-
3
- module Remarkable
4
- module ActiveModel
5
- module Matchers
6
- class RequireAValidCpfMatcher < Remarkable::ActiveModel::Base
7
- arguments :cpf
8
-
9
- collection_assertions :disallow_invalid_value, :allow_valid_value
10
-
11
- protected
12
-
13
- def disallow_invalid_value
14
- @subject.cpf = '123456'
15
- @subject.valid?.errors[:cpf].should == ['is invalid']
16
- end
17
-
18
- def allow_valid_value
19
- @subject.cpf = '764.579.437-21'
20
- @subject.valid?.errors[:cpf].should == []
21
- end
22
- end
23
-
24
- def require_a_valid_cpf(*args, &block)
25
- RequireAValidCpfMatcher.new(*args, &block).spec(self)
26
- end
27
- end
28
- end
29
- end
@@ -1,37 +0,0 @@
1
- require "shoulda-matchers"
2
-
3
- module Shoulda
4
- module Matchers
5
- module ActiveModel
6
- def require_a_valid_cpf(attr = :cpf)
7
- RequireAValidCpfMatcher.new(attr)
8
- end
9
-
10
- class RequireAValidCpfMatcher < ValidationMatcher
11
- def initialize(attribute)
12
- @attribute = attribute
13
- end
14
-
15
- def description
16
- "require a valid CPF number"
17
- end
18
-
19
- def matches?(subject)
20
- super(subject)
21
-
22
- disallows_invalid_value and allows_valid_value
23
- end
24
-
25
- private
26
-
27
- def disallows_invalid_value
28
- disallows_value_of("123456")
29
- end
30
-
31
- def allows_valid_value
32
- allows_value_of("897.546.112-20")
33
- end
34
- end
35
- end
36
- end
37
- end
@@ -1,12 +0,0 @@
1
- class CreateAdmins < ActiveRecord::Migration
2
- def self.up
3
- create_table :admins do |a|
4
- a.string :cpf
5
- a.string :name
6
- end
7
- end
8
-
9
- def self.down
10
- drop_table :admins
11
- end
12
- end
@@ -1,12 +0,0 @@
1
- class CreateUsers < ActiveRecord::Migration
2
- def self.up
3
- create_table :users do |u|
4
- u.string :cpf
5
- u.string :name
6
- end
7
- end
8
-
9
- def self.down
10
- drop_table :users
11
- end
12
- end
@@ -1,20 +0,0 @@
1
- require 'spec_helper'
2
- require 'remarkable/active_model'
3
-
4
- describe Remarkable::ActiveModel::Matchers::RequireAValidCpfMatcher do
5
- before :each do
6
- @user = User.new
7
- end
8
-
9
- it "should accept on cpf" do
10
- @user.should require_a_valid_cpf(:cpf)
11
- end
12
-
13
- it "should accept without a specified attribute" do
14
- @user.should require_a_valid_cpf
15
- end
16
-
17
- it "should reject on name" do
18
- @user.should_not require_a_valid_cpf(:name)
19
- end
20
- end