magick_numbers_rails 0.1.0 → 0.1.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.
data/README.markdown CHANGED
@@ -31,3 +31,7 @@ For ActiveRecord Models:
31
31
 
32
32
  - I18n messages
33
33
  - validators for other numbers
34
+
35
+
36
+ Copyright (c) 2011 Mariusz Nosiński, released under the MIT license
37
+
@@ -0,0 +1,10 @@
1
+ require 'magick_numbers'
2
+ require 'active_model'
3
+
4
+ class PeselValidator < ActiveModel::EachValidator
5
+
6
+ def validate_each(record, attribute, value)
7
+ record.errors[attribute] << "invalid format" unless MagickNumbers::Pesel.new(value).valid?
8
+ end
9
+
10
+ end
@@ -0,0 +1,10 @@
1
+ require 'magick_numbers'
2
+ require 'active_model'
3
+
4
+ class RegonValidator < ActiveModel::EachValidator
5
+
6
+ def validate_each(record, attribute, value)
7
+ record.errors[attribute] << "invalid format" unless MagickNumbers::Regon.new(value).valid?
8
+ end
9
+
10
+ end
@@ -1,3 +1,3 @@
1
1
  module MagickNumbersRails
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
  require 'rspec'
3
3
  require 'active_model'
4
4
 
5
- class BasicModel
5
+ class BasicNipModel
6
6
  include ActiveModel::Validations
7
7
 
8
8
  attr_accessor :nip
@@ -13,7 +13,7 @@ end
13
13
 
14
14
  describe "NipValidator" do
15
15
  before(:each) do
16
- @model = BasicModel.new
16
+ @model = BasicNipModel.new
17
17
  end
18
18
 
19
19
  it "should be valid" do
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+ require 'rspec'
3
+ require 'active_model'
4
+
5
+ class BasicPeselModel
6
+ include ActiveModel::Validations
7
+
8
+ attr_accessor :pesel
9
+
10
+ validates :pesel, :presence => true, :pesel => true
11
+ end
12
+
13
+
14
+ describe "PeselValidator" do
15
+ before(:each) do
16
+ @model = BasicPeselModel.new
17
+ end
18
+
19
+ it "should be valid" do
20
+ @model.should_not be_valid
21
+ @model.pesel = "44051401359"
22
+ @model.should be_valid
23
+ end
24
+
25
+ it "should be invalid" do
26
+ @model.pesel = "44051401353"
27
+ @model.should_not be_valid
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+ require 'rspec'
3
+ require 'active_model'
4
+
5
+ class BasicRegonModel
6
+ include ActiveModel::Validations
7
+
8
+ attr_accessor :regon
9
+
10
+ validates :regon, :presence => true, :regon => true
11
+ end
12
+
13
+
14
+ describe "RegonValidator" do
15
+ before(:each) do
16
+ @model = BasicRegonModel.new
17
+ end
18
+
19
+ it "should be valid" do
20
+ @model.should_not be_valid
21
+ @model.regon = "192598184"
22
+ @model.should be_valid
23
+ end
24
+
25
+ it "should be invalid" do
26
+ @model.regon = "192598183"
27
+ @model.should_not be_valid
28
+ end
29
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: magick_numbers_rails
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.1.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Mariusz Nosinski
@@ -52,9 +52,13 @@ files:
52
52
  - Rakefile
53
53
  - lib/magick_numbers_rails.rb
54
54
  - lib/magick_numbers_rails/nip_validator.rb
55
+ - lib/magick_numbers_rails/pesel_validator.rb
56
+ - lib/magick_numbers_rails/regon_validator.rb
55
57
  - lib/magick_numbers_rails/version.rb
56
58
  - magick_numbers_rails.gemspec
57
59
  - spec/nip_validator_spec.rb
60
+ - spec/pesel_validator_spec.rb
61
+ - spec/regon_validator_spec.rb
58
62
  - spec/spec_helper.rb
59
63
  has_rdoc: true
60
64
  homepage: https://github.com/marioosh/magick_numbers_rails
@@ -86,4 +90,6 @@ specification_version: 3
86
90
  summary: Rails 3 validators for magick numbers like PESEL, NIP, REGON
87
91
  test_files:
88
92
  - spec/nip_validator_spec.rb
93
+ - spec/pesel_validator_spec.rb
94
+ - spec/regon_validator_spec.rb
89
95
  - spec/spec_helper.rb