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.
@@ -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)
@@ -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
- :wrapper_html => {:class => :enum}
6
- select_input method, options
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={})
@@ -1,3 +1,3 @@
1
1
  module HasEnum
2
- VERSION = "0.8.0"
2
+ VERSION = "0.8.1"
3
3
  end
@@ -42,9 +42,11 @@ describe HasEnum do
42
42
  }.with_indifferent_access
43
43
  end
44
44
 
45
- it "should have has_enum? method" do
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
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 8
8
- - 0
9
- version: 0.8.0
8
+ - 1
9
+ version: 0.8.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Andreas Korth