enumerize 2.5.0 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c86135927c636fc672bb7371b83b78b6844716f70dd2b9fa19a255b35ce2a5ca
4
- data.tar.gz: d1ac5ff95c2673d0743fab97725cf7abc939b157594545ad3e40dd9a1eefb841
3
+ metadata.gz: 7ed5759e8b7d540b7261ef4112d6ed175403650cd18f904e19c15826cc1b87b5
4
+ data.tar.gz: 44fdf94b2adcf41a5ffd35e415b9ff622dab59658fd2d16efac6f52ddd89bfcb
5
5
  SHA512:
6
- metadata.gz: 811f624a3f6d92fa20bc988b80051103e441315eab1662f3f2b1b9b98a866984e247e1b823669a7f7645d13e5aa44aaf8e1e95e39294e8c27a28d96dfc87b572
7
- data.tar.gz: 8c50e7946135c94719ac50149ab55ad1601d508b9cdf663e4542f220655b611899824af77a60873601d2193b01fc2611735f643c51d07d8d188213b478123149
6
+ metadata.gz: 0aab786d5ef4ebbd156211e9c659b6397facab2b1b075767f170ed706b7787d953baec2c3ffecb9a918d0cd3f87eecd541f41b7868045f4beafbb2584ca83fe3
7
+ data.tar.gz: 06af74a445ac38938b90e15e5e14cfc529332189328b86929a976593c376f46189ae6ded196ce1ca93c3c31d9f5b68b5ef03c91d65fe7e38d8a392ba88ef1dc6
@@ -32,7 +32,7 @@ jobs:
32
32
  strategy:
33
33
  fail-fast: false
34
34
  matrix:
35
- ruby-version: ['2.6', '2.7', '3.0.2']
35
+ ruby-version: ['2.7', '3.0', '3.1']
36
36
  gemfile:
37
37
  - Gemfile
38
38
  - Gemfile.rails60
@@ -47,14 +47,14 @@ jobs:
47
47
  exclude:
48
48
  - gemfile: Gemfile.mongo_mapper
49
49
  db: postgresql
50
- - ruby-version: '3.0.2'
50
+ - ruby-version: '3.0'
51
51
  gemfile: Gemfile
52
- - ruby-version: '3.0.2'
52
+ - ruby-version: '3.1'
53
+ gemfile: Gemfile
54
+ - ruby-version: '3.0'
55
+ gemfile: Gemfile.mongo_mapper
56
+ - ruby-version: '3.1'
53
57
  gemfile: Gemfile.mongo_mapper
54
- - ruby-version: '2.6'
55
- gemfile: Gemfile.rails70
56
- - ruby-version: '2.6'
57
- gemfile: Gemfile.railsmaster
58
58
  env:
59
59
  BUNDLE_GEMFILE: "${{ matrix.gemfile }}"
