enumerize 2.4.0 → 2.6.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/.github/workflows/ruby.yml +73 -0
- data/CHANGELOG.md +15 -0
- data/Gemfile +1 -1
- data/Gemfile.global +1 -8
- data/Gemfile.rails70 +9 -0
- data/Gemfile.railsmaster +5 -0
- data/README.md +183 -102
- data/enumerize.gemspec +1 -1
- data/lib/enumerize/activerecord.rb +7 -3
- data/lib/enumerize/attribute.rb +4 -0
- data/lib/enumerize/base.rb +20 -16
- data/lib/enumerize/mongoid.rb +7 -0
- data/lib/enumerize/predicatable.rb +1 -1
- data/lib/enumerize/scope/activerecord.rb +4 -0
- data/lib/enumerize/scope/mongoid.rb +4 -0
- data/lib/enumerize/scope/sequel.rb +4 -0
- data/lib/enumerize/version.rb +1 -1
- data/lib/enumerize.rb +1 -1
- data/test/activemodel_test.rb +23 -23
- data/test/activerecord_test.rb +135 -109
- data/test/attribute_map_test.rb +7 -7
- data/test/attribute_test.rb +32 -32
- data/test/base_test.rb +62 -36
- data/test/module_attributes_test.rb +8 -8
- data/test/mongo_mapper_test.rb +9 -9
- data/test/mongoid_test.rb +31 -28
- data/test/multiple_test.rb +9 -9
- data/test/predicates_test.rb +19 -19
- data/test/rails_admin_test.rb +2 -2
- data/test/sequel_test.rb +199 -198
- data/test/set_test.rb +24 -24
- data/test/test_helper.rb +8 -0
- data/test/value_test.rb +29 -36
- metadata +7 -5
- data/.travis.yml +0 -35
data/test/set_test.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'test_helper'
|
4
4
|
require 'yaml'
|
5
5
|
|
6
|
-
|
6
|
+
class SetTest < MiniTest::Spec
|
7
7
|
let(:kklass) do
|
8
8
|
Class.new do
|
9
9
|
extend Enumerize
|
@@ -41,36 +41,36 @@ describe Enumerize::Set do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'equals to other set' do
|
44
|
-
set.must_equal Enumerize::Set.new(nil, kklass.foo, %w(a))
|
44
|
+
expect(set).must_equal Enumerize::Set.new(nil, kklass.foo, %w(a))
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'equals to array' do
|
48
|
-
set.must_equal %w(a)
|
48
|
+
expect(set).must_equal %w(a)
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'equals to array of symbols' do
|
52
|
-
set.must_equal [:a]
|
52
|
+
expect(set).must_equal [:a]
|
53
53
|
end
|
54
54
|
|
55
55
|
it 'has unique values' do
|
56
56
|
set << :a
|
57
|
-
set.must_equal %w(a)
|
57
|
+
expect(set).must_equal %w(a)
|
58
58
|
end
|
59
59
|
|
60
60
|
it 'equals to array with different value order' do
|
61
61
|
set << :b
|
62
|
-
set.must_equal %w(b a)
|
62
|
+
expect(set).must_equal %w(b a)
|
63
63
|
end
|
64
64
|
|
65
65
|
it "isn't equal to a part of values" do
|
66
66
|
set << :b
|
67
|
-
set.wont_equal %w(a)
|
67
|
+
expect(set).wont_equal %w(a)
|
68
68
|
end
|
69
69
|
|
70
70
|
describe '#push' do
|
71
71
|
it 'appends values' do
|
72
72
|
set.push :b
|
73
|
-
set.must_include :b
|
73
|
+
expect(set).must_include :b
|
74
74
|
end
|
75
75
|
|
76
76
|
it 'reassigns attribute' do
|
@@ -83,7 +83,7 @@ describe Enumerize::Set do
|
|
83
83
|
describe '#delete' do
|
84
84
|
it 'deletes value' do
|
85
85
|
set.delete :a
|
86
|
-
set.wont_include :a
|
86
|
+
expect(set).wont_include :a
|
87
87
|
end
|
88
88
|
|
89
89
|
it 'reassigns attribute' do
|
@@ -96,64 +96,64 @@ describe Enumerize::Set do
|
|
96
96
|
describe '#inspect' do
|
97
97
|
it 'returns custom string' do
|
98
98
|
set << :b
|
99
|
-
set.inspect.must_equal '#<Enumerize::Set {a, b}>'
|
99
|
+
expect(set.inspect).must_equal '#<Enumerize::Set {a, b}>'
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
103
103
|
describe '#to_ary' do
|
104
104
|
it 'returns array' do
|
105
|
-
set.to_ary.must_be_instance_of Array
|
105
|
+
expect(set.to_ary).must_be_instance_of Array
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
109
|
describe '#texts' do
|
110
110
|
it 'returns array of text values' do
|
111
|
-
set.texts.must_equal ['A']
|
111
|
+
expect(set.texts).must_equal ['A']
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
115
|
describe '#join' do
|
116
116
|
it 'joins values' do
|
117
117
|
set << :b
|
118
|
-
set.join(', ').must_equal 'a, b'
|
118
|
+
expect(set.join(', ')).must_equal 'a, b'
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
122
122
|
describe 'boolean methods comparison' do
|
123
123
|
it 'returns true if value equals method' do
|
124
124
|
set << :a
|
125
|
-
set.a
|
125
|
+
expect(set.a?).must_equal true
|
126
126
|
end
|
127
127
|
|
128
128
|
it 'returns false if value does not equal method' do
|
129
129
|
set << :a
|
130
|
-
set.b
|
130
|
+
expect(set.b?).must_equal false
|
131
131
|
end
|
132
132
|
|
133
133
|
it 'raises NoMethodError if there are no values like boolean method' do
|
134
|
-
proc {
|
134
|
+
expect(proc {
|
135
135
|
set.some_method?
|
136
|
-
}.must_raise NoMethodError
|
136
|
+
}).must_raise NoMethodError
|
137
137
|
end
|
138
138
|
|
139
139
|
it 'raises ArgumentError if arguments are passed' do
|
140
|
-
proc {
|
140
|
+
expect(proc {
|
141
141
|
set.a?('<3')
|
142
|
-
}.must_raise ArgumentError
|
142
|
+
}).must_raise ArgumentError
|
143
143
|
end
|
144
144
|
|
145
145
|
it 'responds to methods for existing values' do
|
146
|
-
set.must_respond_to :a?
|
147
|
-
set.must_respond_to :b?
|
148
|
-
set.must_respond_to :c?
|
146
|
+
expect(set).must_respond_to :a?
|
147
|
+
expect(set).must_respond_to :b?
|
148
|
+
expect(set).must_respond_to :c?
|
149
149
|
end
|
150
150
|
|
151
151
|
it 'returns a method object' do
|
152
|
-
set.method(:a?).must_be_instance_of Method
|
152
|
+
expect(set.method(:a?)).must_be_instance_of Method
|
153
153
|
end
|
154
154
|
|
155
155
|
it 'does not respond to a method for not existing value' do
|
156
|
-
set.wont_respond_to :some_method?
|
156
|
+
expect(set).wont_respond_to :some_method?
|
157
157
|
end
|
158
158
|
end
|
159
159
|
|
data/test/test_helper.rb
CHANGED
data/test/value_test.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'test_helper'
|
4
4
|
require 'yaml'
|
5
5
|
|
6
|
-
|
6
|
+
class ValueTest < MiniTest::Spec
|
7
7
|
class Model
|
8
8
|
end
|
9
9
|
|
@@ -14,36 +14,36 @@ describe Enumerize::Value do
|
|
14
14
|
let(:val) { Enumerize::Value.new(attr, 'test_value', 1) }
|
15
15
|
|
16
16
|
it 'is a string' do
|
17
|
-
val.must_be_kind_of String
|
17
|
+
expect(val).must_be_kind_of String
|
18
18
|
end
|
19
19
|
|
20
20
|
describe 'equality' do
|
21
21
|
it 'is compared to string' do
|
22
|
-
val.must_be :==, 'test_value'
|
23
|
-
val.wont_be :==, 'not_value'
|
22
|
+
expect(val).must_be :==, 'test_value'
|
23
|
+
expect(val).wont_be :==, 'not_value'
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'is compared to symbol' do
|
27
|
-
val.must_be :==, :test_value
|
28
|
-
val.wont_be :==, :not_value
|
27
|
+
expect(val).must_be :==, :test_value
|
28
|
+
expect(val).wont_be :==, :not_value
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'is compared to integer' do
|
32
|
-
val.must_be :==, 1
|
33
|
-
val.wont_be :==, 2
|
32
|
+
expect(val).must_be :==, 1
|
33
|
+
expect(val).wont_be :==, 2
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
37
|
describe 'translation' do
|
38
38
|
it 'uses common translation' do
|
39
39
|
store_translations(:en, :enumerize => {:attribute_name => {:test_value => "Common translation"}}) do
|
40
|
-
val.text.must_be :==, "Common translation"
|
40
|
+
expect(val.text).must_be :==, "Common translation"
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'uses default translation from the "default" section if its present' do
|
45
45
|
store_translations(:en, :enumerize => {:defaults => {:attribute_name => {:test_value => "Common translation"}}}) do
|
46
|
-
val.text.must_be :==, "Common translation"
|
46
|
+
expect(val.text).must_be :==, "Common translation"
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
@@ -51,7 +51,7 @@ describe Enumerize::Value do
|
|
51
51
|
attr.i18n_scopes = ["enumerize.model_name.attribute_name"]
|
52
52
|
|
53
53
|
store_translations(:en, :enumerize => {:model_name => {:attribute_name => {:test_value => "Model Specific translation"}}}) do
|
54
|
-
val.text.must_be :==, "Model Specific translation"
|
54
|
+
expect(val.text).must_be :==, "Model Specific translation"
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -59,13 +59,13 @@ describe Enumerize::Value do
|
|
59
59
|
attr.i18n_scopes = ["enumerize.model_name.attribute_name"]
|
60
60
|
|
61
61
|
store_translations(:en, :enumerize => {:attribute_name => {:test_value => "Common translation"}, :model_name => {:attribute_name => {:test_value => "Model Specific translation"}}}) do
|
62
|
-
val.text.must_be :==, "Model Specific translation"
|
62
|
+
expect(val.text).must_be :==, "Model Specific translation"
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
66
|
it 'uses simply humanized value when translation is undefined' do
|
67
67
|
store_translations(:en, :enumerize => {}) do
|
68
|
-
val.text.must_be :==, "Test value"
|
68
|
+
expect(val.text).must_be :==, "Test value"
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
@@ -73,7 +73,7 @@ describe Enumerize::Value do
|
|
73
73
|
attr.i18n_scopes = ["other.scope"]
|
74
74
|
|
75
75
|
store_translations(:en, :other => {:scope => {:test_value => "Scope specific translation"}}) do
|
76
|
-
val.text.must_be :==, "Scope specific translation"
|
76
|
+
expect(val.text).must_be :==, "Scope specific translation"
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
@@ -81,14 +81,7 @@ describe Enumerize::Value do
|
|
81
81
|
attr.i18n_scopes = ["nonexistent.scope", "other.scope"]
|
82
82
|
|
83
83
|
store_translations(:en, :other => {:scope => {:test_value => "Scope specific translation"}}) do
|
84
|
-
val.text.must_be :==, "Scope specific translation"
|
85
|
-
end
|
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
|
84
|
+
expect(val.text).must_be :==, "Scope specific translation"
|
92
85
|
end
|
93
86
|
end
|
94
87
|
end
|
@@ -99,44 +92,44 @@ describe Enumerize::Value do
|
|
99
92
|
end
|
100
93
|
|
101
94
|
it 'returns true if value equals method' do
|
102
|
-
val.test_value
|
95
|
+
expect(val.test_value?).must_equal true
|
103
96
|
end
|
104
97
|
|
105
98
|
it 'returns false if value does not equal method' do
|
106
|
-
val.other_value
|
99
|
+
expect(val.other_value?).must_equal false
|
107
100
|
end
|
108
101
|
|
109
102
|
it 'raises NoMethodError if there are no values like boolean method' do
|
110
|
-
proc {
|
103
|
+
expect(proc {
|
111
104
|
val.some_method?
|
112
|
-
}.must_raise NoMethodError
|
105
|
+
}).must_raise NoMethodError
|
113
106
|
end
|
114
107
|
|
115
108
|
it 'raises ArgumentError if arguments are passed' do
|
116
|
-
proc {
|
109
|
+
expect(proc {
|
117
110
|
val.other_value?('<3')
|
118
|
-
}.must_raise ArgumentError
|
111
|
+
}).must_raise ArgumentError
|
119
112
|
end
|
120
113
|
|
121
114
|
it 'responds to methods for existing values' do
|
122
|
-
val.must_respond_to :test_value?
|
123
|
-
val.must_respond_to :other_value?
|
115
|
+
expect(val).must_respond_to :test_value?
|
116
|
+
expect(val).must_respond_to :other_value?
|
124
117
|
end
|
125
118
|
|
126
119
|
it 'returns a method object' do
|
127
|
-
val.method(:test_value?).must_be_instance_of Method
|
120
|
+
expect(val.method(:test_value?)).must_be_instance_of Method
|
128
121
|
end
|
129
122
|
|
130
123
|
it "doesn't respond to a method for not existing value" do
|
131
|
-
val.wont_respond_to :some_method?
|
124
|
+
expect(val).wont_respond_to :some_method?
|
132
125
|
end
|
133
126
|
|
134
127
|
it "doesn't respond to methods is value was modified" do
|
135
128
|
modified_value = val.upcase
|
136
129
|
|
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?
|
130
|
+
expect(modified_value.upcase).wont_respond_to :some_method?
|
131
|
+
expect(modified_value.upcase).wont_respond_to :test_value?
|
132
|
+
expect(modified_value.upcase).wont_respond_to :other_value?
|
140
133
|
end
|
141
134
|
end
|
142
135
|
|
@@ -149,7 +142,7 @@ describe Enumerize::Value do
|
|
149
142
|
|
150
143
|
it 'serializes with Marshal' do
|
151
144
|
dump_value = Marshal.dump(val)
|
152
|
-
Marshal.load(dump_value).must_equal 'test_value'
|
145
|
+
expect(Marshal.load(dump_value)).must_equal 'test_value'
|
153
146
|
end
|
154
147
|
end
|
155
148
|
|
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.6.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:
|
11
|
+
date: 2023-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -31,15 +31,17 @@ executables: []
|
|
31
31
|
extensions: []
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
|
+
- ".github/workflows/ruby.yml"
|
34
35
|
- ".gitignore"
|
35
36
|
- ".rspec"
|
36
|
-
- ".travis.yml"
|
37
37
|
- CHANGELOG.md
|
38
38
|
- Gemfile
|
39
39
|
- Gemfile.global
|
40
40
|
- Gemfile.mongo_mapper
|
41
41
|
- Gemfile.rails60
|
42
42
|
- Gemfile.rails61
|
43
|
+
- Gemfile.rails70
|
44
|
+
- Gemfile.railsmaster
|
43
45
|
- MIT-LICENSE
|
44
46
|
- README.md
|
45
47
|
- Rakefile
|
@@ -105,14 +107,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
105
107
|
requirements:
|
106
108
|
- - ">="
|
107
109
|
- !ruby/object:Gem::Version
|
108
|
-
version:
|
110
|
+
version: '2.7'
|
109
111
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
112
|
requirements:
|
111
113
|
- - ">="
|
112
114
|
- !ruby/object:Gem::Version
|
113
115
|
version: '0'
|
114
116
|
requirements: []
|
115
|
-
rubygems_version: 3.
|
117
|
+
rubygems_version: 3.4.7
|
116
118
|
signing_key:
|
117
119
|
specification_version: 4
|
118
120
|
summary: Enumerated attributes with I18n and ActiveRecord/Mongoid/MongoMapper support
|
data/.travis.yml
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
dist: focal
|
2
|
-
language: ruby
|
3
|
-
sudo: false
|
4
|
-
services:
|
5
|
-
- mongodb
|
6
|
-
addons:
|
7
|
-
postgresql: "13"
|
8
|
-
gemfile:
|
9
|
-
- Gemfile
|
10
|
-
- Gemfile.rails60
|
11
|
-
- Gemfile.rails61
|
12
|
-
- Gemfile.mongo_mapper
|
13
|
-
rvm:
|
14
|
-
- 2.5.8
|
15
|
-
- 2.6.6
|
16
|
-
- 2.7.1
|
17
|
-
before_install:
|
18
|
-
- gem install bundler
|
19
|
-
env:
|
20
|
-
global:
|
21
|
-
- DB_USER=postgres
|
22
|
-
- DB_PASS=
|
23
|
-
matrix:
|
24
|
-
- DB=sqlite3
|
25
|
-
- DB=postgresql
|
26
|
-
matrix:
|
27
|
-
fast_finish: true
|
28
|
-
exclude:
|
29
|
-
- gemfile: Gemfile.mongo_mapper
|
30
|
-
env: DB=postgresql
|
31
|
-
branches:
|
32
|
-
only:
|
33
|
-
- master
|
34
|
-
notifications:
|
35
|
-
email: false
|