enumerize 1.1.1 → 2.0.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.
- checksums.yaml +4 -4
- data/.travis.yml +10 -17
- data/CHANGELOG.md +21 -0
- data/Gemfile +3 -2
- data/Gemfile.global +0 -1
- data/Gemfile.mongo_mapper +2 -1
- data/Gemfile.rails42 +6 -0
- data/README.md +14 -1
- data/enumerize.gemspec +1 -0
- data/lib/enumerize/activerecord.rb +17 -2
- data/lib/enumerize/attribute.rb +1 -1
- data/lib/enumerize/base.rb +21 -25
- data/lib/enumerize/hooks/formtastic.rb +3 -8
- data/lib/enumerize/hooks/sequel_dataset.rb +4 -8
- data/lib/enumerize/hooks/simple_form.rb +5 -11
- data/lib/enumerize/hooks/uniqueness.rb +3 -8
- data/lib/enumerize/integrations/rspec/matcher.rb +1 -1
- data/lib/enumerize/value.rb +3 -3
- data/lib/enumerize/version.rb +1 -1
- data/test/activerecord_test.rb +85 -0
- data/test/base_test.rb +2 -2
- data/test/mongoid_test.rb +7 -0
- metadata +6 -5
- data/Gemfile.rails40 +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1ee47a15b97ca4432e16a29da74e928811cfa59
|
4
|
+
data.tar.gz: 025e85c0386121a06550ed0989bf0b8648b3df3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8df3f6bac28f16da9b07d8104f4e9961491827c7e04932a6449c4f61d19ab7439a31f96c8a702cae340b38ce0ba9aec42ae1e8aea688a6e6aa3a09af9a07c83a
|
7
|
+
data.tar.gz: 25c120a8fbfc07367e8cf498cfba05489cf8d3d6833554422cf70560a2d470a09f56628f08aa7fef95f8d8aef49b5bc1e657c8132fde05ddcf80c74f0af2eacb
|
data/.travis.yml
CHANGED
@@ -1,25 +1,18 @@
|
|
1
1
|
language: ruby
|
2
|
+
sudo: false
|
2
3
|
services:
|
3
4
|
- mongodb
|
4
|
-
before_install:
|
5
|
-
- gem install bundler
|
6
5
|
gemfile:
|
7
6
|
- Gemfile
|
7
|
+
- Gemfile.rails42
|
8
|
+
- Gemfile.mongo_mapper
|
8
9
|
rvm:
|
9
|
-
-
|
10
|
-
- 2.
|
11
|
-
- 2.
|
12
|
-
- 2.2
|
13
|
-
- jruby-19mode
|
10
|
+
- 2.2.5
|
11
|
+
- 2.3.1
|
12
|
+
- jruby-9.1.2.0
|
14
13
|
matrix:
|
15
|
-
|
16
|
-
-
|
17
|
-
|
18
|
-
- rvm: 2.2
|
19
|
-
gemfile: Gemfile.mongo_mapper
|
14
|
+
allow_failures:
|
15
|
+
- gemfile: Gemfile
|
16
|
+
rvm: jruby-9.1.2.0
|
20
17
|
notifications:
|
21
|
-
email:
|
22
|
-
recipients:
|
23
|
-
- lest@brainspec.com
|
24
|
-
- nashby@brainspec.com
|
25
|
-
- dreamfall@brainspec.com
|
18
|
+
email: false
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,27 @@
|
|
4
4
|
|
5
5
|
### bug fix
|
6
6
|
|
7
|
+
## 2.0.0 (August 10, 2016)
|
8
|
+
|
9
|
+
### enhancements
|
10
|
+
|
11
|
+
* Drop support for Ruby older than 2.2. Support only Ruby 2.2+. (by [@nashby](https://github.com/nashby))
|
12
|
+
* Drop support for Rails 4.0 and 4.1. Support only Rails 4.2 and newer. (by [@lest](https://github.com/lest))
|
13
|
+
* Support Rails 5.0. (by [@nashby](https://github.com/nashby) and [@lest](https://github.com/lest))
|
14
|
+
* Allow to pass enumerize values to `ActiveRecord#update_all` (by [@DmitryTsepelev](https://github.com/DmitryTsepelev) and [@ianwhite](https://github.com/ianwhite))
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
User.update_all(status: :blocked)
|
18
|
+
```
|
19
|
+
|
20
|
+
### bug fix
|
21
|
+
|
22
|
+
* Rescue MissingAttributeError on attribute writing. (by [@embs](https://github.com/embs))
|
23
|
+
* Fix presence validation for multiple attributes when the list contains a blank string. (by [@smoriwaki](https://github.com/smoriwaki))
|
24
|
+
* Replace deprecated alias_method_chain with Module#prepend. (by [@koenpunt](https://github.com/koenpunt) and [@akm](https://github.com/akm))
|
25
|
+
* Make it compatible with `globalize` gem. (by [@falm](https://github.com/falm))
|
26
|
+
* Prevent method getter from being called when no default_value is being set. (by [@arjan0307](https://github.com/arjan0307))
|
27
|
+
|
7
28
|
## 1.1.1 (January 25, 2016)
|
8
29
|
|
9
30
|
### bug fix
|
data/Gemfile
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
eval_gemfile('Gemfile.global')
|
2
2
|
|
3
3
|
gem 'minitest', '~> 5.8'
|
4
|
-
gem 'rails', '
|
5
|
-
gem '
|
4
|
+
gem 'rails', '5.0.0', require: false
|
5
|
+
gem 'activerecord-jdbcsqlite3-adapter', github: 'jruby/activerecord-jdbc-adapter', branch: 'rails-5', platform: :jruby
|
6
|
+
gem 'mongoid', github: 'mongodb/mongoid'
|
data/Gemfile.global
CHANGED
data/Gemfile.mongo_mapper
CHANGED
data/Gemfile.rails42
ADDED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Enumerize [](http://travis-ci.org/brainspec/enumerize) [](https://gemnasium.com/brainspec/enumerize)
|
2
2
|
|
3
3
|
Enumerated attributes with I18n and ActiveRecord/Mongoid/MongoMapper/Sequel support
|
4
4
|
|
@@ -180,6 +180,7 @@ user.sex = 'male'
|
|
180
180
|
user.male? # => true
|
181
181
|
user.female? # => false
|
182
182
|
```
|
183
|
+
:warning: If `enumerize` is used with Mongoid, it's not recommended to use `"writer"` as a field value since `writer?` is defined by Mongoid. [See more](https://github.com/brainspec/enumerize/issues/235). :warning:
|
183
184
|
|
184
185
|
Using prefix:
|
185
186
|
|
@@ -284,6 +285,18 @@ get an array of all text values:
|
|
284
285
|
@user.interests.texts # shortcut for @user.interests.map(&:text)
|
285
286
|
```
|
286
287
|
|
288
|
+
Also, the reader method can be overridden, referencing the enumerized attribute value using `super`:
|
289
|
+
|
290
|
+
```ruby
|
291
|
+
def sex
|
292
|
+
if current_user.admin?
|
293
|
+
"Super#{super}"
|
294
|
+
else
|
295
|
+
super
|
296
|
+
end
|
297
|
+
end
|
298
|
+
```
|
299
|
+
|
287
300
|
### SimpleForm
|
288
301
|
|
289
302
|
If you are using SimpleForm gem you don't need to specify input type (`:select` by default) and collection:
|
data/enumerize.gemspec
CHANGED
@@ -4,6 +4,7 @@ require File.expand_path('../lib/enumerize/version', __FILE__)
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
5
|
gem.authors = ["Sergey Nartimov"]
|
6
6
|
gem.email = "team@brainspec.com"
|
7
|
+
gem.licenses = ['MIT']
|
7
8
|
gem.description = %q{Enumerated attributes with I18n and ActiveRecord/Mongoid/MongoMapper support}
|
8
9
|
gem.summary = %q{Enumerated attributes with I18n and ActiveRecord/Mongoid/MongoMapper support}
|
9
10
|
gem.homepage = "https://github.com/brainspec/enumerize"
|
@@ -19,7 +19,7 @@ module Enumerize
|
|
19
19
|
|
20
20
|
module InstanceMethods
|
21
21
|
# https://github.com/brainspec/enumerize/issues/74
|
22
|
-
def write_attribute(attr_name, value)
|
22
|
+
def write_attribute(attr_name, value, *options)
|
23
23
|
if self.class.enumerized_attributes[attr_name]
|
24
24
|
_enumerized_values_for_validation[attr_name.to_s] = value
|
25
25
|
end
|
@@ -31,11 +31,26 @@ module Enumerize
|
|
31
31
|
def becomes(klass)
|
32
32
|
became = super
|
33
33
|
klass.enumerized_attributes.each do |attr|
|
34
|
-
|
34
|
+
# Rescue when column associated to the enum does not exist.
|
35
|
+
begin
|
36
|
+
became.send("#{attr.name}=", send(attr.name))
|
37
|
+
rescue ActiveModel::MissingAttributeError
|
38
|
+
end
|
35
39
|
end
|
36
40
|
|
37
41
|
became
|
38
42
|
end
|
39
43
|
end
|
44
|
+
|
45
|
+
def update_all(updates)
|
46
|
+
if updates.is_a?(Hash)
|
47
|
+
enumerized_attributes.each do |attr|
|
48
|
+
next if updates[attr.name].blank? || attr.kind_of?(Enumerize::Multiple)
|
49
|
+
updates[attr.name] = attr.find_value(updates[attr.name]).value
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
super(updates)
|
54
|
+
end
|
40
55
|
end
|
41
56
|
end
|
data/lib/enumerize/attribute.rb
CHANGED
@@ -174,7 +174,7 @@ module Enumerize
|
|
174
174
|
@#{name} = raw_values
|
175
175
|
end
|
176
176
|
|
177
|
-
_enumerized_values_for_validation['#{name}'] = values.respond_to?(:map) ? values.map(&:to_s) : values
|
177
|
+
_enumerized_values_for_validation['#{name}'] = values.respond_to?(:map) ? values.reject(&:blank?).map(&:to_s) : values
|
178
178
|
|
179
179
|
#{name}
|
180
180
|
end
|
data/lib/enumerize/base.rb
CHANGED
@@ -2,19 +2,11 @@ module Enumerize
|
|
2
2
|
module Base
|
3
3
|
def self.included(base)
|
4
4
|
base.extend ClassMethods
|
5
|
+
base.singleton_class.prepend ClassMethods::Hook
|
5
6
|
|
6
7
|
if base.respond_to?(:validate)
|
7
8
|
base.validate :_validate_enumerized_attributes
|
8
9
|
end
|
9
|
-
|
10
|
-
class << base
|
11
|
-
if (method_defined?(:inherited) || private_method_defined?(:inherited)) && !private_method_defined?(:inherited_without_enumerized)
|
12
|
-
alias_method :inherited_without_enumerized, :inherited
|
13
|
-
private :inherited_without_enumerized
|
14
|
-
end
|
15
|
-
|
16
|
-
alias_method :inherited, :inherited_with_enumerized
|
17
|
-
end
|
18
10
|
end
|
19
11
|
|
20
12
|
module ClassMethods
|
@@ -37,10 +29,10 @@ module Enumerize
|
|
37
29
|
@enumerized_attributes ||= AttributeMap.new
|
38
30
|
end
|
39
31
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
32
|
+
module Hook
|
33
|
+
def inherited(subclass)
|
34
|
+
enumerized_attributes.add_dependant subclass.enumerized_attributes
|
35
|
+
super subclass
|
44
36
|
end
|
45
37
|
end
|
46
38
|
|
@@ -93,22 +85,26 @@ module Enumerize
|
|
93
85
|
|
94
86
|
def _set_default_value_for_enumerized_attributes
|
95
87
|
self.class.enumerized_attributes.each do |attr|
|
96
|
-
if
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
88
|
+
next if attr.default_value.nil?
|
89
|
+
begin
|
90
|
+
if respond_to?(attr.name)
|
91
|
+
attr_value = public_send(attr.name)
|
92
|
+
else
|
93
|
+
next
|
94
|
+
end
|
101
95
|
|
102
|
-
|
96
|
+
value_for_validation = _enumerized_values_for_validation[attr.name.to_s]
|
103
97
|
|
104
|
-
|
105
|
-
|
98
|
+
if (!attr_value || attr_value.empty?) && (!value_for_validation || value_for_validation.empty?)
|
99
|
+
value = attr.default_value
|
106
100
|
|
107
|
-
|
108
|
-
|
109
|
-
|
101
|
+
if value.respond_to?(:call)
|
102
|
+
value = value.arity == 0 ? value.call : value.call(self)
|
103
|
+
end
|
110
104
|
|
111
|
-
|
105
|
+
public_send("#{attr.name}=", value)
|
106
|
+
end
|
107
|
+
rescue ActiveModel::MissingAttributeError
|
112
108
|
end
|
113
109
|
end
|
114
110
|
end
|
@@ -3,13 +3,8 @@ require 'active_support/concern'
|
|
3
3
|
module Enumerize
|
4
4
|
module Hooks
|
5
5
|
module FormtasticFormBuilderExtension
|
6
|
-
extend ActiveSupport::Concern
|
7
6
|
|
8
|
-
|
9
|
-
alias_method_chain :input, :enumerize
|
10
|
-
end
|
11
|
-
|
12
|
-
def input_with_enumerize(method, options={})
|
7
|
+
def input(method, options={})
|
13
8
|
klass = object.class
|
14
9
|
|
15
10
|
if klass.respond_to?(:enumerized_attributes) && (attr = klass.enumerized_attributes[method])
|
@@ -20,10 +15,10 @@ module Enumerize
|
|
20
15
|
end
|
21
16
|
end
|
22
17
|
|
23
|
-
|
18
|
+
super(method, options)
|
24
19
|
end
|
25
20
|
end
|
26
21
|
end
|
27
22
|
end
|
28
23
|
|
29
|
-
::Formtastic::FormBuilder.send :
|
24
|
+
::Formtastic::FormBuilder.send :prepend, Enumerize::Hooks::FormtasticFormBuilderExtension
|
@@ -1,19 +1,15 @@
|
|
1
1
|
module Enumerize
|
2
2
|
module Hooks
|
3
3
|
module SequelDataset
|
4
|
-
def
|
5
|
-
klass.alias_method_chain :literal_append, :enumerize
|
6
|
-
end
|
7
|
-
|
8
|
-
def literal_append_with_enumerize(sql, v)
|
4
|
+
def literal_append(sql, v)
|
9
5
|
if v.is_a?(Enumerize::Value)
|
10
|
-
|
6
|
+
super(sql, v.value)
|
11
7
|
else
|
12
|
-
|
8
|
+
super(sql, v)
|
13
9
|
end
|
14
10
|
end
|
15
11
|
end
|
16
12
|
end
|
17
13
|
end
|
18
14
|
|
19
|
-
::Sequel::Dataset.send :
|
15
|
+
::Sequel::Dataset.send :prepend, Enumerize::Hooks::SequelDataset
|
@@ -3,21 +3,15 @@ require 'active_support/concern'
|
|
3
3
|
module Enumerize
|
4
4
|
module Hooks
|
5
5
|
module SimpleFormBuilderExtension
|
6
|
-
extend ActiveSupport::Concern
|
7
6
|
|
8
|
-
|
9
|
-
alias_method_chain :input, :enumerize
|
10
|
-
alias_method_chain :input_field, :enumerize
|
11
|
-
end
|
12
|
-
|
13
|
-
def input_with_enumerize(attribute_name, options={}, &block)
|
7
|
+
def input(attribute_name, options={}, &block)
|
14
8
|
add_input_options_for_enumerized_attribute(attribute_name, options)
|
15
|
-
|
9
|
+
super(attribute_name, options, &block)
|
16
10
|
end
|
17
11
|
|
18
|
-
def
|
12
|
+
def input_field(attribute_name, options={})
|
19
13
|
add_input_options_for_enumerized_attribute(attribute_name, options)
|
20
|
-
|
14
|
+
super(attribute_name, options)
|
21
15
|
end
|
22
16
|
|
23
17
|
private
|
@@ -37,4 +31,4 @@ module Enumerize
|
|
37
31
|
end
|
38
32
|
end
|
39
33
|
|
40
|
-
::SimpleForm::FormBuilder.send :
|
34
|
+
::SimpleForm::FormBuilder.send :prepend, Enumerize::Hooks::SimpleFormBuilderExtension
|
@@ -3,21 +3,16 @@ require 'active_support/concern'
|
|
3
3
|
module Enumerize
|
4
4
|
module Hooks
|
5
5
|
module UniquenessValidator
|
6
|
-
extend ActiveSupport::Concern
|
7
6
|
|
8
|
-
|
9
|
-
alias_method_chain :validate_each, :enumerize
|
10
|
-
end
|
11
|
-
|
12
|
-
def validate_each_with_enumerize(record, name, value)
|
7
|
+
def validate_each(record, name, value)
|
13
8
|
if record.class.respond_to?(:enumerized_attributes) && (attr = record.class.enumerized_attributes[name])
|
14
9
|
value = attr.find_value(value).try(:value)
|
15
10
|
end
|
16
11
|
|
17
|
-
|
12
|
+
super(record, name, value)
|
18
13
|
end
|
19
14
|
end
|
20
15
|
end
|
21
16
|
end
|
22
17
|
|
23
|
-
::ActiveRecord::Validations::UniquenessValidator.send :
|
18
|
+
::ActiveRecord::Validations::UniquenessValidator.send :prepend, Enumerize::Hooks::UniquenessValidator
|
data/lib/enumerize/value.rb
CHANGED
@@ -34,10 +34,10 @@ module Enumerize
|
|
34
34
|
def i18n_keys
|
35
35
|
@i18n_keys ||= begin
|
36
36
|
i18n_keys = i18n_scopes
|
37
|
-
i18n_keys <<
|
38
|
-
i18n_keys <<
|
37
|
+
i18n_keys << :"enumerize.defaults.#{@attr.name}.#{self}"
|
38
|
+
i18n_keys << :"enumerize.#{@attr.name}.#{self}"
|
39
39
|
i18n_keys << self.underscore.humanize # humanize value if there are no translations
|
40
|
-
i18n_keys
|
40
|
+
i18n_keys
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
data/lib/enumerize/version.rb
CHANGED
data/test/activerecord_test.rb
CHANGED
@@ -53,6 +53,10 @@ class User < ActiveRecord::Base
|
|
53
53
|
enumerize :status, :in => { active: 1, blocked: 2 }, scope: true
|
54
54
|
|
55
55
|
enumerize :account_type, :in => [:basic, :premium]
|
56
|
+
|
57
|
+
# There is no column for relationship enumeration for testing purposes: model
|
58
|
+
# should not be broken even if the associated column does not exist yet.
|
59
|
+
enumerize :relationship, :in => [:single, :married]
|
56
60
|
end
|
57
61
|
|
58
62
|
class UniqStatusUser < User
|
@@ -60,6 +64,10 @@ class UniqStatusUser < User
|
|
60
64
|
validates :sex, presence: true
|
61
65
|
end
|
62
66
|
|
67
|
+
class InterestsRequiredUser < User
|
68
|
+
validates :interests, presence: true
|
69
|
+
end
|
70
|
+
|
63
71
|
describe Enumerize::ActiveRecordSupport do
|
64
72
|
it 'sets nil if invalid value is passed' do
|
65
73
|
user = User.new
|
@@ -298,6 +306,24 @@ describe Enumerize::ActiveRecordSupport do
|
|
298
306
|
user.errors[:status].wont_be :empty?
|
299
307
|
end
|
300
308
|
|
309
|
+
it 'validates presence with multiple attributes' do
|
310
|
+
user = InterestsRequiredUser.new
|
311
|
+
user.interests = []
|
312
|
+
user.valid?
|
313
|
+
|
314
|
+
user.errors[:interests].wont_be :empty?
|
315
|
+
|
316
|
+
user.interests = ['']
|
317
|
+
user.valid?
|
318
|
+
|
319
|
+
user.errors[:interests].wont_be :empty?
|
320
|
+
|
321
|
+
user.interests = [:dancing, :programming]
|
322
|
+
user.valid?
|
323
|
+
|
324
|
+
user.errors[:interests].must_be_empty
|
325
|
+
end
|
326
|
+
|
301
327
|
it 'is valid after #becomes' do
|
302
328
|
User.delete_all
|
303
329
|
user = User.new
|
@@ -345,4 +371,63 @@ describe Enumerize::ActiveRecordSupport do
|
|
345
371
|
|
346
372
|
assert_equal [1, 2], YAML.load(user.changes.to_yaml)[:status]
|
347
373
|
end
|
374
|
+
|
375
|
+
it 'allows using update_all' do
|
376
|
+
User.delete_all
|
377
|
+
|
378
|
+
user = User.create(status: :active, account_type: :premium)
|
379
|
+
|
380
|
+
User.update_all(status: :blocked)
|
381
|
+
user.reload
|
382
|
+
user.status.must_equal 'blocked'
|
383
|
+
|
384
|
+
User.update_all(status: :active, account_type: :basic)
|
385
|
+
user.reload
|
386
|
+
user.status.must_equal 'active'
|
387
|
+
user.account_type.must_equal 'basic'
|
388
|
+
end
|
389
|
+
|
390
|
+
it 'allows using update_all for multiple enumerize' do
|
391
|
+
User.delete_all
|
392
|
+
|
393
|
+
klass = Class.new(User)
|
394
|
+
klass.enumerize :interests, in: { music: 0, sports: 1, dancing: 2, programming: 3}, multiple: true
|
395
|
+
|
396
|
+
user = klass.create(status: :active)
|
397
|
+
klass.update_all(status: :blocked, interests: [:music, :dancing])
|
398
|
+
|
399
|
+
user = klass.find(user.id)
|
400
|
+
user.status.must_equal 'blocked'
|
401
|
+
user.interests.must_equal %w(music dancing)
|
402
|
+
end
|
403
|
+
|
404
|
+
it 'allows using update_all with values' do
|
405
|
+
User.delete_all
|
406
|
+
|
407
|
+
user = User.create(status: :active)
|
408
|
+
|
409
|
+
User.update_all(status: 2)
|
410
|
+
user.reload
|
411
|
+
user.status.must_equal 'blocked'
|
412
|
+
end
|
413
|
+
|
414
|
+
it 'preserves string usage of update_all' do
|
415
|
+
User.delete_all
|
416
|
+
|
417
|
+
user = User.create(name: "Fred")
|
418
|
+
|
419
|
+
User.update_all("name = 'Frederick'")
|
420
|
+
user.reload
|
421
|
+
user.name.must_equal 'Frederick'
|
422
|
+
end
|
423
|
+
|
424
|
+
it 'preserves interpolated array usage of update_all' do
|
425
|
+
User.delete_all
|
426
|
+
|
427
|
+
user = User.create(name: "Fred")
|
428
|
+
|
429
|
+
User.update_all(["name = :name", {name: 'Frederick'}])
|
430
|
+
user.reload
|
431
|
+
user.name.must_equal 'Frederick'
|
432
|
+
end
|
348
433
|
end
|
data/test/base_test.rb
CHANGED
@@ -41,7 +41,7 @@ describe Enumerize::Base do
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
it 'scopes translation by
|
44
|
+
it 'scopes translation by i18n key' do
|
45
45
|
def klass.model_name
|
46
46
|
name = "ExampleClass"
|
47
47
|
def name.i18n_key
|
@@ -171,7 +171,7 @@ describe Enumerize::Base do
|
|
171
171
|
|
172
172
|
object = klass.new
|
173
173
|
object.foo.must_be_nil
|
174
|
-
object.attributes.must_equal({
|
174
|
+
object.attributes.must_equal({})
|
175
175
|
|
176
176
|
object.foo = 'test'
|
177
177
|
object.foo.must_equal 'test'
|
data/test/mongoid_test.rb
CHANGED
@@ -65,6 +65,13 @@ describe Enumerize do
|
|
65
65
|
user.role.must_equal 'user'
|
66
66
|
end
|
67
67
|
|
68
|
+
it 'does not set default value for not selected attributes' do
|
69
|
+
model.delete_all
|
70
|
+
model.create!(sex: :male)
|
71
|
+
|
72
|
+
assert_equal ['_id'], model.only(:id).first.attributes.keys
|
73
|
+
end
|
74
|
+
|
68
75
|
it 'validates inclusion' do
|
69
76
|
user = model.new
|
70
77
|
user.role = 'wrong'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enumerize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Nartimov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -38,7 +38,7 @@ files:
|
|
38
38
|
- Gemfile
|
39
39
|
- Gemfile.global
|
40
40
|
- Gemfile.mongo_mapper
|
41
|
-
- Gemfile.
|
41
|
+
- Gemfile.rails42
|
42
42
|
- MIT-LICENSE
|
43
43
|
- README.md
|
44
44
|
- Rakefile
|
@@ -88,7 +88,8 @@ files:
|
|
88
88
|
- test/test_helper.rb
|
89
89
|
- test/value_test.rb
|
90
90
|
homepage: https://github.com/brainspec/enumerize
|
91
|
-
licenses:
|
91
|
+
licenses:
|
92
|
+
- MIT
|
92
93
|
metadata: {}
|
93
94
|
post_install_message:
|
94
95
|
rdoc_options: []
|
@@ -106,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
107
|
version: '0'
|
107
108
|
requirements: []
|
108
109
|
rubyforge_project:
|
109
|
-
rubygems_version: 2.
|
110
|
+
rubygems_version: 2.5.1
|
110
111
|
signing_key:
|
111
112
|
specification_version: 4
|
112
113
|
summary: Enumerated attributes with I18n and ActiveRecord/Mongoid/MongoMapper support
|