auto_validations 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,8 +6,9 @@ module AutoValidations
6
6
  extend ActiveSupport::Concern
7
7
 
8
8
  module ClassMethods
9
- def auto_length_validation
10
- columns.each do |column|
9
+ def auto_length_validation(options = {})
10
+ options.reverse_merge! :except => []
11
+ columns.select { |c| !options[:except].include?(c.name) }.each do |column|
11
12
  validates_length_of column.name, :maximum => column.limit, :allow_blank => true if column.limit
12
13
  end
13
14
  end
@@ -1,3 +1,3 @@
1
1
  module AutoValidations
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -49,3 +49,15 @@ class AllowBlankTest < Test::Unit::TestCase
49
49
  assert_nothing_thrown { @android.valid? }
50
50
  end
51
51
  end
52
+
53
+ class WithExceptTest < Test::Unit::TestCase
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
57
+ end
58
+
59
+ def test_should_be_valid
60
+ assert @saiyajin.valid?
61
+ end
62
+ end
63
+
@@ -1,2 +1,5 @@
1
1
  class Android < ActiveRecord::Base
2
2
  end
3
+
4
+ class Saiyajin < ActiveRecord::Base
5
+ end
@@ -4,4 +4,10 @@ ActiveRecord::Schema.define do
4
4
  t.text :description, :limit => 40
5
5
  t.integer :number, :limit => 2
6
6
  end
7
+
8
+ create_table :saiyajins, :force => true do |t|
9
+ t.string :name, :limit => 10
10
+ t.boolean :super
11
+ t.integer :age, :limit => 3
12
+ end
7
13
  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: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
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-12 00:00:00 -03:00
19
+ date: 2011-05-17 00:00:00 -03:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency