enumerated_field 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/enumerated_field.rb +5 -1
- data/lib/enumerated_field/version.rb +1 -1
- data/test/enumerated_field_test.rb +5 -0
- metadata +4 -4
data/lib/enumerated_field.rb
CHANGED
@@ -36,7 +36,11 @@ module EnumeratedField
|
|
36
36
|
class_eval do
|
37
37
|
|
38
38
|
unless options[:validate] == false
|
39
|
-
|
39
|
+
valid_values = values_hash.keys
|
40
|
+
valid_values += values_hash.keys.map do |key|
|
41
|
+
key.is_a?(String) ? key.to_sym : key.to_s
|
42
|
+
end
|
43
|
+
validates field_name, :inclusion => valid_values,
|
40
44
|
:allow_nil => options[:allow_nil], :allow_blank => options[:allow_blank]
|
41
45
|
end
|
42
46
|
|
@@ -127,5 +127,10 @@ class EnumeratedFieldTest < Test::Unit::TestCase
|
|
127
127
|
apple = Apple.new(:orange, :macintosh)
|
128
128
|
assert !apple.respond_to?(:valid)
|
129
129
|
end
|
130
|
+
|
131
|
+
should 'accept valid string equivalent to symbol in list' do
|
132
|
+
banana = Banana.new('chiquita', :green)
|
133
|
+
assert banana.valid?, banana.errors[:brand][0]
|
134
|
+
end
|
130
135
|
end
|
131
136
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enumerated_field
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Luke Ludwig
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-07-
|
18
|
+
date: 2011-07-27 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|