has_enum 0.8.2 → 0.9.0

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.
@@ -17,6 +17,18 @@ module HasEnum::ClassMethods
17
17
  has_enum?(enum) && serialized_attributes[enum.to_s] == Array
18
18
  end
19
19
 
20
+ def has_enums
21
+ columns_hash.each do | column_name, column |
22
+ if human_attribute_name("#{column_name}_enum", :count => nil).is_a? Hash
23
+ if column.type == :text
24
+ has_enum column_name, :multiple => true
25
+ else
26
+ has_enum column_name
27
+ end
28
+ end
29
+ end
30
+ end
31
+
20
32
  def has_enum(*params)
21
33
  options = params.extract_options!
22
34
  options.assert_valid_keys(:query_methods, :scopes, :presence, :multiple)
@@ -1,3 +1,3 @@
1
1
  module HasEnum
2
- VERSION = "0.8.2"
2
+ VERSION = "0.9.0"
3
3
  end
@@ -77,6 +77,15 @@ describe HasEnum do
77
77
  TestModel.human_enums[:status][:done].should eql "Завершено"
78
78
  end
79
79
 
80
+ it "should autodetect all enums if has_enums called" do
81
+ AnotherModel.should be_has_multiple_enum(:speed)
82
+
83
+ AnotherModel.should_not be_has_multiple_enum(:size)
84
+ AnotherModel.should be_has_enum(:size)
85
+
86
+ AnotherModel.should_not be_has_enum(:status)
87
+ end
88
+
80
89
  describe "category enum" do
81
90
  it "should accept string enum values" do
82
91
  %w(stuff things misc).each do |value|
data/spec/ru.yml CHANGED
@@ -16,3 +16,4 @@ ru:
16
16
  pending: "На рассмотрении"
17
17
  failed: "Обработано с ошибкой"
18
18
  done: "Завершено"
19
+
data/spec/spec_helper.rb CHANGED
@@ -19,6 +19,12 @@ ActiveRecord::Schema.define(:version => 0) do
19
19
  t.string "speed"
20
20
  end
21
21
 
22
+ create_table "another_models", :force => true do | t |
23
+ t.string "status"
24
+ t.string "size"
25
+ t.text "speed"
26
+ end
27
+
22
28
  create_table "schema_info", :id => false, :force => true do |t|
23
29
  t.integer "version"
24
30
  end
data/spec/test_model.rb CHANGED
@@ -12,3 +12,6 @@ class TestModel < ActiveRecord::Base
12
12
 
13
13
  end
14
14
 
15
+ class AnotherModel < ActiveRecord::Base
16
+ has_enums
17
+ end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 8
8
- - 2
9
- version: 0.8.2
7
+ - 9
8
+ - 0
9
+ version: 0.9.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Andreas Korth
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-04-18 00:00:00 +07:00
19
+ date: 2011-04-19 00:00:00 +07:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency