enumerize 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -1
- data/.travis.yml +4 -0
- data/CHANGELOG.md +13 -0
- data/Gemfile.rails4 +14 -0
- data/README.md +27 -1
- data/enumerize.gemspec +2 -0
- data/lib/enumerize.rb +6 -3
- data/lib/enumerize/activerecord.rb +23 -0
- data/lib/enumerize/attribute.rb +25 -2
- data/lib/enumerize/base.rb +8 -12
- data/lib/enumerize/form_helper.rb +17 -21
- data/lib/enumerize/integrations/rails_admin.rb +16 -0
- data/lib/enumerize/module.rb +31 -0
- data/lib/enumerize/module_attributes.rb +0 -1
- data/lib/enumerize/predicates.rb +1 -1
- data/lib/enumerize/version.rb +1 -1
- data/test/activerecord_test.rb +81 -2
- data/test/attribute_test.rb +31 -4
- data/test/base_test.rb +7 -0
- data/test/rails_admin_test.rb +18 -0
- data/test/support/mock_controller.rb +5 -1
- data/test/test_helper.rb +10 -0
- metadata +18 -32
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
## 0.6.0 (May 16, 2013) ##
|
2
|
+
|
3
|
+
### enhancements
|
4
|
+
* Use inclusion error message for invalid values (by [@lest](https://github.com/lest))
|
5
|
+
* Add `:only` and `except` options to the `Attribute#options` method. (by [@thehappycoder](https://github.com/thehappycoder))
|
6
|
+
* ActiveRecord scopes. (by [@lest](https://github.com/lest), [@banyan](https://github.com/banyan) and [@nashby](https://github.com/nashby))
|
7
|
+
* Support for RailsAdmin (by [@drewda](https://github.com/drewda))
|
8
|
+
|
9
|
+
### bug fix
|
10
|
+
* Return correct default value for enumerized attribute using `default_scope` with generated scope [@nashby](https://github.com/nashby)
|
11
|
+
* Allow either key or value as valid (by [aghull](https://github.com/aghull) and [@lest](https://github.com/lest))
|
12
|
+
* Use default enum value from db column (by [@lest](https://github.com/lest))
|
13
|
+
|
1
14
|
## 0.5.1 (December 10, 2012) ##
|
2
15
|
|
3
16
|
### bug fix
|
data/Gemfile.rails4
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
|
5
|
+
gem 'rake'
|
6
|
+
gem 'minitest', '~> 4.1'
|
7
|
+
|
8
|
+
gem 'activerecord', '4.0.0.rc1'
|
9
|
+
gem 'sqlite3', :platform => [:ruby, :mswin, :mingw]
|
10
|
+
gem 'activerecord-jdbcsqlite3-adapter', :platform => :jruby
|
11
|
+
|
12
|
+
gem 'mongoid', github: 'mongoid/mongoid'
|
13
|
+
gem 'simple_form', '3.0.0.beta1'
|
14
|
+
gem 'formtastic', github: 'justinfrench/formtastic'
|
data/README.md
CHANGED
@@ -85,7 +85,7 @@ get all values for enumerized attribute:
|
|
85
85
|
User.sex.values # or User.enumerized_attributes[:sex].values
|
86
86
|
```
|
87
87
|
|
88
|
-
use it with forms:
|
88
|
+
use it with forms (it supports `:only` and `:except` options):
|
89
89
|
|
90
90
|
```erb
|
91
91
|
<%= form_for @user do |f| %>
|
@@ -164,6 +164,25 @@ class User < ActiveRecord::Base
|
|
164
164
|
end
|
165
165
|
```
|
166
166
|
|
167
|
+
ActiveRecord scopes:
|
168
|
+
|
169
|
+
```ruby
|
170
|
+
class User < ActiveRecord::Base
|
171
|
+
extend Enumerize
|
172
|
+
enumerize :sex, :in => [:male, :female], scope: true
|
173
|
+
enumerize :status, :in => { active: 1, blocked: 2 }, scope: :having_status
|
174
|
+
end
|
175
|
+
|
176
|
+
User.with_sex(:female)
|
177
|
+
# SELECT "users".* FROM "users" WHERE "users"."sex" IN ('female')
|
178
|
+
|
179
|
+
User.without_sex(:male)
|
180
|
+
# SELECT "users".* FROM "users" WHERE "users"."sex" NOT IN ('male')
|
181
|
+
|
182
|
+
User.having_status(:blocked).with_sex(:male, :female)
|
183
|
+
# SELECT "users".* FROM "users" WHERE "users"."status" IN (2) AND "users"."sex" IN ('male', 'female')
|
184
|
+
```
|
185
|
+
|
167
186
|
Array-like attributes with plain ruby objects:
|
168
187
|
|
169
188
|
```ruby
|
@@ -225,6 +244,13 @@ and if you want it as radio buttons:
|
|
225
244
|
<% end %>
|
226
245
|
```
|
227
246
|
|
247
|
+
### Other Integrations
|
248
|
+
|
249
|
+
Enumerize integrates with the following automatically:
|
250
|
+
|
251
|
+
* [RailsAdmin](https://github.com/sferik/rails_admin/)
|
252
|
+
|
253
|
+
|
228
254
|
## Contributing
|
229
255
|
|
230
256
|
1. Fork it
|
data/enumerize.gemspec
CHANGED
data/lib/enumerize.rb
CHANGED
@@ -7,6 +7,7 @@ module Enumerize
|
|
7
7
|
autoload :Value, 'enumerize/value'
|
8
8
|
autoload :Set, 'enumerize/set'
|
9
9
|
autoload :Base, 'enumerize/base'
|
10
|
+
autoload :Module, 'enumerize/module'
|
10
11
|
autoload :ActiveRecord, 'enumerize/activerecord'
|
11
12
|
autoload :Predicates, 'enumerize/predicates'
|
12
13
|
autoload :ModuleAttributes, 'enumerize/module_attributes'
|
@@ -19,12 +20,14 @@ module Enumerize
|
|
19
20
|
def self.extended(base)
|
20
21
|
base.send :include, Enumerize::Base
|
21
22
|
base.extend Enumerize::Predicates
|
23
|
+
base.extend Enumerize::ActiveRecord
|
22
24
|
|
23
|
-
if defined?(::
|
24
|
-
|
25
|
+
if defined?(::RailsAdmin)
|
26
|
+
require 'enumerize/integrations/rails_admin'
|
27
|
+
base.extend Enumerize::Integrations::RailsAdmin
|
25
28
|
end
|
26
29
|
|
27
|
-
if Module === base
|
30
|
+
if ::Module === base
|
28
31
|
base.extend Enumerize::Base::ClassMethods
|
29
32
|
base.extend Enumerize::ModuleAttributes
|
30
33
|
end
|
@@ -2,6 +2,29 @@ require 'active_support/concern'
|
|
2
2
|
|
3
3
|
module Enumerize
|
4
4
|
module ActiveRecord
|
5
|
+
def enumerize(name, options={})
|
6
|
+
super
|
5
7
|
|
8
|
+
if options[:scope]
|
9
|
+
_enumerize_module.dependent_eval do
|
10
|
+
if defined?(::ActiveRecord::Base) && self < ::ActiveRecord::Base
|
11
|
+
scope_name = options[:scope] == true ? "with_#{name}" : options[:scope]
|
12
|
+
define_singleton_method scope_name do |*values|
|
13
|
+
values = values.map { |value| enumerized_attributes[name].find_value(value).value }
|
14
|
+
values = values.first if values.size == 1
|
15
|
+
|
16
|
+
where(name => values)
|
17
|
+
end
|
18
|
+
|
19
|
+
if options[:scope] == true
|
20
|
+
define_singleton_method "without_#{name}" do |*values|
|
21
|
+
values = values.map { |value| enumerized_attributes[name].find_value(value).value }
|
22
|
+
where(arel_table[name].not_in(values))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
6
29
|
end
|
7
30
|
end
|
data/lib/enumerize/attribute.rb
CHANGED
@@ -27,8 +27,25 @@ module Enumerize
|
|
27
27
|
@klass.model_name.i18n_key if @klass.respond_to?(:model_name)
|
28
28
|
end
|
29
29
|
|
30
|
-
def options
|
31
|
-
|
30
|
+
def options(options = {})
|
31
|
+
values = if options.empty?
|
32
|
+
@values
|
33
|
+
else
|
34
|
+
raise ArgumentError, 'Options cannot have both :only and :except' if options[:only] && options[:except]
|
35
|
+
|
36
|
+
only = Array(options[:only]).map(&:to_s)
|
37
|
+
except = Array(options[:except]).map(&:to_s)
|
38
|
+
|
39
|
+
@values.reject do |value|
|
40
|
+
if options[:only]
|
41
|
+
!only.include?(value)
|
42
|
+
elsif options[:except]
|
43
|
+
except.include?(value)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
values.map { |v| [v.text, v.to_s] }
|
32
49
|
end
|
33
50
|
|
34
51
|
def define_methods!(mod)
|
@@ -36,6 +53,8 @@ module Enumerize
|
|
36
53
|
def #{name}
|
37
54
|
if defined?(super)
|
38
55
|
self.class.enumerized_attributes[:#{name}].find_value(super)
|
56
|
+
elsif respond_to?(:read_attribute)
|
57
|
+
self.class.enumerized_attributes[:#{name}].find_value(read_attribute(:#{name}))
|
39
58
|
else
|
40
59
|
if defined?(@#{name})
|
41
60
|
self.class.enumerized_attributes[:#{name}].find_value(@#{name})
|
@@ -53,6 +72,8 @@ module Enumerize
|
|
53
72
|
|
54
73
|
if defined?(super)
|
55
74
|
super allowed_value_or_nil
|
75
|
+
elsif respond_to?(:write_attribute, true)
|
76
|
+
write_attribute '#{name}', allowed_value_or_nil
|
56
77
|
else
|
57
78
|
@#{name} = allowed_value_or_nil
|
58
79
|
end
|
@@ -92,6 +113,8 @@ module Enumerize
|
|
92
113
|
|
93
114
|
if defined?(super)
|
94
115
|
super string_values
|
116
|
+
elsif respond_to?(:write_attribute, true)
|
117
|
+
write_attribute '#{name}', string_values
|
95
118
|
else
|
96
119
|
@#{name} = string_values
|
97
120
|
end
|
data/lib/enumerize/base.rb
CHANGED
@@ -12,6 +12,8 @@ module Enumerize
|
|
12
12
|
|
13
13
|
module ClassMethods
|
14
14
|
def enumerize(name, options={})
|
15
|
+
raise ArgumentError, "Enumerized attribute #{name} is already defined" if enumerized_attributes[name]
|
16
|
+
|
15
17
|
attr = Attribute.new(self, name, options)
|
16
18
|
enumerized_attributes << attr
|
17
19
|
|
@@ -39,14 +41,8 @@ module Enumerize
|
|
39
41
|
|
40
42
|
def _enumerize_module
|
41
43
|
@_enumerize_module ||= begin
|
42
|
-
mod = Module.new
|
43
|
-
@_class_methods = Module.new
|
44
|
-
class << self
|
45
|
-
attr_reader :_class_methods
|
46
|
-
end
|
47
|
-
end
|
44
|
+
mod = Module.new
|
48
45
|
include mod
|
49
|
-
extend mod._class_methods
|
50
46
|
mod
|
51
47
|
end
|
52
48
|
end
|
@@ -55,7 +51,9 @@ module Enumerize
|
|
55
51
|
def initialize(*)
|
56
52
|
super
|
57
53
|
self.class.enumerized_attributes.each do |attr|
|
58
|
-
public_send(
|
54
|
+
if !public_send(attr.name) && !_enumerized_values_for_validation.key?(attr.name)
|
55
|
+
public_send("#{attr.name}=", attr.default_value)
|
56
|
+
end
|
59
57
|
end
|
60
58
|
end
|
61
59
|
|
@@ -78,12 +76,10 @@ module Enumerize
|
|
78
76
|
value = read_attribute_for_validation(attr.name)
|
79
77
|
next if value.blank?
|
80
78
|
|
81
|
-
allowed = attr.values
|
82
|
-
|
83
79
|
if attr.kind_of? Multiple
|
84
|
-
errors.add attr.name unless value.respond_to?(:all?) && value.all? { |v| v.blank? ||
|
80
|
+
errors.add attr.name unless value.respond_to?(:all?) && value.all? { |v| v.blank? || attr.find_value(v) }
|
85
81
|
else
|
86
|
-
errors.add attr.name unless
|
82
|
+
errors.add attr.name, :inclusion unless attr.find_value(value)
|
87
83
|
end
|
88
84
|
end
|
89
85
|
end
|
@@ -1,25 +1,21 @@
|
|
1
1
|
# backport of https://github.com/rails/rails/commit/3be9e8a0c2187744b6c9879ca2836cef5ebed693
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
else
|
20
|
-
value.to_i != 0
|
21
|
-
end
|
22
|
-
end
|
2
|
+
if defined?(ActionView::Helpers::InstanceTag)
|
3
|
+
ActionView::Helpers::InstanceTag.class_eval do
|
4
|
+
def self.check_box_checked?(value, checked_value)
|
5
|
+
case value
|
6
|
+
when TrueClass, FalseClass
|
7
|
+
value
|
8
|
+
when NilClass
|
9
|
+
false
|
10
|
+
when Integer
|
11
|
+
value != 0
|
12
|
+
when String
|
13
|
+
value == checked_value
|
14
|
+
else
|
15
|
+
if value.respond_to?(:include?)
|
16
|
+
value.include?(checked_value)
|
17
|
+
else
|
18
|
+
value.to_i != 0
|
23
19
|
end
|
24
20
|
end
|
25
21
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Enumerize
|
2
|
+
module Integrations
|
3
|
+
module RailsAdmin
|
4
|
+
|
5
|
+
def enumerize(name, options={})
|
6
|
+
super
|
7
|
+
|
8
|
+
_enumerize_module.module_eval <<-RUBY, __FILE__, __LINE__ + 1
|
9
|
+
def #{name}_enum
|
10
|
+
self.class.enumerized_attributes[:#{name}].options
|
11
|
+
end
|
12
|
+
RUBY
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Enumerize
|
2
|
+
class Module < ::Module
|
3
|
+
attr_reader :_class_methods
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
super
|
7
|
+
|
8
|
+
@_class_methods = ::Module.new
|
9
|
+
@_dependents = []
|
10
|
+
@_dependent_evals = []
|
11
|
+
end
|
12
|
+
|
13
|
+
def included(klass)
|
14
|
+
klass.extend _class_methods
|
15
|
+
|
16
|
+
@_dependent_evals.each do |block|
|
17
|
+
klass.instance_eval(&block)
|
18
|
+
end
|
19
|
+
|
20
|
+
@_dependents << klass
|
21
|
+
end
|
22
|
+
|
23
|
+
def dependent_eval(&block)
|
24
|
+
@_dependents.each do |klass|
|
25
|
+
klass.instance_eval(&block)
|
26
|
+
end
|
27
|
+
|
28
|
+
@_dependent_evals << block
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/enumerize/predicates.rb
CHANGED
data/lib/enumerize/version.rb
CHANGED
data/test/activerecord_test.rb
CHANGED
@@ -14,18 +14,42 @@ ActiveRecord::Base.connection.instance_eval do
|
|
14
14
|
t.string :role
|
15
15
|
t.string :name
|
16
16
|
t.string :interests
|
17
|
+
t.string :status
|
18
|
+
t.string :account_type, :default => :basic
|
19
|
+
end
|
20
|
+
|
21
|
+
create_table :documents do |t|
|
22
|
+
t.string :visibility
|
17
23
|
end
|
18
24
|
end
|
19
25
|
|
26
|
+
class BaseEntity < ActiveRecord::Base
|
27
|
+
self.abstract_class = true
|
28
|
+
|
29
|
+
extend Enumerize
|
30
|
+
enumerize :visibility, :in => [:public, :private, :protected], :scope => true, :default => :public
|
31
|
+
end
|
32
|
+
|
33
|
+
class Document < BaseEntity
|
34
|
+
end
|
35
|
+
|
36
|
+
module RoleEnum
|
37
|
+
extend Enumerize
|
38
|
+
enumerize :role, :in => [:user, :admin], :default => :user, scope: :having_role
|
39
|
+
end
|
40
|
+
|
20
41
|
class User < ActiveRecord::Base
|
21
42
|
extend Enumerize
|
43
|
+
include RoleEnum
|
22
44
|
|
23
45
|
enumerize :sex, :in => [:male, :female]
|
24
46
|
|
25
|
-
enumerize :role, :in => [:user, :admin], :default => :user
|
26
|
-
|
27
47
|
serialize :interests, Array
|
28
48
|
enumerize :interests, :in => [:music, :sports, :dancing, :programming], :multiple => true
|
49
|
+
|
50
|
+
enumerize :status, :in => { active: 1, blocked: 2 }, scope: true
|
51
|
+
|
52
|
+
enumerize :account_type, :in => [:basic, :premium]
|
29
53
|
end
|
30
54
|
|
31
55
|
describe Enumerize::ActiveRecord do
|
@@ -58,10 +82,24 @@ describe Enumerize::ActiveRecord do
|
|
58
82
|
User.new.attributes['role'].must_equal 'user'
|
59
83
|
end
|
60
84
|
|
85
|
+
it 'uses default value from db column' do
|
86
|
+
User.new.account_type.must_equal 'basic'
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'has default value with default scope' do
|
90
|
+
UserWithDefaultScope = Class.new(User) do
|
91
|
+
default_scope -> { having_role(:user) }
|
92
|
+
end
|
93
|
+
|
94
|
+
UserWithDefaultScope.new.role.must_equal 'user'
|
95
|
+
UserWithDefaultScope.new.attributes['role'].must_equal 'user'
|
96
|
+
end
|
97
|
+
|
61
98
|
it 'validates inclusion' do
|
62
99
|
user = User.new
|
63
100
|
user.role = 'wrong'
|
64
101
|
user.wont_be :valid?
|
102
|
+
user.errors[:role].must_include 'is not included in the list'
|
65
103
|
end
|
66
104
|
|
67
105
|
it 'validates inclusion on mass assignment' do
|
@@ -127,4 +165,45 @@ describe Enumerize::ActiveRecord do
|
|
127
165
|
user.interests = ['music', '']
|
128
166
|
user.must_be :valid?
|
129
167
|
end
|
168
|
+
|
169
|
+
it 'adds scope' do
|
170
|
+
user_1 = User.create!(status: :active, role: :admin)
|
171
|
+
user_2 = User.create!(status: :blocked)
|
172
|
+
|
173
|
+
User.with_status(:active).must_equal [user_1]
|
174
|
+
User.with_status(:blocked).must_equal [user_2]
|
175
|
+
User.with_status(:active, :blocked).to_set.must_equal [user_1, user_2].to_set
|
176
|
+
|
177
|
+
User.without_status(:active).must_equal [user_2]
|
178
|
+
User.without_status(:active, :blocked).must_equal []
|
179
|
+
|
180
|
+
User.having_role(:admin).must_equal [user_1]
|
181
|
+
end
|
182
|
+
|
183
|
+
it 'allows either key or value as valid' do
|
184
|
+
user_1 = User.new(status: :active)
|
185
|
+
user_2 = User.new(status: 1)
|
186
|
+
user_3 = User.new(status: '1')
|
187
|
+
|
188
|
+
user_1.status.must_equal 'active'
|
189
|
+
user_2.status.must_equal 'active'
|
190
|
+
user_3.status.must_equal 'active'
|
191
|
+
|
192
|
+
user_1.must_be :valid?
|
193
|
+
user_2.must_be :valid?
|
194
|
+
user_3.must_be :valid?
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'supports defining enumerized attributes on abstract class' do
|
198
|
+
document = Document.new
|
199
|
+
document.visibility = :protected
|
200
|
+
document.visibility.must_equal 'protected'
|
201
|
+
end
|
202
|
+
|
203
|
+
it 'supports defining enumerized scopes on abstract class' do
|
204
|
+
document_1 = Document.create!(visibility: :public)
|
205
|
+
document_2 = Document.create!(visibility: :private)
|
206
|
+
|
207
|
+
Document.with_visibility(:public).must_equal [document_1]
|
208
|
+
end
|
130
209
|
end
|
data/test/attribute_test.rb
CHANGED
@@ -19,10 +19,37 @@ describe Enumerize::Attribute do
|
|
19
19
|
attr.name.must_equal :foo
|
20
20
|
end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
describe 'options for select' do
|
23
|
+
it 'returns all options for select' do
|
24
|
+
store_translations(:en, :enumerize => {:foo => {:a => 'a text', :b => 'b text'}}) do
|
25
|
+
build_attr nil, :foo, :in => %w[a b]
|
26
|
+
attr.options.must_equal [['a text', 'a'], ['b text', 'b']]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'returns requested options for select via :only' do
|
31
|
+
store_translations(:en, :enumerize => {:foo => {:a => 'a text', :b => 'b text'}}) do
|
32
|
+
build_attr nil, :foo, :in => %w[a b]
|
33
|
+
attr.options(:only => :a).must_equal [['a text', 'a']]
|
34
|
+
attr.options(:only => [:b]).must_equal [['b text', 'b']]
|
35
|
+
attr.options(:only => []).must_equal []
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'returns requested options for select via :except' do
|
40
|
+
store_translations(:en, :enumerize => {:foo => {:a => 'a text', :b => 'b text'}}) do
|
41
|
+
build_attr nil, :foo, :in => %w[a b]
|
42
|
+
attr.options(:except => :a).must_equal [['b text', 'b']]
|
43
|
+
attr.options(:except => :b).must_equal [['a text', 'a']]
|
44
|
+
attr.options(:except => []).must_equal [['a text', 'a'], ['b text', 'b']]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'does not work with both :only and :except' do
|
49
|
+
store_translations(:en, :enumerize => {:foo => {:a => 'a text', :b => 'b text'}}) do
|
50
|
+
build_attr nil, :foo, :in => %w[a b]
|
51
|
+
proc { attr.options(:except => [], :only => []) }.must_raise ArgumentError
|
52
|
+
end
|
26
53
|
end
|
27
54
|
end
|
28
55
|
|
data/test/base_test.rb
CHANGED
@@ -179,4 +179,11 @@ describe Enumerize::Base do
|
|
179
179
|
object.instance_variable_get(:@foo).must_equal 2
|
180
180
|
object.foo.must_equal 'b'
|
181
181
|
end
|
182
|
+
|
183
|
+
it 'raises exception when enumerized attribute is already defined' do
|
184
|
+
klass.enumerize :foo, in: %w(a b)
|
185
|
+
proc {
|
186
|
+
klass.enumerize :foo, in: %w(a b)
|
187
|
+
}.must_raise ArgumentError
|
188
|
+
end
|
182
189
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class RailsAdminSpec < MiniTest::Spec
|
4
|
+
let(:klass) do
|
5
|
+
Class.new do
|
6
|
+
extend Enumerize
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:object) { klass.new }
|
11
|
+
|
12
|
+
it 'defines enum method' do
|
13
|
+
store_translations(:en, :enumerize => {:foo => {:a => 'a text', :b => 'b text'}}) do
|
14
|
+
klass.enumerize(:foo, in: [:a, :b])
|
15
|
+
object.foo_enum.must_equal [['a text', 'a'], ['b text', 'b']]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'minitest/autorun'
|
2
2
|
require 'minitest/spec'
|
3
3
|
require 'active_support/core_ext/kernel/reporting'
|
4
|
+
require 'active_model'
|
4
5
|
|
5
6
|
$VERBOSE=true
|
6
7
|
|
@@ -12,6 +13,15 @@ module SimpleForm
|
|
12
13
|
end
|
13
14
|
end
|
14
15
|
|
16
|
+
module Formtastic
|
17
|
+
module Rails
|
18
|
+
VERSION = ActiveSupport::VERSION
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
module RailsAdmin
|
23
|
+
end
|
24
|
+
|
15
25
|
require 'enumerize'
|
16
26
|
|
17
27
|
Dir["#{File.dirname(__FILE__)}/support/*.rb"].each do |file|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enumerize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,24 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-05-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
|
16
|
-
version_requirements: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
17
|
- - ! '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '3.2'
|
22
|
-
prerelease: false
|
23
|
-
name: activesupport
|
24
|
-
requirement: !ruby/object:Gem::Requirement
|
25
20
|
none: false
|
21
|
+
type: :runtime
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
24
|
- - ! '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '3.2'
|
27
|
+
none: false
|
28
|
+
prerelease: false
|
29
|
+
name: activesupport
|
30
30
|
description: Enumerated attributes with I18n and ActiveRecord/Mongoid support
|
31
31
|
email: team@brainspec.com
|
32
32
|
executables: []
|
@@ -37,6 +37,7 @@ files:
|
|
37
37
|
- .travis.yml
|
38
38
|
- CHANGELOG.md
|
39
39
|
- Gemfile
|
40
|
+
- Gemfile.rails4
|
40
41
|
- MIT-LICENSE
|
41
42
|
- README.md
|
42
43
|
- Rakefile
|
@@ -49,6 +50,8 @@ files:
|
|
49
50
|
- lib/enumerize/form_helper.rb
|
50
51
|
- lib/enumerize/hooks/formtastic.rb
|
51
52
|
- lib/enumerize/hooks/simple_form.rb
|
53
|
+
- lib/enumerize/integrations/rails_admin.rb
|
54
|
+
- lib/enumerize/module.rb
|
52
55
|
- lib/enumerize/module_attributes.rb
|
53
56
|
- lib/enumerize/predicates.rb
|
54
57
|
- lib/enumerize/set.rb
|
@@ -63,6 +66,7 @@ files:
|
|
63
66
|
- test/mongoid_test.rb
|
64
67
|
- test/multiple_test.rb
|
65
68
|
- test/predicates_test.rb
|
69
|
+
- test/rails_admin_test.rb
|
66
70
|
- test/set_test.rb
|
67
71
|
- test/simple_form_test.rb
|
68
72
|
- test/support/mock_controller.rb
|
@@ -76,42 +80,24 @@ rdoc_options: []
|
|
76
80
|
require_paths:
|
77
81
|
- lib
|
78
82
|
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
-
none: false
|
80
83
|
requirements:
|
81
84
|
- - ! '>='
|
82
85
|
- !ruby/object:Gem::Version
|
83
|
-
|
84
|
-
- 0
|
85
|
-
hash: -178434692500399788
|
86
|
-
version: '0'
|
87
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
version: 1.9.3
|
88
87
|
none: false
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
89
|
requirements:
|
90
90
|
- - ! '>='
|
91
91
|
- !ruby/object:Gem::Version
|
92
|
+
hash: -277888819637979361
|
93
|
+
version: '0'
|
92
94
|
segments:
|
93
95
|
- 0
|
94
|
-
|
95
|
-
version: '0'
|
96
|
+
none: false
|
96
97
|
requirements: []
|
97
98
|
rubyforge_project:
|
98
99
|
rubygems_version: 1.8.23
|
99
100
|
signing_key:
|
100
101
|
specification_version: 3
|
101
102
|
summary: Enumerated attributes with I18n and ActiveRecord/Mongoid support
|
102
|
-
test_files:
|
103
|
-
- test/activerecord_test.rb
|
104
|
-
- test/attribute_map_test.rb
|
105
|
-
- test/attribute_test.rb
|
106
|
-
- test/base_test.rb
|
107
|
-
- test/formtastic_test.rb
|
108
|
-
- test/module_attributes_test.rb
|
109
|
-
- test/mongoid_test.rb
|
110
|
-
- test/multiple_test.rb
|
111
|
-
- test/predicates_test.rb
|
112
|
-
- test/set_test.rb
|
113
|
-
- test/simple_form_test.rb
|
114
|
-
- test/support/mock_controller.rb
|
115
|
-
- test/support/view_test_helper.rb
|
116
|
-
- test/test_helper.rb
|
117
|
-
- test/value_test.rb
|
103
|
+
test_files: []
|