has_enum 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/has_enum.gemspec +1 -1
- data/lib/has_enum/active_record.rb +4 -4
- data/spec/has_enum_spec.rb +9 -8
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.3
|
data/has_enum.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{has_enum}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Andreas Korth", "Konstantin Shabanov"]
|
@@ -35,9 +35,9 @@ module HasEnum
|
|
35
35
|
end
|
36
36
|
|
37
37
|
define_method(:"#{attribute}=") do |value|
|
38
|
-
value = value.to_s.insert(0, ':') if symbols
|
39
|
-
|
40
|
-
if values.find{ |val| val == value }
|
38
|
+
value = value.to_s.insert(0, ':') if symbols and value
|
39
|
+
|
40
|
+
if value.nil? or values.find{ |val| val == value }
|
41
41
|
write_attribute(attribute, value.blank? ? nil : value.to_s)
|
42
42
|
else
|
43
43
|
errors.add(:"#{attribute}", "#{value} is not in enum")
|
@@ -45,7 +45,7 @@ module HasEnum
|
|
45
45
|
end
|
46
46
|
|
47
47
|
define_method(:"#{attribute}") do
|
48
|
-
if symbols
|
48
|
+
if symbols and read_attribute(attribute.to_sym)
|
49
49
|
read_attribute(attribute.to_sym).tap{|str| str.slice!(0)}.to_sym
|
50
50
|
else
|
51
51
|
read_attribute(attribute.to_sym)
|
data/spec/has_enum_spec.rb
CHANGED
@@ -17,6 +17,11 @@ describe HasEnum::ActiveRecord do
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
+
it "should accept nil value for the attribute" do
|
21
|
+
@model.category = nil
|
22
|
+
@model.category.should be_nil
|
23
|
+
end
|
24
|
+
|
20
25
|
it "should reject non enum values for the attribute" do
|
21
26
|
@model.category = 'objects'
|
22
27
|
@model.errors[:category].size.should eql(1)
|
@@ -71,14 +76,10 @@ describe HasEnum::ActiveRecord do
|
|
71
76
|
@model.status = :pending
|
72
77
|
@model.should be_pending
|
73
78
|
end
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
['bar', 'barcode', 'bargain'].each do |value|
|
79
|
-
@model.foo = value
|
80
|
-
@model.should be_valid
|
81
|
-
end
|
79
|
+
|
80
|
+
it "should accept nil value for the attribute" do
|
81
|
+
@model.status = nil
|
82
|
+
@model.status.should be_nil
|
82
83
|
end
|
83
84
|
end
|
84
85
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
8
|
+
- 3
|
9
|
+
version: 0.3.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Andreas Korth
|
@@ -221,7 +221,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
221
221
|
requirements:
|
222
222
|
- - ">="
|
223
223
|
- !ruby/object:Gem::Version
|
224
|
-
hash:
|
224
|
+
hash: 4222407025214625140
|
225
225
|
segments:
|
226
226
|
- 0
|
227
227
|
version: "0"
|