enumerize 2.3.1 → 2.4.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 +9 -16
- data/CHANGELOG.md +10 -1
- data/Gemfile +2 -3
- data/Gemfile.global +1 -2
- data/Gemfile.mongo_mapper +2 -3
- data/Gemfile.rails60 +6 -0
- data/Gemfile.rails61 +6 -0
- data/README.md +3 -3
- data/lib/enumerize.rb +1 -0
- data/lib/enumerize/activerecord.rb +8 -2
- data/lib/enumerize/attribute.rb +2 -2
- data/lib/enumerize/integrations/rspec/matcher.rb +5 -2
- data/lib/enumerize/predicatable.rb +1 -1
- data/lib/enumerize/value.rb +7 -2
- data/lib/enumerize/version.rb +1 -1
- data/spec/enumerize/integrations/rspec/matcher_spec.rb +11 -10
- data/test/activerecord_test.rb +29 -1
- data/test/mongo_mapper_test.rb +1 -2
- data/test/multiple_test.rb +6 -0
- data/test/support/view_test_helper.rb +12 -1
- data/test/value_test.rb +30 -3
- metadata +8 -10
- data/Gemfile.rails42 +0 -7
- data/Gemfile.rails50 +0 -7
- data/Gemfile.rails52 +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15a8427afecf01652e67b4758c05a499ba541254799d8ca61f0146f942647388
|
4
|
+
data.tar.gz: ee769906574712f378ca8dfb8aaadcfcc5993a485531cf520b44c41420e8fa84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46edf9a1fed39c9122247957a64dab6a773f5d0a8d0176204e48bd9d28074019480c1ae3cf16ccc3ad7a185d64fb7cf92d9f1a5ec63a581a388d1dd4620ac651
|
7
|
+
data.tar.gz: 206734dd6819196fbdff49e89626d30e45cd29154a63151f8631c87d13d15c7bd2bae90916b411a7f7d71287fa5be5a742f281392348f3c330401dde9d4b72c2
|
data/.travis.yml
CHANGED
@@ -1,26 +1,21 @@
|
|
1
|
+
dist: focal
|
1
2
|
language: ruby
|
2
3
|
sudo: false
|
3
4
|
services:
|
4
|
-
- postgresql
|
5
5
|
- mongodb
|
6
|
+
addons:
|
7
|
+
postgresql: "13"
|
6
8
|
gemfile:
|
7
9
|
- Gemfile
|
8
|
-
- Gemfile.
|
9
|
-
- Gemfile.
|
10
|
-
- Gemfile.rails52
|
10
|
+
- Gemfile.rails60
|
11
|
+
- Gemfile.rails61
|
11
12
|
- Gemfile.mongo_mapper
|
12
13
|
rvm:
|
13
|
-
- 2.
|
14
|
-
- 2.
|
15
|
-
- 2.
|
16
|
-
- 2.5.0
|
17
|
-
- jruby-9.1.14.0
|
14
|
+
- 2.5.8
|
15
|
+
- 2.6.6
|
16
|
+
- 2.7.1
|
18
17
|
before_install:
|
19
|
-
|
20
|
-
- gem install "rubygems-update:<3.0.0" --no-document && update_rubygems
|
21
|
-
# Bundler 2.0 is not supported by Rails < 5
|
22
|
-
- gem list -i bundler -v '>= 2.0.0' && rvm @global do gem uninstall bundler -x || true
|
23
|
-
- gem install bundler -v '< 2'
|
18
|
+
- gem install bundler
|
24
19
|
env:
|
25
20
|
global:
|
26
21
|
- DB_USER=postgres
|
@@ -30,8 +25,6 @@ env:
|
|
30
25
|
- DB=postgresql
|
31
26
|
matrix:
|
32
27
|
fast_finish: true
|
33
|
-
allow_failures:
|
34
|
-
- rvm: jruby-9.1.14.0
|
35
28
|
exclude:
|
36
29
|
- gemfile: Gemfile.mongo_mapper
|
37
30
|
env: DB=postgresql
|
data/CHANGELOG.md
CHANGED
@@ -1,9 +1,18 @@
|
|
1
|
-
##
|
1
|
+
## 2.4.0 (December 12, 2020)
|
2
2
|
|
3
3
|
### enhancements
|
4
4
|
|
5
|
+
* Show warning when enumerized value name conflicts with existing object's methods. (by [@aki77](https://github.com/aki77))
|
6
|
+
* Add RSpec support for shallow scopes. (by [@nashby](https://github.com/nashby))
|
7
|
+
* Drop support for Ruby older than 2.5. Support only Ruby 2.5+. (by [@nashby](https://github.com/nashby))
|
8
|
+
* Drop support for Rails 4. Support only Rails 5.2+. (by [@nashby](https://github.com/nashby))
|
9
|
+
* Add support for Rails 6.1 (by [@y-yagi](https://github.com/y-yagi))
|
10
|
+
|
5
11
|
### bug fix
|
6
12
|
|
13
|
+
* Fix exception when using predicate methods on enumerized value transformed into invalid value. (by [@guigs](https://github.com/guigs))
|
14
|
+
* Fix issue with RSpec#with_predicates matcher when custom values are used as attribute. (by [@nashby](https://github.com/nashby))
|
15
|
+
|
7
16
|
## 2.3.1 (May 2, 2019)
|
8
17
|
|
9
18
|
### enhancements
|
data/Gemfile
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
eval_gemfile('Gemfile.global')
|
2
2
|
|
3
3
|
gem 'minitest', '~> 5.8'
|
4
|
-
gem 'rails', '5.
|
5
|
-
gem 'activerecord-jdbcsqlite3-adapter', '~> 51.0', platform: :jruby
|
6
|
-
gem 'activerecord-jdbcpostgresql-adapter', '~> 51.0', platform: :jruby
|
4
|
+
gem 'rails', '~> 5.2.4', require: false
|
7
5
|
gem 'mongoid'
|
6
|
+
gem 'sqlite3', '~> 1.3.6', :platform => [:ruby, :mswin, :mingw]
|
data/Gemfile.global
CHANGED
@@ -5,8 +5,7 @@ gemspec
|
|
5
5
|
gem 'rake'
|
6
6
|
gem 'rspec', :require => false
|
7
7
|
|
8
|
-
gem '
|
9
|
-
gem 'pg', '~> 0.21.0', :platform => [:ruby, :mswin, :mingw]
|
8
|
+
gem 'pg', '~> 1.2.3', :platform => [:ruby, :mswin, :mingw]
|
10
9
|
gem 'sequel'
|
11
10
|
|
12
11
|
platforms :rbx do
|
data/Gemfile.mongo_mapper
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
eval_gemfile('Gemfile.global')
|
2
2
|
|
3
3
|
gem 'minitest', '~> 5.8'
|
4
|
-
gem 'rails', '
|
5
|
-
gem 'activerecord-jdbcsqlite3-adapter', '~> 1.3.0', platform: :jruby
|
6
|
-
gem 'activerecord-jdbcpostgresql-adapter', '~> 1.3.0', platform: :jruby
|
4
|
+
gem 'rails', '~> 5.2.4', :require => false
|
7
5
|
gem 'mongo_mapper'
|
6
|
+
gem 'sqlite3', '~> 1.3.6', :platform => [:ruby, :mswin, :mingw]
|
data/Gemfile.rails60
ADDED
data/Gemfile.rails61
ADDED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Enumerize [](http://travis-ci.org/brainspec/enumerize)
|
1
|
+
# Enumerize [](http://travis-ci.org/brainspec/enumerize)
|
2
2
|
|
3
3
|
Enumerated attributes with I18n and ActiveRecord/Mongoid/MongoMapper/Sequel support
|
4
4
|
|
@@ -17,8 +17,8 @@ Or install it yourself as:
|
|
17
17
|
$ gem install enumerize
|
18
18
|
|
19
19
|
## Supported Versions
|
20
|
-
- Ruby 2.
|
21
|
-
- Rails
|
20
|
+
- Ruby 2.5+
|
21
|
+
- Rails 5.2+
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
data/lib/enumerize.rb
CHANGED
@@ -21,8 +21,14 @@ module Enumerize
|
|
21
21
|
require 'enumerize/hooks/uniqueness'
|
22
22
|
|
23
23
|
unless options[:multiple]
|
24
|
-
|
25
|
-
|
24
|
+
if ::ActiveRecord.version >= ::Gem::Version.new("6.1.0.alpha")
|
25
|
+
decorate_attribute_type(name.to_s) do |subtype|
|
26
|
+
Type.new(enumerized_attributes[name], subtype)
|
27
|
+
end
|
28
|
+
else
|
29
|
+
decorate_attribute_type(name, :enumerize) do |subtype|
|
30
|
+
Type.new(enumerized_attributes[name], subtype)
|
31
|
+
end
|
26
32
|
end
|
27
33
|
end
|
28
34
|
end
|
data/lib/enumerize/attribute.rb
CHANGED
@@ -172,7 +172,7 @@ module Enumerize
|
|
172
172
|
|
173
173
|
def #{name}=(values)
|
174
174
|
@_#{name}_enumerized_set = Enumerize::Set.new(self, self.class.enumerized_attributes[:#{name}], values)
|
175
|
-
raw_values =
|
175
|
+
raw_values = self.#{name}.values.map(&:value)
|
176
176
|
|
177
177
|
if defined?(super)
|
178
178
|
super raw_values
|
@@ -184,7 +184,7 @@ module Enumerize
|
|
184
184
|
|
185
185
|
_enumerized_values_for_validation['#{name}'] = values.respond_to?(:map) ? values.reject(&:blank?).map(&:to_s) : values
|
186
186
|
|
187
|
-
|
187
|
+
self.#{name}
|
188
188
|
end
|
189
189
|
RUBY
|
190
190
|
end
|
@@ -110,7 +110,7 @@ module Enumerize
|
|
110
110
|
|
111
111
|
def matches_predicates?
|
112
112
|
if expected_predicates.is_a?(TrueClass)
|
113
|
-
subject.respond_to?("#{
|
113
|
+
subject.respond_to?("#{enumerized_values.first}?")
|
114
114
|
else
|
115
115
|
subject.respond_to?("#{expected_attr}_#{attributes.values.first}?")
|
116
116
|
end
|
@@ -121,8 +121,11 @@ module Enumerize
|
|
121
121
|
end
|
122
122
|
|
123
123
|
def matches_scope?
|
124
|
-
|
124
|
+
case expected_scope
|
125
|
+
when TrueClass
|
125
126
|
subject_class.respond_to?("with_#{expected_attr}")
|
127
|
+
when :shallow
|
128
|
+
enumerized_values.all? { |value| subject_class.respond_to?(value) }
|
126
129
|
else
|
127
130
|
subject_class.respond_to?(expected_scope[:scope])
|
128
131
|
end
|
data/lib/enumerize/value.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'i18n'
|
4
|
+
require 'active_support/inflector'
|
4
5
|
|
5
6
|
module Enumerize
|
6
7
|
class Value < String
|
@@ -9,6 +10,10 @@ module Enumerize
|
|
9
10
|
attr_reader :value
|
10
11
|
|
11
12
|
def initialize(attr, name, value=nil)
|
13
|
+
if self.class.method_defined?("#{name}?")
|
14
|
+
warn("It's not recommended to use `#{name}` as a field value since `#{name}?` is defined. (#{attr.klass.name}##{attr.name})")
|
15
|
+
end
|
16
|
+
|
12
17
|
@attr = attr
|
13
18
|
@value = value.nil? ? name.to_s : value
|
14
19
|
|
@@ -17,12 +22,12 @@ module Enumerize
|
|
17
22
|
@i18n_keys = @attr.i18n_scopes.map { |s| :"#{s}.#{self}" }
|
18
23
|
@i18n_keys << :"enumerize.defaults.#{@attr.name}.#{self}"
|
19
24
|
@i18n_keys << :"enumerize.#{@attr.name}.#{self}"
|
20
|
-
@i18n_keys <<
|
25
|
+
@i18n_keys << ActiveSupport::Inflector.humanize(ActiveSupport::Inflector.underscore(self)) # humanize value if there are no translations
|
21
26
|
@i18n_keys
|
22
27
|
end
|
23
28
|
|
24
29
|
def text
|
25
|
-
I18n.t(@i18n_keys[0], :default => @i18n_keys[1..-1])
|
30
|
+
I18n.t(@i18n_keys[0], :default => @i18n_keys[1..-1]) if @i18n_keys
|
26
31
|
end
|
27
32
|
|
28
33
|
def ==(other)
|
data/lib/enumerize/version.rb
CHANGED
@@ -13,6 +13,7 @@ ActiveRecord::Base.connection.instance_eval do
|
|
13
13
|
t.string :sex
|
14
14
|
t.string :role
|
15
15
|
t.string :account_type
|
16
|
+
t.string :status
|
16
17
|
end
|
17
18
|
end
|
18
19
|
|
@@ -22,6 +23,7 @@ class User < ActiveRecord::Base
|
|
22
23
|
enumerize :sex, :in => [:male, :female], scope: true
|
23
24
|
enumerize :role, :in => [:user, :admin], scope: :having_role
|
24
25
|
enumerize :account_type, :in => [:basic, :premium]
|
26
|
+
enumerize :status, :in => [:active, :disabled], scope: :shallow
|
25
27
|
end
|
26
28
|
|
27
29
|
RSpec.describe Enumerize::Integrations::RSpec::Matcher do
|
@@ -41,7 +43,6 @@ RSpec.describe Enumerize::Integrations::RSpec::Matcher do
|
|
41
43
|
end
|
42
44
|
|
43
45
|
describe 'without qualifier' do
|
44
|
-
|
45
46
|
it 'accepts when has defined a enumerize' do
|
46
47
|
model.enumerize(:sex, :in => [:male, :female])
|
47
48
|
expect(subject).to enumerize(:sex)
|
@@ -56,9 +57,7 @@ RSpec.describe Enumerize::Integrations::RSpec::Matcher do
|
|
56
57
|
end
|
57
58
|
|
58
59
|
describe '#in' do
|
59
|
-
|
60
60
|
context 'defined as array' do
|
61
|
-
|
62
61
|
before do
|
63
62
|
model.enumerize(:sex, :in => [:male, :female])
|
64
63
|
end
|
@@ -91,7 +90,6 @@ RSpec.describe Enumerize::Integrations::RSpec::Matcher do
|
|
91
90
|
end
|
92
91
|
|
93
92
|
context 'defined as hash' do
|
94
|
-
|
95
93
|
before do
|
96
94
|
model.enumerize(:sex, :in => { male: 0, female: 1 })
|
97
95
|
end
|
@@ -130,7 +128,6 @@ RSpec.describe Enumerize::Integrations::RSpec::Matcher do
|
|
130
128
|
end
|
131
129
|
|
132
130
|
describe '#with_default' do
|
133
|
-
|
134
131
|
before do
|
135
132
|
model.enumerize(:sex, :in => [:male, :female], default: :female)
|
136
133
|
end
|
@@ -161,9 +158,7 @@ RSpec.describe Enumerize::Integrations::RSpec::Matcher do
|
|
161
158
|
end
|
162
159
|
|
163
160
|
describe '#with_i18n_scope' do
|
164
|
-
|
165
161
|
context 'defined as string' do
|
166
|
-
|
167
162
|
before do
|
168
163
|
model.enumerize(:sex, :in => [:male, :female], i18n_scope: 'sex')
|
169
164
|
end
|
@@ -200,7 +195,6 @@ RSpec.describe Enumerize::Integrations::RSpec::Matcher do
|
|
200
195
|
end
|
201
196
|
|
202
197
|
describe '#with_predicates' do
|
203
|
-
|
204
198
|
it 'accepts when predicates is defined as a boolean' do
|
205
199
|
model.enumerize(:sex, :in => [:male, :female], predicates: true)
|
206
200
|
expect(subject).to enumerize(:sex).in(:male, :female).with_predicates(true)
|
@@ -211,6 +205,11 @@ RSpec.describe Enumerize::Integrations::RSpec::Matcher do
|
|
211
205
|
expect(subject).to enumerize(:sex).in(:male, :female).with_predicates(prefix: true)
|
212
206
|
end
|
213
207
|
|
208
|
+
it 'accepts when custom values are used as attribute' do
|
209
|
+
model.enumerize(:sex, :in => { male: 0, female: 1 }, predicates: true)
|
210
|
+
expect(subject).to enumerize(:sex).in(:male, :female).with_predicates(true)
|
211
|
+
end
|
212
|
+
|
214
213
|
it 'rejects when predicates is not defined' do
|
215
214
|
model.enumerize(:sex, :in => [:male, :female])
|
216
215
|
message = 'Expected Model to define enumerize :sex in: "female", "male" predicates: true'
|
@@ -221,7 +220,6 @@ RSpec.describe Enumerize::Integrations::RSpec::Matcher do
|
|
221
220
|
end
|
222
221
|
|
223
222
|
describe '#with_multiple' do
|
224
|
-
|
225
223
|
it 'accepts when has defined the multiple' do
|
226
224
|
model.enumerize(:sex, :in => [:male, :female], multiple: true)
|
227
225
|
expect(subject).to enumerize(:sex).in(:male, :female).with_multiple(true)
|
@@ -237,7 +235,6 @@ RSpec.describe Enumerize::Integrations::RSpec::Matcher do
|
|
237
235
|
end
|
238
236
|
|
239
237
|
describe '#with_scope' do
|
240
|
-
|
241
238
|
subject do
|
242
239
|
User.new
|
243
240
|
end
|
@@ -250,6 +247,10 @@ RSpec.describe Enumerize::Integrations::RSpec::Matcher do
|
|
250
247
|
expect(subject).to enumerize(:role).in(:user, :admin).with_scope(scope: :having_role)
|
251
248
|
end
|
252
249
|
|
250
|
+
it 'accepts shallow scope' do
|
251
|
+
expect(subject).to enumerize(:status).in(:active, :disabled).with_scope(:shallow)
|
252
|
+
end
|
253
|
+
|
253
254
|
it 'rejects when scope is not defined' do
|
254
255
|
message = 'Expected User to define enumerize :account_type in: "basic", "premium" scope: true'
|
255
256
|
expect do
|
data/test/activerecord_test.rb
CHANGED
@@ -180,7 +180,9 @@ describe Enumerize::ActiveRecordSupport do
|
|
180
180
|
User.delete_all
|
181
181
|
User.create!(:sex => :male)
|
182
182
|
|
183
|
-
|
183
|
+
user = User.select(:id).first
|
184
|
+
user.attributes['role'].must_equal nil
|
185
|
+
user.attributes['lambda_role'].must_equal nil
|
184
186
|
end
|
185
187
|
|
186
188
|
it 'has default value with lambda' do
|
@@ -616,4 +618,30 @@ describe Enumerize::ActiveRecordSupport do
|
|
616
618
|
|
617
619
|
sql.must_include 'LIKE \'%foo%\''
|
618
620
|
end
|
621
|
+
|
622
|
+
if Rails::VERSION::MAJOR >= 6
|
623
|
+
it 'supports AR#insert_all' do
|
624
|
+
User.delete_all
|
625
|
+
|
626
|
+
User.insert_all([{ sex: :male }])
|
627
|
+
User.insert_all([{ status: :active }])
|
628
|
+
User.insert_all([{ interests: [:music, :sports] }])
|
629
|
+
|
630
|
+
User.exists?(sex: :male).must_equal true
|
631
|
+
User.exists?(status: :active).must_equal true
|
632
|
+
User.exists?(interests: [:music, :sports]).must_equal true
|
633
|
+
end
|
634
|
+
|
635
|
+
it 'supports AR#upsert_all' do
|
636
|
+
User.delete_all
|
637
|
+
|
638
|
+
User.upsert_all([{ sex: :male }])
|
639
|
+
User.upsert_all([{ status: :active }])
|
640
|
+
User.upsert_all([{ interests: [:music, :sports] }])
|
641
|
+
|
642
|
+
User.exists?(sex: :male).must_equal true
|
643
|
+
User.exists?(status: :active).must_equal true
|
644
|
+
User.exists?(interests: [:music, :sports]).must_equal true
|
645
|
+
end
|
646
|
+
end
|
619
647
|
end
|
data/test/mongo_mapper_test.rb
CHANGED
@@ -8,8 +8,7 @@ silence_warnings do
|
|
8
8
|
require 'mongo_mapper'
|
9
9
|
end
|
10
10
|
|
11
|
-
MongoMapper.connection = Mongo::
|
12
|
-
MongoMapper.database = 'enumerize-test-suite-of-mongomapper'
|
11
|
+
MongoMapper.connection = Mongo::Client.new(['localhost:27017'], database: 'enumerize-test-suite-of-mongomapper')
|
13
12
|
|
14
13
|
describe Enumerize do
|
15
14
|
class MongoMapperUser
|
data/test/multiple_test.rb
CHANGED
@@ -56,4 +56,10 @@ describe Enumerize::Base do
|
|
56
56
|
kklass.enumerize :foos, in: %w(a b c), multiple: true, scope: true
|
57
57
|
end
|
58
58
|
end
|
59
|
+
|
60
|
+
it 'assign a name with the first letter capitalized' do
|
61
|
+
kklass.enumerize :Foos, in: %w(a b c), multiple: true
|
62
|
+
object.Foos = %w(a c)
|
63
|
+
object.Foos.must_equal %w(a c)
|
64
|
+
end
|
59
65
|
end
|
@@ -7,10 +7,21 @@ if defined?(ActionView::RoutingUrlFor)
|
|
7
7
|
ActionView::RoutingUrlFor.send(:include, ActionDispatch::Routing::UrlFor)
|
8
8
|
end
|
9
9
|
|
10
|
-
module
|
10
|
+
module SetupAndTeardownHelper
|
11
11
|
extend ActiveSupport::Concern
|
12
12
|
|
13
13
|
include ActiveSupport::Testing::SetupAndTeardown
|
14
|
+
|
15
|
+
included do
|
16
|
+
include ActiveSupport::Callbacks
|
17
|
+
define_callbacks :setup, :teardown
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module ViewTestHelper
|
22
|
+
extend ActiveSupport::Concern
|
23
|
+
|
24
|
+
include SetupAndTeardownHelper
|
14
25
|
include ActionView::TestCase::Behavior
|
15
26
|
|
16
27
|
included do
|
data/test/value_test.rb
CHANGED
@@ -4,10 +4,13 @@ require 'test_helper'
|
|
4
4
|
require 'yaml'
|
5
5
|
|
6
6
|
describe Enumerize::Value do
|
7
|
-
class
|
7
|
+
class Model
|
8
8
|
end
|
9
9
|
|
10
|
-
|
10
|
+
class Attr < Struct.new(:values, :name, :i18n_scopes, :klass)
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:attr) { Attr.new([], "attribute_name", [], Model) }
|
11
14
|
let(:val) { Enumerize::Value.new(attr, 'test_value', 1) }
|
12
15
|
|
13
16
|
it 'is a string' do
|
@@ -32,7 +35,6 @@ describe Enumerize::Value do
|
|
32
35
|
end
|
33
36
|
|
34
37
|
describe 'translation' do
|
35
|
-
|
36
38
|
it 'uses common translation' do
|
37
39
|
store_translations(:en, :enumerize => {:attribute_name => {:test_value => "Common translation"}}) do
|
38
40
|
val.text.must_be :==, "Common translation"
|
@@ -82,6 +84,13 @@ describe Enumerize::Value do
|
|
82
84
|
val.text.must_be :==, "Scope specific translation"
|
83
85
|
end
|
84
86
|
end
|
87
|
+
|
88
|
+
it 'returns nil if value was modified' do
|
89
|
+
store_translations(:en, :enumerize => {:attribute_name => {:test_value => "Common translation"}}) do
|
90
|
+
modified_val = val.upcase
|
91
|
+
modified_val.text.must_be_nil
|
92
|
+
end
|
93
|
+
end
|
85
94
|
end
|
86
95
|
|
87
96
|
describe 'boolean methods comparison' do
|
@@ -121,6 +130,14 @@ describe Enumerize::Value do
|
|
121
130
|
it "doesn't respond to a method for not existing value" do
|
122
131
|
val.wont_respond_to :some_method?
|
123
132
|
end
|
133
|
+
|
134
|
+
it "doesn't respond to methods is value was modified" do
|
135
|
+
modified_value = val.upcase
|
136
|
+
|
137
|
+
modified_value.upcase.wont_respond_to :some_method?
|
138
|
+
modified_value.upcase.wont_respond_to :test_value?
|
139
|
+
modified_value.upcase.wont_respond_to :other_value?
|
140
|
+
end
|
124
141
|
end
|
125
142
|
|
126
143
|
describe 'serialization' do
|
@@ -135,4 +152,14 @@ describe Enumerize::Value do
|
|
135
152
|
Marshal.load(dump_value).must_equal 'test_value'
|
136
153
|
end
|
137
154
|
end
|
155
|
+
|
156
|
+
describe 'initialize' do
|
157
|
+
it 'no output if undefined boolean method' do
|
158
|
+
assert_silent() { Enumerize::Value.new(attr, 'test_value') }
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'error output if defined boolean method' do
|
162
|
+
assert_output(nil, /`empty\?` is defined/) { Enumerize::Value.new(attr, 'empty') }
|
163
|
+
end
|
164
|
+
end
|
138
165
|
end
|
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: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Nartimov
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -38,9 +38,8 @@ files:
|
|
38
38
|
- Gemfile
|
39
39
|
- Gemfile.global
|
40
40
|
- Gemfile.mongo_mapper
|
41
|
-
- Gemfile.
|
42
|
-
- Gemfile.
|
43
|
-
- Gemfile.rails52
|
41
|
+
- Gemfile.rails60
|
42
|
+
- Gemfile.rails61
|
44
43
|
- MIT-LICENSE
|
45
44
|
- README.md
|
46
45
|
- Rakefile
|
@@ -98,7 +97,7 @@ homepage: https://github.com/brainspec/enumerize
|
|
98
97
|
licenses:
|
99
98
|
- MIT
|
100
99
|
metadata: {}
|
101
|
-
post_install_message:
|
100
|
+
post_install_message:
|
102
101
|
rdoc_options: []
|
103
102
|
require_paths:
|
104
103
|
- lib
|
@@ -113,9 +112,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
112
|
- !ruby/object:Gem::Version
|
114
113
|
version: '0'
|
115
114
|
requirements: []
|
116
|
-
|
117
|
-
|
118
|
-
signing_key:
|
115
|
+
rubygems_version: 3.0.8
|
116
|
+
signing_key:
|
119
117
|
specification_version: 4
|
120
118
|
summary: Enumerated attributes with I18n and ActiveRecord/Mongoid/MongoMapper support
|
121
119
|
test_files:
|
data/Gemfile.rails42
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
eval_gemfile('Gemfile.global')
|
2
|
-
|
3
|
-
gem 'minitest', '~> 5.8'
|
4
|
-
gem 'rails', '4.2.8', :require => false
|
5
|
-
gem 'activerecord-jdbcsqlite3-adapter', '~> 1.3.0', platform: :jruby
|
6
|
-
gem 'activerecord-jdbcpostgresql-adapter', '~> 1.3.0', platform: :jruby
|
7
|
-
gem 'mongoid', '~> 5.0'
|
data/Gemfile.rails50
DELETED
data/Gemfile.rails52
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
eval_gemfile('Gemfile.global')
|
2
|
-
|
3
|
-
gem 'minitest', '~> 5.8'
|
4
|
-
gem 'rails', '5.2.0.rc1', require: false
|
5
|
-
gem 'activerecord-jdbcsqlite3-adapter', github: 'jruby/activerecord-jdbc-adapter', branch: 'master', platform: :jruby
|
6
|
-
gem 'activerecord-jdbcpostgresql-adapter', github: 'jruby/activerecord-jdbc-adapter', branch: 'master', platform: :jruby
|
7
|
-
gem 'mongoid', github: 'mongodb/mongoid'
|