auto_validations 0.0.2 → 0.0.3
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/lib/auto_validations.rb +3 -2
- data/lib/auto_validations/version.rb +1 -1
- data/test/auto_length_test.rb +12 -0
- data/test/support/models.rb +3 -0
- data/test/support/schema.rb +6 -0
- metadata +4 -4
data/lib/auto_validations.rb
CHANGED
@@ -6,8 +6,9 @@ module AutoValidations
|
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
|
8
8
|
module ClassMethods
|
9
|
-
def auto_length_validation
|
10
|
-
|
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
|
data/test/auto_length_test.rb
CHANGED
@@ -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
|
+
|
data/test/support/models.rb
CHANGED
data/test/support/schema.rb
CHANGED
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:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
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-
|
19
|
+
date: 2011-05-17 00:00:00 -03:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|