enumerize 2.1.2 → 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 +5 -5
- data/.travis.yml +10 -9
- data/CHANGELOG.md +50 -3
- 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 +37 -1
- data/Rakefile +2 -0
- data/lib/enumerize.rb +9 -0
- data/lib/enumerize/activemodel.rb +47 -0
- data/lib/enumerize/activerecord.rb +33 -3
- data/lib/enumerize/attribute.rb +19 -11
- data/lib/enumerize/attribute_map.rb +2 -0
- data/lib/enumerize/base.rb +6 -6
- data/lib/enumerize/hooks/formtastic.rb +4 -1
- data/lib/enumerize/hooks/sequel_dataset.rb +2 -0
- data/lib/enumerize/hooks/simple_form.rb +4 -1
- data/lib/enumerize/hooks/uniqueness.rb +5 -1
- data/lib/enumerize/integrations/rails_admin.rb +3 -1
- data/lib/enumerize/integrations/rspec.rb +2 -0
- data/lib/enumerize/integrations/rspec/matcher.rb +7 -2
- data/lib/enumerize/module.rb +2 -0
- data/lib/enumerize/module_attributes.rb +2 -0
- data/lib/enumerize/mongoid.rb +16 -0
- data/lib/enumerize/predicatable.rb +3 -1
- data/lib/enumerize/predicates.rb +2 -0
- data/lib/enumerize/scope/activerecord.rb +12 -0
- data/lib/enumerize/scope/mongoid.rb +11 -0
- data/lib/enumerize/scope/sequel.rb +12 -0
- data/lib/enumerize/sequel.rb +9 -4
- data/lib/enumerize/set.rb +2 -0
- data/lib/enumerize/utils.rb +12 -0
- data/lib/enumerize/value.rb +14 -15
- data/lib/enumerize/version.rb +1 -1
- data/lib/sequel/plugins/enumerize.rb +18 -0
- data/spec/enumerize/integrations/rspec/matcher_spec.rb +13 -10
- data/spec/spec_helper.rb +2 -0
- data/test/activemodel_test.rb +114 -0
- data/test/activerecord_test.rb +127 -5
- data/test/attribute_map_test.rb +2 -0
- data/test/attribute_test.rb +7 -0
- data/test/base_test.rb +35 -33
- data/test/formtastic_test.rb +25 -0
- data/test/module_attributes_test.rb +2 -0
- data/test/mongo_mapper_test.rb +12 -3
- data/test/mongoid_test.rb +30 -4
- data/test/multiple_test.rb +19 -11
- data/test/predicates_test.rb +12 -10
- data/test/rails_admin_test.rb +7 -5
- data/test/sequel_test.rb +62 -12
- data/test/set_test.rb +6 -4
- data/test/simple_form_test.rb +25 -0
- data/test/support/mock_controller.rb +2 -0
- data/test/support/shared_enums.rb +43 -0
- data/test/support/view_test_helper.rb +14 -1
- data/test/test_helper.rb +2 -0
- data/test/value_test.rb +33 -5
- metadata +15 -9
- data/Gemfile.rails42 +0 -7
- data/Gemfile.rails51 +0 -7
data/test/set_test.rb
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'test_helper'
|
|
2
4
|
require 'yaml'
|
|
3
5
|
|
|
4
6
|
describe Enumerize::Set do
|
|
5
|
-
let(:
|
|
7
|
+
let(:kklass) do
|
|
6
8
|
Class.new do
|
|
7
9
|
extend Enumerize
|
|
8
10
|
enumerize :foo, :in => %w(a b c), :multiple => true
|
|
9
11
|
end
|
|
10
12
|
end
|
|
11
13
|
|
|
12
|
-
let(:object) {
|
|
14
|
+
let(:object) { kklass.new }
|
|
13
15
|
|
|
14
16
|
def build_set(values)
|
|
15
|
-
@set = Enumerize::Set.new(object,
|
|
17
|
+
@set = Enumerize::Set.new(object, kklass.foo, values)
|
|
16
18
|
end
|
|
17
19
|
|
|
18
20
|
def set
|
|
@@ -39,7 +41,7 @@ describe Enumerize::Set do
|
|
|
39
41
|
end
|
|
40
42
|
|
|
41
43
|
it 'equals to other set' do
|
|
42
|
-
set.must_equal Enumerize::Set.new(nil,
|
|
44
|
+
set.must_equal Enumerize::Set.new(nil, kklass.foo, %w(a))
|
|
43
45
|
end
|
|
44
46
|
|
|
45
47
|
it 'equals to array' do
|
data/test/simple_form_test.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'test_helper'
|
|
2
4
|
require 'simple_form/version'
|
|
3
5
|
|
|
@@ -40,6 +42,12 @@ class SimpleFormSpec < MiniTest::Spec
|
|
|
40
42
|
end
|
|
41
43
|
end
|
|
42
44
|
|
|
45
|
+
class Registration < Struct.new(:sex)
|
|
46
|
+
extend Enumerize
|
|
47
|
+
|
|
48
|
+
enumerize :sex, in: [:male, :female]
|
|
49
|
+
end
|
|
50
|
+
|
|
43
51
|
let(:user) { User.new }
|
|
44
52
|
let(:post) { Post.new }
|
|
45
53
|
|
|
@@ -128,4 +136,21 @@ class SimpleFormSpec < MiniTest::Spec
|
|
|
128
136
|
|
|
129
137
|
assert_select 'input.string'
|
|
130
138
|
end
|
|
139
|
+
|
|
140
|
+
it 'renders select with enumerized values for non-ActiveModel object' do
|
|
141
|
+
concat(simple_form_for(Registration.new, as: 'registration', url: '/') do |f|
|
|
142
|
+
f.input(:sex)
|
|
143
|
+
end)
|
|
144
|
+
|
|
145
|
+
assert_select 'select option[value=male]'
|
|
146
|
+
assert_select 'select option[value=female]'
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
it 'does not affect forms without object' do
|
|
150
|
+
concat(simple_form_for('') do |f|
|
|
151
|
+
f.input(:name)
|
|
152
|
+
end)
|
|
153
|
+
|
|
154
|
+
assert_select 'input.string'
|
|
155
|
+
end
|
|
131
156
|
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'active_record'
|
|
4
|
+
require 'sequel'
|
|
5
|
+
|
|
6
|
+
module EnumerizeExtention
|
|
7
|
+
def self.included(base)
|
|
8
|
+
case
|
|
9
|
+
when base < ActiveRecord::Base
|
|
10
|
+
base.extend Enumerize
|
|
11
|
+
when base < Sequel::Model
|
|
12
|
+
base.plugin :enumerize
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
module SkipValidationsEnum
|
|
18
|
+
def self.included(base)
|
|
19
|
+
base.include EnumerizeExtention
|
|
20
|
+
base.enumerize :foo, :in => [:bar, :baz], :skip_validations => true
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
module DoNotSkipValidationsEnum
|
|
25
|
+
def self.included(base)
|
|
26
|
+
base.include EnumerizeExtention
|
|
27
|
+
base.enumerize :foo, :in => [:bar, :baz], :skip_validations => false
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
module SkipValidationsLambdaEnum
|
|
32
|
+
def self.included(base)
|
|
33
|
+
base.include EnumerizeExtention
|
|
34
|
+
base.enumerize :foo, :in => [:bar, :baz], :skip_validations => lambda { true }
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
module SkipValidationsLambdaWithParamEnum
|
|
39
|
+
def self.included(base)
|
|
40
|
+
base.include EnumerizeExtention
|
|
41
|
+
base.enumerize :foo, :in => [:bar, :baz], :skip_validations => lambda { |record| true }
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'active_support/concern'
|
|
2
4
|
require 'active_support/testing/setup_and_teardown'
|
|
3
5
|
|
|
@@ -5,10 +7,21 @@ if defined?(ActionView::RoutingUrlFor)
|
|
|
5
7
|
ActionView::RoutingUrlFor.send(:include, ActionDispatch::Routing::UrlFor)
|
|
6
8
|
end
|
|
7
9
|
|
|
8
|
-
module
|
|
10
|
+
module SetupAndTeardownHelper
|
|
9
11
|
extend ActiveSupport::Concern
|
|
10
12
|
|
|
11
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
|
|
12
25
|
include ActionView::TestCase::Behavior
|
|
13
26
|
|
|
14
27
|
included do
|
data/test/test_helper.rb
CHANGED
data/test/value_test.rb
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'test_helper'
|
|
2
4
|
require 'yaml'
|
|
3
5
|
|
|
4
6
|
describe Enumerize::Value do
|
|
5
|
-
class
|
|
7
|
+
class Model
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
class Attr < Struct.new(:values, :name, :i18n_scopes, :klass)
|
|
6
11
|
end
|
|
7
12
|
|
|
8
|
-
let(:attr) { Attr.new([]) }
|
|
9
|
-
let(:val)
|
|
13
|
+
let(:attr) { Attr.new([], "attribute_name", [], Model) }
|
|
14
|
+
let(:val) { Enumerize::Value.new(attr, 'test_value', 1) }
|
|
10
15
|
|
|
11
16
|
it 'is a string' do
|
|
12
17
|
val.must_be_kind_of String
|
|
@@ -30,8 +35,6 @@ describe Enumerize::Value do
|
|
|
30
35
|
end
|
|
31
36
|
|
|
32
37
|
describe 'translation' do
|
|
33
|
-
let(:attr) { Struct.new(:values, :name, :i18n_scopes).new([], "attribute_name", []) }
|
|
34
|
-
|
|
35
38
|
it 'uses common translation' do
|
|
36
39
|
store_translations(:en, :enumerize => {:attribute_name => {:test_value => "Common translation"}}) do
|
|
37
40
|
val.text.must_be :==, "Common translation"
|
|
@@ -81,6 +84,13 @@ describe Enumerize::Value do
|
|
|
81
84
|
val.text.must_be :==, "Scope specific translation"
|
|
82
85
|
end
|
|
83
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
|
|
84
94
|
end
|
|
85
95
|
|
|
86
96
|
describe 'boolean methods comparison' do
|
|
@@ -120,6 +130,14 @@ describe Enumerize::Value do
|
|
|
120
130
|
it "doesn't respond to a method for not existing value" do
|
|
121
131
|
val.wont_respond_to :some_method?
|
|
122
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
|
|
123
141
|
end
|
|
124
142
|
|
|
125
143
|
describe 'serialization' do
|
|
@@ -134,4 +152,14 @@ describe Enumerize::Value do
|
|
|
134
152
|
Marshal.load(dump_value).must_equal 'test_value'
|
|
135
153
|
end
|
|
136
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
|
|
137
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,13 +38,14 @@ files:
|
|
|
38
38
|
- Gemfile
|
|
39
39
|
- Gemfile.global
|
|
40
40
|
- Gemfile.mongo_mapper
|
|
41
|
-
- Gemfile.
|
|
42
|
-
- Gemfile.
|
|
41
|
+
- Gemfile.rails60
|
|
42
|
+
- Gemfile.rails61
|
|
43
43
|
- MIT-LICENSE
|
|
44
44
|
- README.md
|
|
45
45
|
- Rakefile
|
|
46
46
|
- enumerize.gemspec
|
|
47
47
|
- lib/enumerize.rb
|
|
48
|
+
- lib/enumerize/activemodel.rb
|
|
48
49
|
- lib/enumerize/activerecord.rb
|
|
49
50
|
- lib/enumerize/attribute.rb
|
|
50
51
|
- lib/enumerize/attribute_map.rb
|
|
@@ -66,10 +67,13 @@ files:
|
|
|
66
67
|
- lib/enumerize/scope/sequel.rb
|
|
67
68
|
- lib/enumerize/sequel.rb
|
|
68
69
|
- lib/enumerize/set.rb
|
|
70
|
+
- lib/enumerize/utils.rb
|
|
69
71
|
- lib/enumerize/value.rb
|
|
70
72
|
- lib/enumerize/version.rb
|
|
73
|
+
- lib/sequel/plugins/enumerize.rb
|
|
71
74
|
- spec/enumerize/integrations/rspec/matcher_spec.rb
|
|
72
75
|
- spec/spec_helper.rb
|
|
76
|
+
- test/activemodel_test.rb
|
|
73
77
|
- test/activerecord_test.rb
|
|
74
78
|
- test/attribute_map_test.rb
|
|
75
79
|
- test/attribute_test.rb
|
|
@@ -85,6 +89,7 @@ files:
|
|
|
85
89
|
- test/set_test.rb
|
|
86
90
|
- test/simple_form_test.rb
|
|
87
91
|
- test/support/mock_controller.rb
|
|
92
|
+
- test/support/shared_enums.rb
|
|
88
93
|
- test/support/view_test_helper.rb
|
|
89
94
|
- test/test_helper.rb
|
|
90
95
|
- test/value_test.rb
|
|
@@ -92,7 +97,7 @@ homepage: https://github.com/brainspec/enumerize
|
|
|
92
97
|
licenses:
|
|
93
98
|
- MIT
|
|
94
99
|
metadata: {}
|
|
95
|
-
post_install_message:
|
|
100
|
+
post_install_message:
|
|
96
101
|
rdoc_options: []
|
|
97
102
|
require_paths:
|
|
98
103
|
- lib
|
|
@@ -107,14 +112,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
107
112
|
- !ruby/object:Gem::Version
|
|
108
113
|
version: '0'
|
|
109
114
|
requirements: []
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
signing_key:
|
|
115
|
+
rubygems_version: 3.0.8
|
|
116
|
+
signing_key:
|
|
113
117
|
specification_version: 4
|
|
114
118
|
summary: Enumerated attributes with I18n and ActiveRecord/Mongoid/MongoMapper support
|
|
115
119
|
test_files:
|
|
116
120
|
- spec/enumerize/integrations/rspec/matcher_spec.rb
|
|
117
121
|
- spec/spec_helper.rb
|
|
122
|
+
- test/activemodel_test.rb
|
|
118
123
|
- test/activerecord_test.rb
|
|
119
124
|
- test/attribute_map_test.rb
|
|
120
125
|
- test/attribute_test.rb
|
|
@@ -130,6 +135,7 @@ test_files:
|
|
|
130
135
|
- test/set_test.rb
|
|
131
136
|
- test/simple_form_test.rb
|
|
132
137
|
- test/support/mock_controller.rb
|
|
138
|
+
- test/support/shared_enums.rb
|
|
133
139
|
- test/support/view_test_helper.rb
|
|
134
140
|
- test/test_helper.rb
|
|
135
141
|
- test/value_test.rb
|
data/Gemfile.rails42
DELETED
data/Gemfile.rails51
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
eval_gemfile('Gemfile.global')
|
|
2
|
-
|
|
3
|
-
gem 'minitest', '~> 5.8'
|
|
4
|
-
gem 'rails', '5.1.0.rc1', require: false
|
|
5
|
-
gem 'activerecord-jdbcsqlite3-adapter', github: 'jruby/activerecord-jdbc-adapter', branch: 'rails-5', platform: :jruby
|
|
6
|
-
gem 'activerecord-jdbcpostgresql-adapter', github: 'jruby/activerecord-jdbc-adapter', branch: 'rails-5', platform: :jruby
|
|
7
|
-
gem 'mongoid', github: 'mongodb/mongoid'
|