cpf_validator 0.2.0 → 0.2.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7a1babe491c16ca0f50f986ef5dccac92e82aa4d
4
+ data.tar.gz: 613ad4969650270faada42a65f755accd0a15dbc
5
+ SHA512:
6
+ metadata.gz: 84bb943769267b1b13b913e27b61c5a83908c4c691129c6b23cb93c68946fafc761af004741bfdd2d259184fb507f8d82798d409e93c21f40ea500c4277ea021
7
+ data.tar.gz: c9e4201ca10fb1840ab3295cd9b832ecb8e06ac15683c288fcac0f259405ffd92d135bae3bad60e5d92da954b022c96c3aa3fecdc87fb4b21d212f95c1b3e14f
data/.gitignore CHANGED
@@ -1 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ .rvmrc
1
4
  Gemfile.lock
5
+ pkg/*
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- # Specify your gem's dependencies in foo.gemspec
3
+ # Specify your gem's dependencies in cpf_validator.gemspec
4
4
  gemspec
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009-2011 Gabriel Sobrinho
1
+ Copyright (c) 2009-2012 nohup brasil
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -0,0 +1,17 @@
1
+ # cpf_validator
2
+
3
+ CPF validation for ActiveModel
4
+
5
+ ## Installation
6
+
7
+ gem "cpf_validator"
8
+
9
+ ## Usage
10
+
11
+ class Person < ActiveRecord::Base
12
+ validates :cpf, :cpf => true
13
+ end
14
+
15
+ ## License
16
+
17
+ Copyright (c) 2009-2012 nohup brasil, released under the MIT license
@@ -1,11 +1,11 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  Gem::Specification.new do |s|
3
3
  s.name = "cpf_validator"
4
- s.version = "0.2.0"
4
+ s.version = "0.2.1"
5
5
  s.platform = Gem::Platform::RUBY
6
6
  s.authors = ["Gabriel Sobrinho"]
7
7
  s.email = ["gabriel.sobrinho@gmail.com"]
8
- s.homepage = "https://github.com/sobrinho/cpf_validator"
8
+ s.homepage = "https://github.com/nohupbrasil/cpf_validator"
9
9
  s.summary = %q{CPF validation for ActiveModel}
10
10
 
11
11
  s.files = `git ls-files`.split("\n")
@@ -13,5 +13,6 @@ Gem::Specification.new do |s|
13
13
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
14
14
  s.require_paths = ["lib"]
15
15
 
16
- s.add_dependency(%q<activemodel>, [">= 3.0"])
16
+ s.add_dependency 'activemodel', '>= 3.0'
17
+ s.add_development_dependency 'rake', '>= 0.8.7'
17
18
  end
@@ -2,6 +2,7 @@ class CpfValidator < ActiveModel::EachValidator
2
2
  autoload :Cpf, 'cpf_validator/cpf'
3
3
 
4
4
  def validate_each(record, attribute, value)
5
- record.errors.add(attribute, options[:message]) unless Cpf.valid?(value)
5
+ message = options[:message].presence || :invalid
6
+ record.errors.add(attribute, message) unless Cpf.valid?(value)
6
7
  end
7
8
  end
@@ -15,6 +15,12 @@ class CpfValidatorTest < Test::Unit::TestCase
15
15
  assert_invalid '234.624.576-57'
16
16
  end
17
17
 
18
+ def test_blank_values
19
+ assert_invalid ''
20
+ assert_invalid false
21
+ assert_invalid nil
22
+ end
23
+
18
24
  def test_masked
19
25
  assert_valid '262.249.648-66'
20
26
  assert_valid '124.713.257-93'
@@ -29,15 +35,15 @@ class CpfValidatorTest < Test::Unit::TestCase
29
35
 
30
36
  protected
31
37
 
32
- def assert_valid(number)
33
- assert document(number).valid?
38
+ def assert_valid(cpf)
39
+ assert person(:cpf => cpf).valid?
34
40
  end
35
41
 
36
- def assert_invalid(number)
37
- assert document(number).invalid?
42
+ def assert_invalid(cpf)
43
+ assert person(:cpf => cpf).invalid?
38
44
  end
39
45
 
40
- def document(number)
41
- Document.new(number)
46
+ def person(attributes = {})
47
+ Person.new(attributes)
42
48
  end
43
49
  end
@@ -2,8 +2,9 @@ require 'rubygems'
2
2
  require 'test/unit'
3
3
  require 'active_model'
4
4
  require 'cpf_validator'
5
+ require 'ostruct'
5
6
 
6
- class Document < Struct.new(:number)
7
+ class Person < OpenStruct
7
8
  include ActiveModel::Validations
8
- validates :number, :cpf => true
9
+ validates :cpf, :cpf => true
9
10
  end
metadata CHANGED
@@ -1,77 +1,83 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: cpf_validator
3
- version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.2.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
6
5
  platform: ruby
7
- authors:
6
+ authors:
8
7
  - Gabriel Sobrinho
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
-
13
- date: 2011-05-14 00:00:00 -03:00
14
- default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
11
+ date: 2014-10-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
17
14
  name: activemodel
18
- prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
20
- none: false
21
- requirements:
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
22
17
  - - ">="
23
- - !ruby/object:Gem::Version
24
- version: "3.0"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
25
20
  type: :runtime
26
- version_requirements: *id001
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.8.7
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.8.7
27
41
  description:
28
- email:
42
+ email:
29
43
  - gabriel.sobrinho@gmail.com
30
44
  executables: []
31
-
32
45
  extensions: []
33
-
34
46
  extra_rdoc_files: []
35
-
36
- files:
37
- - .gitignore
47
+ files:
48
+ - ".gitignore"
38
49
  - Gemfile
39
50
  - MIT-LICENSE
40
- - README.textile
51
+ - README.markdown
41
52
  - Rakefile
42
53
  - cpf_validator.gemspec
43
54
  - lib/cpf_validator.rb
44
55
  - lib/cpf_validator/cpf.rb
45
56
  - test/cpf_validator_test.rb
46
57
  - test/test_helper.rb
47
- has_rdoc: true
48
- homepage: https://github.com/sobrinho/cpf_validator
58
+ homepage: https://github.com/nohupbrasil/cpf_validator
49
59
  licenses: []
50
-
60
+ metadata: {}
51
61
  post_install_message:
52
62
  rdoc_options: []
53
-
54
- require_paths:
63
+ require_paths:
55
64
  - lib
56
- required_ruby_version: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
59
67
  - - ">="
60
- - !ruby/object:Gem::Version
61
- version: "0"
62
- required_rubygems_version: !ruby/object:Gem::Requirement
63
- none: false
64
- requirements:
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
65
72
  - - ">="
66
- - !ruby/object:Gem::Version
67
- version: "0"
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
68
75
  requirements: []
69
-
70
76
  rubyforge_project:
71
- rubygems_version: 1.5.2
77
+ rubygems_version: 2.2.2
72
78
  signing_key:
73
- specification_version: 3
79
+ specification_version: 4
74
80
  summary: CPF validation for ActiveModel
75
- test_files:
81
+ test_files:
76
82
  - test/cpf_validator_test.rb
77
83
  - test/test_helper.rb
@@ -1,17 +0,0 @@
1
- h1. ValidatesAsCpf
2
-
3
- This project is based on O.S. Systems works "here":https://projetos.ossystems.com.br/projects/plugonrails/repository/browse/plugins/validates_as_cpf
4
-
5
- h2. Installation
6
-
7
- <pre>gem "validates_as_cpf"</pre>
8
-
9
- h2. Usage
10
-
11
- <pre>class Person < ActiveRecord::Base
12
- validates :document, :cpf => true
13
- end</pre>
14
-
15
- h2. License
16
-
17
- Copyright (c) 2009-2011 Gabriel Sobrinho, released under the MIT license