60
60
  DB: "${{ matrix.db }}"
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 2.6.0 (March 7, 2023)
2
+
3
+ ### enhancements
4
+
5
+ * Add `Enumerize::Attribute#value?`. This new method prevents the following breakage
6
+ when autocorrecting with Performance/InefficientHashSearch cop. (by [@koic](https://github.com/koic))
7
+ * Allow usage of kwargs with inheritance in Ruby 3.x. Support only Ruby 2.7+. (by [@mortik](https://github.com/mortik))
8
+
1
9
  ## 2.5.0 (December 24, 2021)
2
10
 
3
11
  ### enhancements
data/Gemfile CHANGED
@@ -3,4 +3,4 @@ eval_gemfile('Gemfile.global')
3
3
  gem 'minitest', '~> 5.8'
4
4
  gem 'rails', '~> 5.2.4', require: false
5
5
  gem 'mongoid'
6
- gem 'sqlite3', '~> 1.3.6', :platform => [:ruby, :mswin, :mingw]
6
+ gem 'sqlite3', '~> 1.5', :platform => [:ruby, :mswin, :mingw]
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Enumerize [![TravisCI](https://secure.travis-ci.org/brainspec/enumerize.svg?branch=master)](http://travis-ci.org/brainspec/enumerize)
1
+ # Enumerize [![Ruby](https://github.com/brainspec/enumerize/actions/workflows/ruby.yml/badge.svg)](https://github.com/brainspec/enumerize/actions/workflows/ruby.yml)
2
2
 
3
3
  Enumerated attributes with I18n and ActiveRecord/Mongoid/MongoMapper/Sequel support
4
4
 
@@ -46,7 +46,7 @@ Or install it yourself as:
46
46
 
47
47
  ## Supported Versions
48
48
 
49
- - Ruby 2.6+
49
+ - Ruby 2.7+
50
50
  - Rails 5.2+
51
51
 
52
52
  ## Usage
@@ -61,7 +61,7 @@ class User
61
61
  end
62
62
  ```
63
63
 
64
- Note that enumerized values are just identificators so if you want to use multi-word, etc. values then you should use `I18n` feature.
64
+ Note that enumerized values are just identifiers so if you want to use multi-word, etc. values then you should use `I18n` feature.
65
65
 
66
66
  ---
67
67
 
data/enumerize.gemspec CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |gem|
16
16
  gem.require_paths = ["lib"]
17
17
  gem.version = Enumerize::VERSION
18
18
 
19
- gem.required_ruby_version = '>= 1.9.3'
19
+ gem.required_ruby_version = '>= 2.7'
20
20
 
21
21
  gem.add_dependency('activesupport', '>= 3.2')
22
22
  end
@@ -122,7 +122,7 @@ module Enumerize
122
122
  alias type_cast_from_database deserialize
123
123
 
124
124
  def as_json(options = nil)
125
- {attr: @attr.name, subtype: @subtype}.as_json(options)
125
+ {attr: @attr.name}.as_json(options)
126
126
  end
127
127
 
128
128
  def encode_with(coder)
@@ -52,6 +52,10 @@ module Enumerize
52
52
  values.each { |value| yield value }
53
53
  end
54
54
 
55
+ def value?(value)
56
+ values.include?(value)
57
+ end
58
+
55
59
  def i18n_scopes
56
60
  @i18n_scopes ||= if i18n_scope
57
61
  Array(i18n_scope)
@@ -49,7 +49,7 @@ module Enumerize
49
49
  end
50
50
  end
51
51
 
52
- def initialize(*)
52
+ def initialize(*args, **kwargs)
53
53
  super
54
54
  _set_default_value_for_enumerized_attributes
55
55
  end
@@ -90,22 +90,26 @@ module Enumerize
90
90
 
91
91
  def _set_default_value_for_enumerized_attributes
92
92
  self.class.enumerized_attributes.each do |attr|
93
- next if attr.default_value.nil?
94
- begin
95
- if respond_to?(attr.name)
96
- attr_value = public_send(attr.name)
97
- else
98
- next
99
- end
100
-
101
- value_for_validation = _enumerized_values_for_validation[attr.name.to_s]
102
-
103
- if (!attr_value || attr_value.empty?) && (!value_for_validation || value_for_validation.empty?)
104
- value = Utils.call_if_callable(attr.default_value, self)
105
- public_send("#{attr.name}=", value)
106
- end
107
- rescue ActiveModel::MissingAttributeError
93
+ _set_default_value_for_enumerized_attribute(attr)
94
+ end
95
+ end
96
+
97
+ def _set_default_value_for_enumerized_attribute(attr)
98
+ return if attr.default_value.nil?
99
+ begin
100
+ if respond_to?(attr.name)
101
+ attr_value = public_send(attr.name)
102
+ else
103
+ return
104
+ end
105
+
106
+ value_for_validation = _enumerized_values_for_validation[attr.name.to_s]
107
+
108
+ if (!attr_value || attr_value.empty?) && (!value_for_validation || value_for_validation.empty?)
109
+ value = Utils.call_if_callable(attr.default_value, self)
110
+ public_send("#{attr.name}=", value)
108
111
  end
112
+ rescue ActiveModel::MissingAttributeError
109
113
  end
110
114
  end
111
115
  end
@@ -24,6 +24,13 @@ module Enumerize
24
24
 
25
25
  reloaded
26
26
  end
27
+
28
+ private
29
+
30
+ def _set_default_value_for_enumerized_attribute(attr)
31
+ super
32
+ rescue Mongoid::Errors::AttributeNotLoaded
33
+ end
27
34
  end
28
35
  end
29
36
  end
@@ -17,7 +17,7 @@ module Enumerize
17
17
  end
18
18
 
19
19
  def predicate_method?(method)
20
- method[-1] == '?' && @attr && @attr.values.include?(method[0..-2])
20
+ method[-1] == '?' && @attr && @attr.value?(method[0..-2])
21
21
  end
22
22
  end
23
23
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Enumerize
4
- VERSION = '2.5.0'
4
+ VERSION = '2.6.0'
5
5
  end
data/lib/enumerize.rb CHANGED
@@ -82,7 +82,7 @@ module Enumerize
82
82
  end
83
83
 
84
84
  begin
85
- require 'rspec/matchers'
85
+ require 'rspec'
86
86
  rescue LoadError
87
87
  else
88
88
  require 'enumerize/integrations/rspec'
@@ -4,7 +4,7 @@ require 'test_helper'
4
4
 
5
5
  if defined?(::ActiveModel::Attributes)
6
6
 
7
- describe Enumerize do
7
+ class ActiveModelTest < MiniTest::Spec
8
8
  class ActiveModelUser
9
9
  include ActiveModel::Model
10
10
  include ActiveModel::Attributes
@@ -8,6 +8,9 @@ db = (ENV['DB'] || 'sqlite3').to_sym
8
8
 
9
9
  silence_warnings do
10
10
  ActiveRecord::Migration.verbose = false
11
+ if ActiveRecord::Base.respond_to?(:use_yaml_unsafe_load)
12
+ ActiveRecord::Base.use_yaml_unsafe_load = true
13
+ end
11
14
  ActiveRecord::Base.logger = Logger.new(nil)
12
15
  ActiveRecord::Base.configurations = {
13
16
  'sqlite3' => {
@@ -151,7 +154,7 @@ class SkipValidationsLambdaWithParamUser < ActiveRecord::Base
151
154
  include SkipValidationsLambdaWithParamEnum
152
155
  end
153
156
 
154
- describe Enumerize::ActiveRecordSupport do
157
+ class ActiveRecordTest < MiniTest::Spec
155
158
  it 'sets nil if invalid value is passed' do
156
159
  user = User.new
157
160
  user.sex = :invalid
@@ -511,7 +514,7 @@ describe Enumerize::ActiveRecordSupport do
511
514
  user = User.create(:status => :active)
512
515
  user.status = :blocked
513
516
 
514
- assert_equal [1, 2], YAML.load(user.changes.to_yaml)[:status]
517
+ assert_equal [1, 2], unsafe_yaml_load(user.changes.to_yaml)[:status]
515
518
  end
516
519
 
517
520
  it 'does not change by the practical same value' do
@@ -630,7 +633,7 @@ describe Enumerize::ActiveRecordSupport do
630
633
  end
631
634
 
632
635
  it "doesn't break YAML serialization" do
633
- user = YAML.load(User.create(status: :blocked).to_yaml)
636
+ user = unsafe_yaml_load(User.create(status: :blocked).to_yaml)
634
637
  expect(user.status).must_equal 'blocked'
635
638
  end
636
639
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'test_helper'
4
4
 
5
- describe Enumerize::Attribute do
5
+ class AttributeTest < MiniTest::Spec
6
6
  def attr
7
7
  @attr ||= nil
8
8
  end
data/test/base_test.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'test_helper'
4
4
 
5
- describe Enumerize::Base do
5
+ class BaseTest < MiniTest::Spec
6
6
  let(:kklass) do
7
7
  Class.new do
8
8
  extend Enumerize
@@ -201,4 +201,30 @@ describe Enumerize::Base do
201
201
  object.foo = :b
202
202
  expect(object.foo_value).must_equal 2
203
203
  end
204
+
205
+ it 'allows initialize method with arguments' do
206
+ klass = Class.new do
207
+ extend Enumerize
208
+
209
+ def initialize(argument, key_word_argument: nil); end
210
+ end
211
+
212
+ klass.new('arg1', key_word_argument: 'kwargs1')
213
+ end
214
+
215
+ it 'allows initialize method with arguments for inherited classes' do
216
+ parent_klass = Class.new do
217
+ def initialize(argument, key_word_argument: nil); end
218
+ end
219
+
220
+ klass = Class.new(parent_klass) do
221
+ extend Enumerize
222
+
223
+ def initialize(argument, key_word_argument: nil)
224
+ super
225
+ end
226
+ end
227
+
228
+ klass.new('arg1', key_word_argument: 'kwargs1')
229
+ end
204
230
  end
@@ -10,7 +10,7 @@ end
10
10
 
11
11
  MongoMapper.connection = Mongo::Client.new(['localhost:27017'], database: 'enumerize-test-suite-of-mongomapper')
12
12
 
13
- describe Enumerize do
13
+ class MongoMapperTest < MiniTest::Spec
14
14
  class MongoMapperUser
15
15
  include MongoMapper::Document
16
16
  extend Enumerize
data/test/mongoid_test.rb CHANGED
@@ -13,7 +13,7 @@ Mongoid.configure do |config|
13
13
  config.options = { use_utc: true, include_root_in_json: true }
14
14
  end
15
15
 
16
- describe Enumerize do
16
+ class MongoidTest < MiniTest::Spec
17
17
  class MongoidUser
18
18
  include Mongoid::Document
19
19
  extend Enumerize
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'test_helper'
4
4
 
5
- describe Enumerize::Base do
5
+ class MultipleTest < MiniTest::Spec
6
6
  let(:kklass) do
7
7
  Class.new do
8
8
  extend Enumerize
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'test_helper'
4
4
 
5
- describe Enumerize::Predicates do
5
+ class PredicatesTest < MiniTest::Spec
6
6
  let(:kklass) do
7
7
  Class.new do
8
8
  extend Enumerize
data/test/sequel_test.rb CHANGED
@@ -5,7 +5,7 @@ require 'sequel'
5
5
  require 'logger'
6
6
  require 'jdbc/sqlite3' if RUBY_PLATFORM == 'java'
7
7
 
8
- module SequelTest
8
+ class SequelTest < MiniTest::Spec
9
9
  silence_warnings do
10
10
  DB = if RUBY_PLATFORM == 'java'
11
11
  Sequel.connect('jdbc:sqlite::memory:')
@@ -89,256 +89,254 @@ module SequelTest
89
89
  include SkipValidationsLambdaWithParamEnum
90
90
  end
91
91
 
92
- describe Enumerize::SequelSupport do
93
- it 'sets nil if invalid value is passed' do
94
- user = User.new
95
- user.sex = :invalid
96
- expect(user.sex).must_be_nil
97
- end
92
+ it 'sets nil if invalid value is passed' do
93
+ user = User.new
94
+ user.sex = :invalid
95
+ expect(user.sex).must_be_nil
96
+ end
98
97
 
99
- it 'saves value' do
100
- User.filter{ true }.delete
101
- user = User.new
102
- user.sex = :female
103
- user.save
104
- expect(user.sex).must_equal 'female'
105
- end
98
+ it 'saves value' do
99
+ User.filter{ true }.delete
100
+ user = User.new
101
+ user.sex = :female
102
+ user.save
103
+ expect(user.sex).must_equal 'female'
104
+ end
106
105
 
107
- it 'loads value' do
108
- User.filter{ true }.delete
109
- User.create(:sex => :male)
110
- store_translations(:en, :enumerize => {:sex => {:male => 'Male'}}) do
111
- user = User.first
112
- expect(user.sex).must_equal 'male'
113
- expect(user.sex_text).must_equal 'Male'
114
- end
106
+ it 'loads value' do
107
+ User.filter{ true }.delete
108
+ User.create(:sex => :male)
109
+ store_translations(:en, :enumerize => {:sex => {:male => 'Male'}}) do
110
+ user = User.first
111
+ expect(user.sex).must_equal 'male'
112
+ expect(user.sex_text).must_equal 'Male'
115
113
  end
114
+ end
116
115
 
117
- it 'has default value' do
118
- expect(User.new.role).must_equal 'user'
119
- expect(User.new.values[:role]).must_equal 'user'
120
- end
116
+ it 'has default value' do
117
+ expect(User.new.role).must_equal 'user'
118
+ expect(User.new.values[:role]).must_equal 'user'
119
+ end
121
120
 
122
- it 'does not set default value for not selected attributes' do
123
- User.filter{ true }.delete
124
- User.create(:sex => :male)
121
+ it 'does not set default value for not selected attributes' do
122
+ User.filter{ true }.delete
123
+ User.create(:sex => :male)
125
124
 
126
- assert_equal [:id], User.select(:id).first.values.keys
127
- end
125
+ assert_equal [:id], User.select(:id).first.values.keys
126
+ end
128
127
 
129
- it 'has default value with lambda' do
130
- expect(User.new.lambda_role).must_equal 'admin'
131
- expect(User.new.values[:lambda_role]).must_equal 'admin'
132
- end
133
- it 'uses after_initialize callback to set default value' do
134
- User.filter{ true }.delete
135
- User.create(sex: 'male', lambda_role: nil)
128
+ it 'has default value with lambda' do
129
+ expect(User.new.lambda_role).must_equal 'admin'
130
+ expect(User.new.values[:lambda_role]).must_equal 'admin'
131
+ end
132
+ it 'uses after_initialize callback to set default value' do
133
+ User.filter{ true }.delete
134
+ User.create(sex: 'male', lambda_role: nil)
136
135
 
137
- user = User.where(:sex => 'male').first
138
- expect(user.lambda_role).must_equal 'admin'
139
- end
136
+ user = User.where(:sex => 'male').first
137
+ expect(user.lambda_role).must_equal 'admin'
138
+ end
140
139
 
141
- it 'uses default value from db column' do
142
- expect(User.new.account_type).must_equal 'basic'
143
- end
140
+ it 'uses default value from db column' do
141
+ expect(User.new.account_type).must_equal 'basic'
142
+ end
144
143
 
145
- it 'validates inclusion' do
146
- user = User.new
147
- user.role = 'wrong'
148
- expect(user).wont_be :valid?
149
- expect(user.errors[:role]).must_include 'is not included in the list'
150
- end
144
+ it 'validates inclusion' do
145
+ user = User.new
146
+ user.role = 'wrong'
147
+ expect(user).wont_be :valid?
148
+ expect(user.errors[:role]).must_include 'is not included in the list'
149
+ end
151
150
 
152
- it 'validates inclusion on mass assignment' do
153
- assert_raises Sequel::ValidationFailed do
154
- User.create(role: 'wrong')
155
- end
151
+ it 'validates inclusion on mass assignment' do
152
+ assert_raises Sequel::ValidationFailed do
153
+ User.create(role: 'wrong')
156
154
  end
155
+ end
157
156
 
158
- it "uses persisted value for validation if it hasn't been set" do
159
- user = User.create :sex => :male
160
- expect(User[user.id].read_attribute_for_validation(:sex)).must_equal 'male'
161
- end
157
+ it "uses persisted value for validation if it hasn't been set" do
158
+ user = User.create :sex => :male
159
+ expect(User[user.id].read_attribute_for_validation(:sex)).must_equal 'male'
160
+ end
162
161
 
163
- it 'is valid with empty string assigned' do
164
- user = User.new
165
- user.role = ''
166
- expect(user).must_be :valid?
167
- end
162
+ it 'is valid with empty string assigned' do
163
+ user = User.new
164
+ user.role = ''
165
+ expect(user).must_be :valid?
166
+ end
168
167
 
169
- it 'stores nil when empty string assigned' do
170
- user = User.new
171
- user.role = ''
172
- expect(user.values[:role]).must_be_nil
173
- end
168
+ it 'stores nil when empty string assigned' do
169
+ user = User.new
170
+ user.role = ''
171
+ expect(user.values[:role]).must_be_nil
172
+ end
174
173
 
175
- it 'validates inclusion when :skip_validations = false' do
176
- user = DoNotSkipValidationsUser.new
177
- user.foo = 'wrong'
178
- expect(user).wont_be :valid?
179
- expect(user.errors[:foo]).must_include 'is not included in the list'
180
- end
174
+ it 'validates inclusion when :skip_validations = false' do
175
+ user = DoNotSkipValidationsUser.new
176
+ user.foo = 'wrong'
177
+ expect(user).wont_be :valid?
178
+ expect(user.errors[:foo]).must_include 'is not included in the list'
179
+ end
181
180
 
182
- it 'does not validate inclusion when :skip_validations = true' do
183
- user = SkipValidationsUser.new
184
- user.foo = 'wrong'
185
- expect(user).must_be :valid?
186
- end
181
+ it 'does not validate inclusion when :skip_validations = true' do
182
+ user = SkipValidationsUser.new
183
+ user.foo = 'wrong'
184
+ expect(user).must_be :valid?
185
+ end
187
186
 
188
- it 'supports :skip_validations option as lambda' do
189
- user = SkipValidationsLambdaUser.new
190
- user.foo = 'wrong'
191
- expect(user).must_be :valid?
192
- end
187
+ it 'supports :skip_validations option as lambda' do
188
+ user = SkipValidationsLambdaUser.new
189
+ user.foo = 'wrong'
190
+ expect(user).must_be :valid?
191
+ end
193
192
 
194
- it 'supports :skip_validations option as lambda with a parameter' do
195
- user = SkipValidationsLambdaWithParamUser.new
196
- user.foo = 'wrong'
197
- expect(user).must_be :valid?
198
- end
193
+ it 'supports :skip_validations option as lambda with a parameter' do
194
+ user = SkipValidationsLambdaWithParamUser.new
195
+ user.foo = 'wrong'
196
+ expect(user).must_be :valid?
197
+ end
199
198
 
200
- it 'supports multiple attributes' do
201
- user = User.new
202
- user.interests ||= []
203
- expect(user.interests).must_be_empty
204
- user.interests << "music"
205
- expect(user.interests).must_equal %w(music)
206
- user.save
207
-
208
- user = User[user.id]
209
- expect(user.interests).must_be_instance_of Enumerize::Set
210
- expect(user.interests).must_equal %w(music)
211
- user.interests << "sports"
212
- expect(user.interests).must_equal %w(music sports)
213
-
214
- user.interests = []
215
- interests = user.interests
216
- interests << "music"
217
- expect(interests).must_equal %w(music)
218
- interests << "dancing"
219
- expect(interests).must_equal %w(music dancing)
220
- end
199
+ it 'supports multiple attributes' do
200
+ user = User.new
201
+ user.interests ||= []
202
+ expect(user.interests).must_be_empty
203
+ user.interests << "music"
204
+ expect(user.interests).must_equal %w(music)
205
+ user.save
206
+
207
+ user = User[user.id]
208
+ expect(user.interests).must_be_instance_of Enumerize::Set
209
+ expect(user.interests).must_equal %w(music)
210
+ user.interests << "sports"
211
+ expect(user.interests).must_equal %w(music sports)
212
+
213
+ user.interests = []
214
+ interests = user.interests
215
+ interests << "music"
216
+ expect(interests).must_equal %w(music)
217
+ interests << "dancing"
218
+ expect(interests).must_equal %w(music dancing)
219
+ end
221
220
 
222
- it 'returns invalid multiple value for validation' do
223
- user = User.new
224
- user.interests << :music
225
- user.interests << :invalid
226
- values = user.read_attribute_for_validation(:interests)
227
- expect(values).must_equal %w(music invalid)
228
- end
221
+ it 'returns invalid multiple value for validation' do
222
+ user = User.new
223
+ user.interests << :music
224
+ user.interests << :invalid
225
+ values = user.read_attribute_for_validation(:interests)
226
+ expect(values).must_equal %w(music invalid)
227
+ end
229
228
 
230
- it 'validates multiple attributes' do
231
- user = User.new
232
- user.interests << :invalid
233
- expect(user).wont_be :valid?
229
+ it 'validates multiple attributes' do
230
+ user = User.new
231
+ user.interests << :invalid
232
+ expect(user).wont_be :valid?
234
233
 
235
- user.interests = Object.new
236
- expect(user).wont_be :valid?
234
+ user.interests = Object.new
235
+ expect(user).wont_be :valid?
237
236
 
238
- user.interests = ['music', '']
239
- expect(user).must_be :valid?
240
- end
237
+ user.interests = ['music', '']
238
+ expect(user).must_be :valid?
239
+ end
241
240
 
242
- it 'stores custom values for multiple attributes' do
243
- User.filter{ true }.delete
241
+ it 'stores custom values for multiple attributes' do
242
+ User.filter{ true }.delete
244
243
 
245
- klass = Class.new(User)
246
- klass.enumerize :interests, in: { music: 0, sports: 1, dancing: 2, programming: 3}, multiple: true
244
+ klass = Class.new(User)
245
+ klass.enumerize :interests, in: { music: 0, sports: 1, dancing: 2, programming: 3}, multiple: true
247
246
 
248
- user = klass.new
249
- user.interests << :music
250
- expect(user.interests).must_equal %w(music)
251
- user.save
247
+ user = klass.new
248
+ user.interests << :music
249
+ expect(user.interests).must_equal %w(music)
250
+ user.save
252
251
 
253
- user = klass[user.id]
254
- expect(user.interests).must_equal %w(music)
255
- end
252
+ user = klass[user.id]
253
+ expect(user.interests).must_equal %w(music)
254
+ end
256
255
 
257
- it 'adds scope' do
258
- User.filter{ true }.delete
256
+ it 'adds scope' do
257
+ User.filter{ true }.delete
259
258
 
260
- user_1 = User.create(sex: :female, skill: :noob, status: :active, role: :admin)
261
- user_2 = User.create(sex: :female, skill: :casual, status: :blocked)
262
- user_3 = User.create(sex: :male, skill: :pro)
259
+ user_1 = User.create(sex: :female, skill: :noob, status: :active, role: :admin)
260
+ user_2 = User.create(sex: :female, skill: :casual, status: :blocked)
261
+ user_3 = User.create(sex: :male, skill: :pro)
263
262
 
264
- expect(User.with_status(:active).to_a).must_equal [user_1]
265
- expect(User.with_status(:blocked).to_a).must_equal [user_2]
266
- expect(User.with_status(:active, :blocked).to_set).must_equal [user_1, user_2].to_set
263
+ expect(User.with_status(:active).to_a).must_equal [user_1]
264
+ expect(User.with_status(:blocked).to_a).must_equal [user_2]
265
+ expect(User.with_status(:active, :blocked).to_set).must_equal [user_1, user_2].to_set
267
266
 
268
- expect(User.without_status(:active).to_a).must_equal [user_2]
269
- expect(User.without_status(:active, :blocked).to_a).must_equal []
267
+ expect(User.without_status(:active).to_a).must_equal [user_2]
268
+ expect(User.without_status(:active, :blocked).to_a).must_equal []
270
269
 
271
- expect(User.having_role(:admin).to_a).must_equal [user_1]
272
- expect(User.male.to_a).must_equal [user_3]
273
- expect(User.pro.to_a).must_equal [user_3]
270
+ expect(User.having_role(:admin).to_a).must_equal [user_1]
271
+ expect(User.male.to_a).must_equal [user_3]
272
+ expect(User.pro.to_a).must_equal [user_3]
274
273
 
275
- expect(User.not_male.to_set).must_equal [user_1, user_2].to_set
276
- expect(User.not_pro.to_set).must_equal [user_1, user_2].to_set
277
- end
274
+ expect(User.not_male.to_set).must_equal [user_1, user_2].to_set
275
+ expect(User.not_pro.to_set).must_equal [user_1, user_2].to_set
276
+ end
278
277
 
279
- it 'allows either key or value as valid' do
280
- user_1 = User.new(status: :active)
281
- user_2 = User.new(status: 1)
282
- user_3 = User.new(status: '1')
278
+ it 'allows either key or value as valid' do
279
+ user_1 = User.new(status: :active)
280
+ user_2 = User.new(status: 1)
281
+ user_3 = User.new(status: '1')
283
282
 
284
- expect(user_1.status).must_equal 'active'
285
- expect(user_2.status).must_equal 'active'
286
- expect(user_3.status).must_equal 'active'
283
+ expect(user_1.status).must_equal 'active'
284
+ expect(user_2.status).must_equal 'active'
285
+ expect(user_3.status).must_equal 'active'
287
286
 
288
- expect(user_1).must_be :valid?
289
- expect(user_2).must_be :valid?
290
- expect(user_3).must_be :valid?
291
- end
287
+ expect(user_1).must_be :valid?
288
+ expect(user_2).must_be :valid?
289
+ expect(user_3).must_be :valid?
290
+ end
292
291
 
293
- it 'supports defining enumerized attributes on abstract class' do
294
- Document.filter{ true }.delete
292
+ it 'supports defining enumerized attributes on abstract class' do
293
+ Document.filter{ true }.delete
295
294
 
296
- document = Document.new
297
- document.visibility = :protected
298
- expect(document.visibility).must_equal 'protected'
299
- end
295
+ document = Document.new
296
+ document.visibility = :protected
297
+ expect(document.visibility).must_equal 'protected'
298
+ end
300
299
 
301
- it 'supports defining enumerized scopes on abstract class' do
302
- Document.filter{ true }.delete
300
+ it 'supports defining enumerized scopes on abstract class' do
301
+ Document.filter{ true }.delete
303
302
 
304
- document_1 = Document.create(visibility: :public)
305
- document_2 = Document.create(visibility: :private)
303
+ document_1 = Document.create(visibility: :public)
304
+ document_2 = Document.create(visibility: :private)
306
305
 
307
- expect(Document.with_visibility(:public).to_a).must_equal [document_1]
308
- end
306
+ expect(Document.with_visibility(:public).to_a).must_equal [document_1]
307
+ end
309
308
 
310
- it 'validates uniqueness' do
311
- user = User.create(status: :active, sex: "male")
309
+ it 'validates uniqueness' do
310
+ user = User.create(status: :active, sex: "male")
312
311
 
313
- user = UniqStatusUser.new
314
- user.sex = "male"
315
- user.status = :active
316
- expect(user.valid?).must_equal false
312
+ user = UniqStatusUser.new
313
+ user.sex = "male"
314
+ user.status = :active
315
+ expect(user.valid?).must_equal false
317
316
 
318
- expect(user.errors[:status]).wont_be :empty?
319
- end
317
+ expect(user.errors[:status]).wont_be :empty?
318
+ end
320
319
 
321
- it "doesn't update record" do
322
- Document.filter{ true }.delete
320
+ it "doesn't update record" do
321
+ Document.filter{ true }.delete
323
322
 
324
- expected = Time.new(2010, 10, 10)
323
+ expected = Time.new(2010, 10, 10)
325
324
 
326
- document = Document.new
327
- document.updated_at = expected
328
- document.save
325
+ document = Document.new
326
+ document.updated_at = expected
327
+ document.save
329
328
 
330
- document = Document.last
331
- document.save
329
+ document = Document.last
330
+ document.save
332
331
 
333
- assert_equal expected, document.updated_at
334
- end
332
+ assert_equal expected, document.updated_at
333
+ end
335
334
 
336
- it 'changes from dirty should be serialized as scalar values' do
337
- user = User.create(:status => :active)
338
- user.status = :blocked
335
+ it 'changes from dirty should be serialized as scalar values' do
336
+ user = User.create(:status => :active)
337
+ user.status = :blocked
339
338
 
340
- expected = { status: [1, 2] }.to_yaml
341
- assert_equal expected, user.column_changes.to_yaml
342
- end
339
+ expected = { status: [1, 2] }.to_yaml
340
+ assert_equal expected, user.column_changes.to_yaml
343
341
  end
344
342
  end
data/test/set_test.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  require 'test_helper'
4
4
  require 'yaml'
5
5
 
6
- describe Enumerize::Set do
6
+ class SetTest < MiniTest::Spec
7
7
  let(:kklass) do
8
8
  Class.new do
9
9
  extend Enumerize
data/test/test_helper.rb CHANGED
@@ -46,6 +46,14 @@ module MiscHelpers
46
46
  I18n.reload!
47
47
  end
48
48
  end
49
+
50
+ def unsafe_yaml_load(yaml)
51
+ if YAML.respond_to?(:unsafe_load)
52
+ YAML.unsafe_load(yaml)
53
+ else
54
+ YAML.load(yaml)
55
+ end
56
+ end
49
57
  end
50
58
 
51
59
  class MiniTest::Spec
data/test/value_test.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  require 'test_helper'
4
4
  require 'yaml'
5
5
 
6
- describe Enumerize::Value do
6
+ class ValueTest < MiniTest::Spec
7
7
  class Model
8
8
  end
9
9
 
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.5.0
4
+ version: 2.6.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: 2021-12-24 00:00:00.000000000 Z
11
+ date: 2023-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -99,7 +99,7 @@ homepage: https://github.com/brainspec/enumerize
99
99
  licenses:
100
100
  - MIT
101
101
  metadata: {}
102
- post_install_message:
102
+ post_install_message:
103
103
  rdoc_options: []
104
104
  require_paths:
105
105
  - lib
@@ -107,15 +107,37 @@ required_ruby_version: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
- version: 1.9.3
110
+ version: '2.7'
111
111
  required_rubygems_version: !ruby/object:Gem::Requirement
112
112
  requirements:
113
113
  - - ">="
114
114
  - !ruby/object:Gem::Version
115
115
  version: '0'
116
116
  requirements: []
117
- rubygems_version: 3.0.9
118
- signing_key:
117
+ rubygems_version: 3.4.7
118
+ signing_key:
119
119
  specification_version: 4
120
120
  summary: Enumerated attributes with I18n and ActiveRecord/Mongoid/MongoMapper support
121
- test_files: []
121
+ test_files:
122
+ - spec/enumerize/integrations/rspec/matcher_spec.rb
123
+ - spec/spec_helper.rb
124
+ - test/activemodel_test.rb
125
+ - test/activerecord_test.rb
126
+ - test/attribute_map_test.rb
127
+ - test/attribute_test.rb
128
+ - test/base_test.rb
129
+ - test/formtastic_test.rb
130
+ - test/module_attributes_test.rb
131
+ - test/mongo_mapper_test.rb
132
+ - test/mongoid_test.rb
133
+ - test/multiple_test.rb
134
+ - test/predicates_test.rb
135
+ - test/rails_admin_test.rb
136
+ - test/sequel_test.rb
137
+ - test/set_test.rb
138
+ - test/simple_form_test.rb
139
+ - test/support/mock_controller.rb
140
+ - test/support/shared_enums.rb
141
+ - test/support/view_test_helper.rb
142
+ - test/test_helper.rb
143
+ - test/value_test.rb