validates_cpf 0.1.1 → 0.2.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.
- data/README.rdoc +2 -2
- data/lib/remarkable/validate_as_cpf_matcher.rb +34 -0
- data/lib/shoulda-matchers/validate_as_cpf_matcher.rb +2 -0
- data/lib/validates_cpf/version.rb +1 -1
- data/lib/validates_cpf.rb +2 -2
- data/spec/remarkable/validate_as_cpf_matcher_spec.rb +26 -0
- data/spec/shoulda-matchers/validate_as_cpf_matcher_spec.rb +15 -14
- data/spec/spec_helper.rb +0 -1
- data/validates_cpf.gemspec +4 -3
- metadata +29 -16
    
        data/README.rdoc
    CHANGED
    
    | @@ -16,7 +16,7 @@ end | |
| 16 16 |  | 
| 17 17 | 
             
            == Test
         | 
| 18 18 |  | 
| 19 | 
            -
            Only Rspec supported at the moment  | 
| 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  | 
| 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
         | 
    
        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 | 
            -
             | 
| 6 | 
            -
             | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 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 | 
            -
             | 
| 11 | 
            -
             | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 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 | 
            -
             | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 18 | 
            +
                before do
         | 
| 19 | 
            +
                  @user = Admin.new(:cpf => '123456')
         | 
| 20 | 
            +
                end
         | 
| 20 21 |  | 
| 21 | 
            -
             | 
| 22 | 
            -
             | 
| 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
    
    
    
        data/validates_cpf.gemspec
    CHANGED
    
    | @@ -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 | 
| 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. | 
| 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- | 
| 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: & | 
| 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: * | 
| 24 | 
            +
              version_requirements: *12718380
         | 
| 25 25 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 26 | 
            -
              name:  | 
| 27 | 
            -
              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:  | 
| 33 | 
            -
              type: : | 
| 32 | 
            +
                    version: 2.0.0
         | 
| 33 | 
            +
              type: :development
         | 
| 34 34 | 
             
              prerelease: false
         | 
| 35 | 
            -
              version_requirements: * | 
| 35 | 
            +
              version_requirements: *12715860
         | 
| 36 36 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 37 | 
            -
              name:  | 
| 38 | 
            -
              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:  | 
| 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: * | 
| 57 | 
            +
              version_requirements: *12713040
         | 
| 47 58 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 48 59 | 
             
              name: sqlite3
         | 
| 49 | 
            -
              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: * | 
| 58 | 
            -
            description: Validates CPF | 
| 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
         |