iron-enum 1.0.3 → 1.0.4
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/History.txt +4 -0
- data/Version.txt +1 -1
- data/lib/iron/enum/attr_support.rb +3 -1
- data/spec/enum/model_spec.rb +8 -0
- metadata +1 -1
data/History.txt
CHANGED
data/Version.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.4
|
@@ -41,7 +41,8 @@ module Enum
|
|
41
41
|
#
|
42
42
|
# User.with_user_type(UserType::MEMBER) => scope returning a relation selecting User instances where user_type's value == UserType::MEMBER
|
43
43
|
#
|
44
|
-
# In addition, enum attributes will show up in #inspect output as e.g. UserType::GUEST instead of 0.
|
44
|
+
# In addition, enum attributes will show up in #inspect output as e.g. UserType::GUEST instead of 0. Enum attributes will also generate an
|
45
|
+
# automatic inclusion validation to ensure that the attribute never ends up being an invalid value.
|
45
46
|
module AttrSupport
|
46
47
|
|
47
48
|
# Call with enum_attr :field => Enum
|
@@ -109,6 +110,7 @@ module Enum
|
|
109
110
|
# Override default setter to allow setting an enum attribute via key
|
110
111
|
class_eval <<-eos, __FILE__, __LINE__ + 1
|
111
112
|
def #{attr_field}=(val)
|
113
|
+
val = nil if val.is_a?(String) && val.empty?
|
112
114
|
write_attribute(:#{attr_field}, #{enum_klass}.value(val))
|
113
115
|
end
|
114
116
|
eos
|
data/spec/enum/model_spec.rb
CHANGED
@@ -91,5 +91,13 @@ describe Enum do
|
|
91
91
|
@test.should be_valid
|
92
92
|
end
|
93
93
|
|
94
|
+
it 'should support string values' do
|
95
|
+
@test.enum_field = '2'
|
96
|
+
@test.enum_field.should == 2
|
97
|
+
@test.enum_field = ''
|
98
|
+
@test.enum_field.should be_nil
|
99
|
+
expect { @test.enum_field = '1notreally' }.to raise_error
|
100
|
+
end
|
101
|
+
|
94
102
|
end
|
95
103
|
end
|