auto_validations 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,8 +7,16 @@ module AutoValidations
7
7
 
8
8
  module ClassMethods
9
9
  def auto_length_validation(options = {})
10
- options.reverse_merge! :except => []
11
- columns.select { |c| !options[:except].include?(c.name) }.each do |column|
10
+ options[:except] = Array.wrap(options[:except])
11
+ options[:except].map!(&:to_s)
12
+
13
+ options.reverse_merge! :ignore_types => [:boolean, :datetime]
14
+
15
+ columns.each do |column|
16
+
17
+ next if options[:except].include?(column.name)
18
+ next if options[:ignore_types].include?(column.type)
19
+
12
20
  validates_length_of column.name, :maximum => column.limit, :allow_blank => true if column.limit
13
21
  end
14
22
  end
@@ -1,3 +1,3 @@
1
1
  module AutoValidations
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -52,12 +52,50 @@ end
52
52
 
53
53
  class WithExceptTest < Test::Unit::TestCase
54
54
  def setup
55
- Saiyajin.auto_length_validation :except => 'name'
56
- @saiyajin = Saiyajin.new :name => 'Goku the super saiyajin in the earth', :age => 5, :super => true
55
+ Saiyajin.auto_length_validation :except => 'name'
57
56
  end
58
57
 
59
- def test_should_be_valid
60
- assert @saiyajin.valid?
58
+ def test_should_not_include_validator_on_name
59
+ assert_equal Saiyajin.validators_on(:name).map(&:kind).include?(:lenght), false
61
60
  end
61
+
62
+ def test_should_include_validation_on_age
63
+ assert Saiyajin.validators_on(:age).map(&:kind).include?(:length)
64
+ end
65
+ end
66
+
67
+ class WithExceptAsArrayTest < Test::Unit::TestCase
68
+ def setup
69
+ Namek.auto_length_validation :except => ['name', :master]
70
+ end
71
+
72
+ def test_should_not_include_validator_on_name
73
+ assert_equal Namek.validators_on(:name).map(&:kind).include?(:lenght), false
74
+ end
75
+
76
+ def test_should_not_include_validation_on_master
77
+ assert_equal Namek.validators_on(:master).map(&:kind).include?(:length), false
78
+ end
79
+
80
+ def test_should_include_validation_on_qi
81
+ assert Namek.validators_on(:qi).map(&:kind).include?(:length)
82
+ end
62
83
  end
63
84
 
85
+ class IgnoreFieldsTest < Test::Unit::TestCase
86
+ def setup
87
+ Saiyajin.auto_length_validation
88
+ end
89
+
90
+ def test_should_not_include_validation_on_boolean_file
91
+ assert_equal Saiyajin.validators_on(:super).map(&:kind).include?(:length), false
92
+ end
93
+
94
+ def test_should_include_validation_on_text_file
95
+ assert Saiyajin.validators_on(:name).map(&:kind).include?(:length)
96
+ end
97
+ end
98
+
99
+
100
+
101
+
@@ -3,3 +3,6 @@ end
3
3
 
4
4
  class Saiyajin < ActiveRecord::Base
5
5
  end
6
+
7
+ class Namek < ActiveRecord::Base
8
+ end
@@ -10,4 +10,11 @@ ActiveRecord::Schema.define do
10
10
  t.boolean :super
11
11
  t.integer :age, :limit => 3
12
12
  end
13
+
14
+ create_table :nameks, :force => true do |t|
15
+ t.string :name, :limit => 3
16
+ t.integer :qi, :limit => 1000
17
+ t.integer :age
18
+ t.string :master, :limit => 10
19
+ end
13
20
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: auto_validations
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease:
4
+ hash: 23
5
+ prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Rodrigo Navarro
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-05-17 00:00:00 -03:00
19
+ date: 2011-05-18 00:00:00 -03:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -100,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
100
  requirements: []
101
101
 
102
102
  rubyforge_project: auto_validations
103
- rubygems_version: 1.5.0
103
+ rubygems_version: 1.3.7
104
104
  signing_key:
105
105
  specification_version: 3
106
106
  summary: Auto generate validations for your models