has_enum 0.8.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/has_enum/class_methods.rb +4 -0
- data/lib/has_enum/formtastic.rb +6 -3
- data/lib/has_enum/version.rb +1 -1
- data/spec/has_enum_spec.rb +3 -1
- metadata +2 -2
@@ -13,6 +13,10 @@ module HasEnum::ClassMethods
|
|
13
13
|
enums.include? enum
|
14
14
|
end
|
15
15
|
|
16
|
+
def has_multiple_enum?(enum)
|
17
|
+
has_enum?(enum) && serialized_attributes[enum.to_s] == Array
|
18
|
+
end
|
19
|
+
|
16
20
|
def has_enum(*params)
|
17
21
|
options = params.extract_options!
|
18
22
|
options.assert_valid_keys(:query_methods, :scopes, :presence, :multiple)
|
data/lib/has_enum/formtastic.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
Formtastic::SemanticFormBuilder.class_eval do
|
2
2
|
|
3
3
|
def enum_input(method, options = {})
|
4
|
-
options.merge! :collection => object.class.values_for_select_tag(method)
|
5
|
-
|
6
|
-
|
4
|
+
options.merge! :collection => object.class.values_for_select_tag(method)
|
5
|
+
if object.class.has_mutliple_enum? method
|
6
|
+
check_boxes_input method, options
|
7
|
+
else
|
8
|
+
select_input method, options.merge(:wrapper_html => {:class => :enum})
|
9
|
+
end
|
7
10
|
end
|
8
11
|
|
9
12
|
def default_input_type_with_enum(method, options={})
|
data/lib/has_enum/version.rb
CHANGED
data/spec/has_enum_spec.rb
CHANGED
@@ -42,9 +42,11 @@ describe HasEnum do
|
|
42
42
|
}.with_indifferent_access
|
43
43
|
end
|
44
44
|
|
45
|
-
it "should have has_enum?
|
45
|
+
it "should have has_enum? and has_multiple_enum? methods" do
|
46
46
|
TestModel.should be_has_enum(:state)
|
47
47
|
TestModel.should_not be_has_enum(:some_attribute)
|
48
|
+
TestModel.should be_has_multiple_enum(:speed)
|
49
|
+
TestModel.should_not be_has_multiple_enum(:status)
|
48
50
|
end
|
49
51
|
|
50
52
|
it "should return values by name symbol" do
|