assignable_values 0.16.0 → 0.16.1
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 +22 -3
- data/CHANGELOG.md +15 -0
- data/Gemfile +1 -1
- data/Gemfile.2.3.lock +1 -1
- data/Gemfile.3.2.lock +1 -1
- data/Gemfile.4.2.lock +1 -1
- data/Gemfile.5.0.lock +1 -1
- data/Gemfile.5.1.lock +1 -1
- data/Gemfile.5.1.pg.lock +1 -1
- data/Gemfile.6.0.pg +16 -0
- data/Gemfile.6.0.pg.lock +68 -0
- data/Gemfile.lock +1 -1
- data/README.md +2 -2
- data/lib/assignable_values/active_record/restriction/scalar_attribute.rb +4 -4
- data/lib/assignable_values/version.rb +1 -1
- data/spec/assignable_values/active_record_spec.rb +90 -50
- data/spec/support/database.rb +1 -1
- data/spec/support/i18n.yml +4 -1
- data/spec/support/models.rb +3 -3
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 977d6a6005a660c922f2ceb114f0d0e9ca187312
|
4
|
+
data.tar.gz: 93af552eef243da11888c86be25e595242d67b65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8a4a8064ed9a7b68639212901128814f083651af7628645fa8275968f20ae78920459397efa0ece9755d78ce659054745c7baf3e2aef3a891aa34b6436119c2
|
7
|
+
data.tar.gz: 4ee5bbd8c8a9137bd0f3b55cbfab07d104c0a5cc21817818ba21b2ceca48e0f5c4d42297778a4c23a4fe66399f3e8eda1d4ba98e357445b48734fea96990628f
|
data/.travis.yml
CHANGED
@@ -5,6 +5,7 @@ rvm:
|
|
5
5
|
- 2.1.8
|
6
6
|
- 2.3.1
|
7
7
|
- 2.4.2
|
8
|
+
- 2.5.3
|
8
9
|
|
9
10
|
gemfile:
|
10
11
|
- Gemfile.2.3
|
@@ -13,6 +14,7 @@ gemfile:
|
|
13
14
|
- Gemfile.5.0
|
14
15
|
- Gemfile.5.1
|
15
16
|
- Gemfile.5.1.pg
|
17
|
+
- Gemfile.6.0.pg
|
16
18
|
|
17
19
|
matrix:
|
18
20
|
exclude:
|
@@ -22,26 +24,43 @@ matrix:
|
|
22
24
|
rvm: 2.3.1
|
23
25
|
- gemfile: Gemfile.2.3
|
24
26
|
rvm: 2.4.2
|
27
|
+
- gemfile: Gemfile.2.3
|
28
|
+
rvm: 2.5.3
|
25
29
|
- gemfile: Gemfile.3.2
|
26
30
|
rvm: 2.3.1
|
27
31
|
- gemfile: Gemfile.3.2
|
28
32
|
rvm: 2.4.2
|
33
|
+
- gemfile: Gemfile.3.2
|
34
|
+
rvm: 2.5.3
|
29
35
|
- gemfile: Gemfile.4.2
|
30
36
|
rvm: 1.8.7
|
31
37
|
- gemfile: Gemfile.4.2
|
32
38
|
rvm: 2.4.2
|
39
|
+
- gemfile: Gemfile.4.2
|
40
|
+
rvm: 2.5.3
|
33
41
|
- gemfile: Gemfile.5.0
|
34
|
-
rvm:
|
42
|
+
rvm: 1.8.7
|
35
43
|
- gemfile: Gemfile.5.0
|
44
|
+
rvm: 2.1.8
|
45
|
+
- gemfile: Gemfile.5.1
|
36
46
|
rvm: 1.8.7
|
37
47
|
- gemfile: Gemfile.5.1
|
38
48
|
rvm: 2.1.8
|
39
|
-
- gemfile: Gemfile.5.1
|
49
|
+
- gemfile: Gemfile.5.1.pg
|
40
50
|
rvm: 1.8.7
|
41
51
|
- gemfile: Gemfile.5.1.pg
|
42
52
|
rvm: 2.1.8
|
43
|
-
- gemfile: Gemfile.
|
53
|
+
- gemfile: Gemfile.6.0.pg
|
44
54
|
rvm: 1.8.7
|
55
|
+
- gemfile: Gemfile.6.0.pg
|
56
|
+
rvm: 2.1.8
|
57
|
+
- gemfile: Gemfile.6.0.pg
|
58
|
+
rvm: 2.3.1
|
59
|
+
- gemfile: Gemfile.6.0.pg
|
60
|
+
rvm: 2.4.2
|
61
|
+
|
62
|
+
addons:
|
63
|
+
postgresql: "9.4"
|
45
64
|
|
46
65
|
sudo: false
|
47
66
|
|
data/CHANGELOG.md
CHANGED
@@ -9,6 +9,21 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html
|
|
9
9
|
### Compatible changes
|
10
10
|
|
11
11
|
|
12
|
+
## 0.16.1 - 2019-05-14
|
13
|
+
|
14
|
+
### Compatible changes
|
15
|
+
|
16
|
+
- add tests for Rails 6
|
17
|
+
- Humanized assignable value methods now also take the include_old_values option (fixes #25)
|
18
|
+
|
19
|
+
|
20
|
+
## 0.16.0 - 2019-02-20
|
21
|
+
|
22
|
+
### Breaking changes
|
23
|
+
|
24
|
+
- fix arity bug
|
25
|
+
|
26
|
+
|
12
27
|
## 0.15.1 - 2018-11-05
|
13
28
|
|
14
29
|
### Compatible changes
|
data/Gemfile
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
Gemfile.4.2
|
data/Gemfile.2.3.lock
CHANGED
data/Gemfile.3.2.lock
CHANGED
data/Gemfile.4.2.lock
CHANGED
data/Gemfile.5.0.lock
CHANGED
data/Gemfile.5.1.lock
CHANGED
data/Gemfile.5.1.pg.lock
CHANGED
data/Gemfile.6.0.pg
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Runtime dependencies
|
4
|
+
gem 'activerecord', '~>6.0.0beta'
|
5
|
+
gem 'i18n'
|
6
|
+
gem 'pg', '<1'
|
7
|
+
|
8
|
+
# Development dependencies
|
9
|
+
gem 'rake'
|
10
|
+
gem 'database_cleaner'
|
11
|
+
gem 'rspec'
|
12
|
+
gem 'rspec_candy'
|
13
|
+
gem 'gemika'
|
14
|
+
|
15
|
+
# Gem under test
|
16
|
+
gem 'assignable_values', :path => '.'
|
data/Gemfile.6.0.pg.lock
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
assignable_values (0.16.1)
|
5
|
+
activerecord (>= 2.3)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activemodel (6.0.0.beta3)
|
11
|
+
activesupport (= 6.0.0.beta3)
|
12
|
+
activerecord (6.0.0.beta3)
|
13
|
+
activemodel (= 6.0.0.beta3)
|
14
|
+
activesupport (= 6.0.0.beta3)
|
15
|
+
activesupport (6.0.0.beta3)
|
16
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
|
+
i18n (>= 0.7, < 2)
|
18
|
+
minitest (~> 5.1)
|
19
|
+
tzinfo (~> 1.1)
|
20
|
+
zeitwerk (~> 1.3, >= 1.3.1)
|
21
|
+
concurrent-ruby (1.1.5)
|
22
|
+
database_cleaner (1.7.0)
|
23
|
+
diff-lcs (1.3)
|
24
|
+
gemika (0.3.4)
|
25
|
+
i18n (1.6.0)
|
26
|
+
concurrent-ruby (~> 1.0)
|
27
|
+
minitest (5.11.3)
|
28
|
+
pg (0.21.0)
|
29
|
+
rake (12.3.2)
|
30
|
+
rspec (3.8.0)
|
31
|
+
rspec-core (~> 3.8.0)
|
32
|
+
rspec-expectations (~> 3.8.0)
|
33
|
+
rspec-mocks (~> 3.8.0)
|
34
|
+
rspec-core (3.8.0)
|
35
|
+
rspec-support (~> 3.8.0)
|
36
|
+
rspec-expectations (3.8.2)
|
37
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
38
|
+
rspec-support (~> 3.8.0)
|
39
|
+
rspec-mocks (3.8.0)
|
40
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
41
|
+
rspec-support (~> 3.8.0)
|
42
|
+
rspec-support (3.8.0)
|
43
|
+
rspec_candy (0.5.1)
|
44
|
+
rspec
|
45
|
+
sneaky-save
|
46
|
+
sneaky-save (0.1.3)
|
47
|
+
activerecord (>= 3.2.0)
|
48
|
+
thread_safe (0.3.6)
|
49
|
+
tzinfo (1.2.5)
|
50
|
+
thread_safe (~> 0.1)
|
51
|
+
zeitwerk (1.4.3)
|
52
|
+
|
53
|
+
PLATFORMS
|
54
|
+
ruby
|
55
|
+
|
56
|
+
DEPENDENCIES
|
57
|
+
activerecord (~> 6.0.0beta)
|
58
|
+
assignable_values!
|
59
|
+
database_cleaner
|
60
|
+
gemika
|
61
|
+
i18n
|
62
|
+
pg (< 1)
|
63
|
+
rake
|
64
|
+
rspec
|
65
|
+
rspec_candy
|
66
|
+
|
67
|
+
BUNDLED WITH
|
68
|
+
1.17.3
|
data/Gemfile.lock
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
Gemfile.4.2.lock
|
data/README.md
CHANGED
@@ -5,7 +5,7 @@ assignable_values - Enums on vitamins [ on Ruby 1.8.7, 2.1, 2.3, 2.4 and 2.5.
|
9
9
|
|
10
10
|
|
11
11
|
Restricting scalar attributes
|
@@ -353,7 +353,7 @@ There are tests in `spec`. We only accept PRs with tests. To run tests:
|
|
353
353
|
- Create a local test database `assignable_values_test` in both MySQL and PostgreSQL
|
354
354
|
- Copy `spec/support/database.sample.yml` to `spec/support/database.yml` and enter your local credentials for the test database
|
355
355
|
- Install development dependencies using `bundle install`
|
356
|
-
- Run tests using `bundle exec current_rspec`
|
356
|
+
- Run tests using `bundle exec rake current_rspec`
|
357
357
|
|
358
358
|
We recommend to test large changes against multiple versions of Ruby and multiple dependency sets. Supported combinations are configured in `.travis.yml`. We provide some rake tasks to help with this:
|
359
359
|
|
@@ -17,8 +17,8 @@ module AssignableValues
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
def humanized_assignable_values(record)
|
21
|
-
values = assignable_values(record)
|
20
|
+
def humanized_assignable_values(record, options = {})
|
21
|
+
values = assignable_values(record, options)
|
22
22
|
values.collect do |value|
|
23
23
|
HumanizedValue.new(value, humanized_value(value))
|
24
24
|
end
|
@@ -75,8 +75,8 @@ module AssignableValues
|
|
75
75
|
restriction = self
|
76
76
|
multiple = @options[:multiple]
|
77
77
|
enhance_model do
|
78
|
-
define_method :"humanized_assignable_#{restriction.property.to_s.pluralize}" do
|
79
|
-
restriction.humanized_assignable_values(self)
|
78
|
+
define_method :"humanized_assignable_#{restriction.property.to_s.pluralize}" do |*args|
|
79
|
+
restriction.humanized_assignable_values(self, *args)
|
80
80
|
end
|
81
81
|
|
82
82
|
unless multiple
|
@@ -1,6 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'ostruct'
|
3
3
|
|
4
|
+
def save_without_validation(record)
|
5
|
+
if ActiveRecord::VERSION::MAJOR < 3
|
6
|
+
record.save(false)
|
7
|
+
else
|
8
|
+
record.save(:validate => false)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
4
12
|
describe AssignableValues::ActiveRecord do
|
5
13
|
|
6
14
|
describe '.assignable_values' do
|
@@ -17,30 +25,30 @@ describe AssignableValues::ActiveRecord do
|
|
17
25
|
|
18
26
|
before :each do
|
19
27
|
@klass = Song.disposable_copy do
|
20
|
-
assignable_values_for :
|
28
|
+
assignable_values_for :virtual_sub_genre do
|
21
29
|
%w[pop rock]
|
22
30
|
end
|
23
31
|
|
24
|
-
assignable_values_for :
|
32
|
+
assignable_values_for :virtual_multi_genres, :multiple => true, :allow_blank => true do
|
25
33
|
%w[pop rock]
|
26
34
|
end
|
27
35
|
end
|
28
36
|
end
|
29
37
|
|
30
38
|
it 'should validate that the attribute is allowed' do
|
31
|
-
@klass.new(:
|
32
|
-
@klass.new(:
|
39
|
+
@klass.new(:virtual_sub_genre => 'pop').should be_valid
|
40
|
+
@klass.new(:virtual_sub_genre => 'disallowed value').should_not be_valid
|
33
41
|
end
|
34
42
|
|
35
43
|
it 'should not allow nil for the attribute value' do
|
36
|
-
@klass.new(:
|
44
|
+
@klass.new(:virtual_sub_genre => nil).should_not be_valid
|
37
45
|
end
|
38
46
|
|
39
47
|
it 'should generate a method returning the humanized value' do
|
40
|
-
song = @klass.new(:
|
41
|
-
song.
|
42
|
-
song.
|
43
|
-
song.
|
48
|
+
song = @klass.new(:virtual_sub_genre => 'pop')
|
49
|
+
song.humanized_virtual_sub_genre.should == 'Pop music'
|
50
|
+
song.humanized_virtual_sub_genre('rock').should == 'Rock music'
|
51
|
+
song.humanized_virtual_multi_genre('rock').should == 'Rock music'
|
44
52
|
end
|
45
53
|
|
46
54
|
end
|
@@ -51,21 +59,21 @@ describe AssignableValues::ActiveRecord do
|
|
51
59
|
|
52
60
|
before :each do
|
53
61
|
@klass = Song.disposable_copy do
|
54
|
-
assignable_values_for :
|
62
|
+
assignable_values_for :virtual_multi_genres, :multiple => true do
|
55
63
|
%w[pop rock]
|
56
64
|
end
|
57
65
|
end
|
58
66
|
end
|
59
67
|
|
60
68
|
it 'should validate that the attribute is a subset' do
|
61
|
-
@klass.new(:
|
62
|
-
@klass.new(:
|
63
|
-
@klass.new(:
|
69
|
+
@klass.new(:virtual_multi_genres => ['pop']).should be_valid
|
70
|
+
@klass.new(:virtual_multi_genres => ['pop', 'rock']).should be_valid
|
71
|
+
@klass.new(:virtual_multi_genres => ['pop', 'disallowed value']).should_not be_valid
|
64
72
|
end
|
65
73
|
|
66
74
|
it 'should not allow nil or [] for allow_blank: false' do
|
67
|
-
@klass.new(:
|
68
|
-
@klass.new(:
|
75
|
+
@klass.new(:virtual_multi_genres => nil).should_not be_valid
|
76
|
+
@klass.new(:virtual_multi_genres => []).should_not be_valid
|
69
77
|
end
|
70
78
|
|
71
79
|
end
|
@@ -74,15 +82,15 @@ describe AssignableValues::ActiveRecord do
|
|
74
82
|
|
75
83
|
before :each do
|
76
84
|
@klass = Song.disposable_copy do
|
77
|
-
assignable_values_for :
|
85
|
+
assignable_values_for :virtual_multi_genres, :multiple => true, :allow_blank => true do
|
78
86
|
%w[pop rock]
|
79
87
|
end
|
80
88
|
end
|
81
89
|
end
|
82
90
|
|
83
91
|
it 'should allow nil or [] for allow_blank: false' do
|
84
|
-
@klass.new(:
|
85
|
-
@klass.new(:
|
92
|
+
@klass.new(:virtual_multi_genres => nil).should be_valid
|
93
|
+
@klass.new(:virtual_multi_genres => []).should be_valid
|
86
94
|
end
|
87
95
|
|
88
96
|
end
|
@@ -99,7 +107,7 @@ describe AssignableValues::ActiveRecord do
|
|
99
107
|
%w[pop rock]
|
100
108
|
end
|
101
109
|
|
102
|
-
assignable_values_for :
|
110
|
+
assignable_values_for :virtual_multi_genres, :multiple => true, :allow_blank => true do
|
103
111
|
%w[pop rock]
|
104
112
|
end
|
105
113
|
end
|
@@ -166,26 +174,26 @@ describe AssignableValues::ActiveRecord do
|
|
166
174
|
context 'for multiple: true' do
|
167
175
|
it 'should raise when trying to humanize a value without an argument' do
|
168
176
|
song = @klass.new
|
169
|
-
proc { song.
|
177
|
+
proc { song.humanized_virtual_multi_genre }.should raise_error(ArgumentError)
|
170
178
|
end
|
171
179
|
|
172
180
|
it 'should generate an instance method to retrieve the humanization of any given value' do
|
173
181
|
song = @klass.new(:genre => 'pop')
|
174
|
-
song.
|
182
|
+
song.humanized_virtual_multi_genre('rock').should == 'Rock music'
|
175
183
|
end
|
176
184
|
|
177
185
|
it 'should generate a class method to retrieve the humanization of any given value' do
|
178
|
-
@klass.
|
186
|
+
@klass.humanized_virtual_multi_genre('rock').should == 'Rock music'
|
179
187
|
end
|
180
188
|
|
181
189
|
it 'should generate an instance method to retrieve the humanizations of all current values' do
|
182
190
|
song = @klass.new
|
183
|
-
song.
|
184
|
-
song.
|
185
|
-
song.
|
186
|
-
song.
|
187
|
-
song.
|
188
|
-
song.
|
191
|
+
song.virtual_multi_genres = nil
|
192
|
+
song.humanized_virtual_multi_genres.should == nil
|
193
|
+
song.virtual_multi_genres = []
|
194
|
+
song.humanized_virtual_multi_genres.should == []
|
195
|
+
song.virtual_multi_genres = ['pop', 'rock']
|
196
|
+
song.humanized_virtual_multi_genres.should == ['Pop music', 'Rock music']
|
189
197
|
end
|
190
198
|
end
|
191
199
|
end
|
@@ -280,43 +288,39 @@ describe AssignableValues::ActiveRecord do
|
|
280
288
|
|
281
289
|
before :each do
|
282
290
|
@klass = Song.disposable_copy do
|
283
|
-
assignable_values_for :
|
291
|
+
assignable_values_for :multi_genres, :multiple => true do
|
284
292
|
%w[pop rock]
|
285
293
|
end
|
286
294
|
end
|
287
295
|
end
|
288
296
|
|
289
297
|
it 'should validate that the attribute is allowed' do
|
290
|
-
@klass.new(:
|
291
|
-
@klass.new(:
|
292
|
-
@klass.new(:
|
298
|
+
@klass.new(:multi_genres => ['pop']).should be_valid
|
299
|
+
@klass.new(:multi_genres => ['pop', 'rock']).should be_valid
|
300
|
+
@klass.new(:multi_genres => ['pop', 'invalid value']).should_not be_valid
|
293
301
|
end
|
294
302
|
|
295
303
|
it 'should not allow a scalar attribute' do
|
296
|
-
@klass.new(:
|
304
|
+
@klass.new(:multi_genres => 'pop').should_not be_valid
|
297
305
|
end
|
298
306
|
|
299
307
|
it 'should not allow nil or [] for the attribute value' do
|
300
|
-
@klass.new(:
|
301
|
-
@klass.new(:
|
308
|
+
@klass.new(:multi_genres => nil).should_not be_valid
|
309
|
+
@klass.new(:multi_genres => []).should_not be_valid
|
302
310
|
end
|
303
311
|
|
304
312
|
it 'should allow a subset of previously saved values even if that value is no longer allowed' do
|
305
|
-
record = @klass.create!(:
|
306
|
-
record.
|
307
|
-
|
308
|
-
record.save(false)
|
309
|
-
else
|
310
|
-
record.save(:validate => false) # update without validations for the sake of this test
|
311
|
-
end
|
313
|
+
record = @klass.create!(:multi_genres => ['pop'])
|
314
|
+
record.multi_genres = ['pretend', 'previously', 'valid', 'value']
|
315
|
+
save_without_validation(record) # update without validation for the sake of this test
|
312
316
|
record.reload.should be_valid
|
313
|
-
record.
|
317
|
+
record.multi_genres = ['valid', 'previously', 'pop']
|
314
318
|
record.should be_valid
|
315
319
|
end
|
316
320
|
|
317
321
|
it 'should allow a previously saved, blank value even if that value is no longer allowed' do
|
318
|
-
record = @klass.create!(:
|
319
|
-
@klass.update_all(:
|
322
|
+
record = @klass.create!(:multi_genres => ['pop'])
|
323
|
+
@klass.update_all(:multi_genres => []) # update without validations for the sake of this test
|
320
324
|
record.reload.should be_valid
|
321
325
|
end
|
322
326
|
|
@@ -326,18 +330,18 @@ describe AssignableValues::ActiveRecord do
|
|
326
330
|
|
327
331
|
before :each do
|
328
332
|
@klass = Song.disposable_copy do
|
329
|
-
assignable_values_for :
|
333
|
+
assignable_values_for :multi_genres, :multiple => true, :allow_blank => true do
|
330
334
|
%w[pop rock]
|
331
335
|
end
|
332
336
|
end
|
333
337
|
end
|
334
338
|
|
335
339
|
it 'should allow nil for the attribute value' do
|
336
|
-
@klass.new(:
|
340
|
+
@klass.new(:multi_genres => nil).should be_valid
|
337
341
|
end
|
338
342
|
|
339
343
|
it 'should allow an empty array as value' do
|
340
|
-
@klass.new(:
|
344
|
+
@klass.new(:multi_genres => []).should be_valid
|
341
345
|
end
|
342
346
|
|
343
347
|
end
|
@@ -752,10 +756,28 @@ describe AssignableValues::ActiveRecord do
|
|
752
756
|
assignable_values_for :genre do
|
753
757
|
%w[pop rock]
|
754
758
|
end
|
759
|
+
|
760
|
+
assignable_values_for :multi_genres, :multiple => true do
|
761
|
+
%w[pop rock]
|
762
|
+
end
|
755
763
|
end
|
756
|
-
record = klass.create!(:genre => 'pop')
|
764
|
+
record = klass.create!(:genre => 'pop', :multi_genres => ['rock'])
|
757
765
|
klass.update_all(:genre => 'ballad') # update without validation for the sake of this test
|
758
766
|
record.reload.assignable_genres.should == %w[ballad pop rock]
|
767
|
+
|
768
|
+
humanized_genres = record.humanized_assignable_genres
|
769
|
+
humanized_genres.collect(&:value).should == %w[ballad pop rock]
|
770
|
+
humanized_genres.collect(&:humanized).should == ['Ballad', 'Pop music', 'Rock music']
|
771
|
+
humanized_genres.collect(&:to_s).should == ['Ballad', 'Pop music', 'Rock music']
|
772
|
+
|
773
|
+
record.multi_genres = %w[ballad classic]
|
774
|
+
save_without_validation(record) # update without validation for the sake of this test
|
775
|
+
record.reload.multi_genres.should == %w[ballad classic]
|
776
|
+
|
777
|
+
humanized_multi_genres = record.humanized_assignable_multi_genres
|
778
|
+
humanized_multi_genres.collect(&:value).should == %w[ballad classic pop rock]
|
779
|
+
humanized_multi_genres.collect(&:humanized).should == ['Ballad', 'Classic', 'Pop music', 'Rock music']
|
780
|
+
humanized_multi_genres.collect(&:to_s).should == ['Ballad', 'Classic', 'Pop music', 'Rock music']
|
759
781
|
end
|
760
782
|
|
761
783
|
it 'should not prepend a previously saved value to the top of the list if it is still allowed (bugfix)' do
|
@@ -795,10 +817,28 @@ describe AssignableValues::ActiveRecord do
|
|
795
817
|
assignable_values_for :genre do
|
796
818
|
%w[pop rock]
|
797
819
|
end
|
820
|
+
|
821
|
+
assignable_values_for :multi_genres, :multiple => true do
|
822
|
+
%w[pop rock]
|
823
|
+
end
|
798
824
|
end
|
799
|
-
record = klass.create!(:genre => 'pop')
|
825
|
+
record = klass.create!(:genre => 'pop', :multi_genres => ['rock'])
|
800
826
|
klass.update_all(:genre => 'ballad') # update without validation for the sake of this test
|
801
827
|
record.reload.assignable_genres(:include_old_value => false).should == %w[pop rock]
|
828
|
+
|
829
|
+
humanized_genres = record.humanized_assignable_genres(:include_old_value => false)
|
830
|
+
humanized_genres.collect(&:value).should == %w[pop rock]
|
831
|
+
humanized_genres.collect(&:humanized).should == ['Pop music', 'Rock music']
|
832
|
+
humanized_genres.collect(&:to_s).should == ['Pop music', 'Rock music']
|
833
|
+
|
834
|
+
record.multi_genres = %w[ballad classic]
|
835
|
+
save_without_validation(record) # update without validation for the sake of this test
|
836
|
+
record.reload.multi_genres.should == %w[ballad classic]
|
837
|
+
|
838
|
+
humanized_multi_genres = record.humanized_assignable_multi_genres(:include_old_value => false)
|
839
|
+
humanized_multi_genres.collect(&:value).should == %w[pop rock]
|
840
|
+
humanized_multi_genres.collect(&:humanized).should == ['Pop music', 'Rock music']
|
841
|
+
humanized_multi_genres.collect(&:to_s).should == ['Pop music', 'Rock music']
|
802
842
|
end
|
803
843
|
|
804
844
|
it 'should allow omitting a previously saved association' do
|
data/spec/support/database.rb
CHANGED
data/spec/support/i18n.yml
CHANGED
data/spec/support/models.rb
CHANGED
@@ -8,11 +8,11 @@ class Song < ActiveRecord::Base
|
|
8
8
|
|
9
9
|
belongs_to :artist
|
10
10
|
|
11
|
-
attr_accessor :
|
11
|
+
attr_accessor :virtual_sub_genre, :virtual_sub_genres, :virtual_multi_genres
|
12
12
|
|
13
|
-
if ActiveRecord::VERSION::MAJOR < 4 || !Song.new(:
|
13
|
+
if ActiveRecord::VERSION::MAJOR < 4 || !Song.new(:multi_genres => ['test']).multi_genres.is_a?(Array)
|
14
14
|
# Rails 4 or not postgres
|
15
|
-
serialize :
|
15
|
+
serialize :multi_genres
|
16
16
|
end
|
17
17
|
|
18
18
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: assignable_values
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.16.
|
4
|
+
version: 0.16.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henning Koch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -48,6 +48,8 @@ files:
|
|
48
48
|
- Gemfile.5.1.lock
|
49
49
|
- Gemfile.5.1.pg
|
50
50
|
- Gemfile.5.1.pg.lock
|
51
|
+
- Gemfile.6.0.pg
|
52
|
+
- Gemfile.6.0.pg.lock
|
51
53
|
- Gemfile.lock
|
52
54
|
- LICENSE
|
53
55
|
- README.md
|
@@ -90,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
92
|
version: '0'
|
91
93
|
requirements: []
|
92
94
|
rubyforge_project:
|
93
|
-
rubygems_version: 2.
|
95
|
+
rubygems_version: 2.5.1
|
94
96
|
signing_key:
|
95
97
|
specification_version: 4
|
96
98
|
summary: Restrict the values assignable to ActiveRecord attributes or associations
|