assignable_values 0.16.2 → 0.16.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- 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.lock +1 -1
- data/lib/assignable_values/active_record/restriction/base.rb +1 -1
- data/lib/assignable_values/version.rb +1 -1
- data/spec/assignable_values/active_record_spec.rb +39 -23
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 400d27572075ed4ae3361303c97ccb7acf0afb00e63cfdc8e3a667d8da73b874
|
4
|
+
data.tar.gz: 20e2628282f45a9265d036a0b3ca1078a5bb5532cf06654d05c79bd67c878d96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d8d5c406b2829863c62fe04851341667ce4f49cc2e6f3c29e6e58cc4710fe70d123ac7cbc315f56f8fdd1734dcab7c5b9693186bd9b12033db3df03fd686261
|
7
|
+
data.tar.gz: d0e460d55fa4ce7d26207a239778177f56a4c1dcd73a8f7ee7aa6167094b55b75af84a0a8a9cc9e9e3a371c693b4fb813df16978057e545b4dbaa50415926668
|
data/CHANGELOG.md
CHANGED
@@ -8,6 +8,12 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html
|
|
8
8
|
|
9
9
|
### Compatible changes
|
10
10
|
|
11
|
+
## 0.16.3 - 2020-10-15
|
12
|
+
|
13
|
+
### Compatible changes
|
14
|
+
|
15
|
+
- No longer crashes when assigning `nil` to an attribute with assignable values that are provided as a scope.
|
16
|
+
|
11
17
|
## 0.16.2 - 2020-10-06
|
12
18
|
|
13
19
|
### Compatible changes
|
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.lock
CHANGED
@@ -107,7 +107,7 @@ module AssignableValues
|
|
107
107
|
values_or_scope = assignable_values(record, :include_old_value => false)
|
108
108
|
|
109
109
|
if is_scope?(values_or_scope)
|
110
|
-
values_or_scope.exists?(value.id)
|
110
|
+
values_or_scope.exists?(value.id) unless value.nil?
|
111
111
|
else
|
112
112
|
values_or_scope.include?(value)
|
113
113
|
end
|
@@ -510,44 +510,60 @@ describe AssignableValues::ActiveRecord do
|
|
510
510
|
record.valid?
|
511
511
|
end
|
512
512
|
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
MyArtist = Artist.disposable_copy
|
517
|
-
|
518
|
-
MyArtist.class_eval do
|
519
|
-
after_initialize :increase_initialized_count
|
520
|
-
|
521
|
-
define_method :increase_initialized_count do
|
522
|
-
initialized_artists_count += 1
|
523
|
-
end
|
524
|
-
end
|
525
|
-
|
526
|
-
klass = Song.disposable_copy
|
513
|
+
context 'when assignable values are provided as an ActiveRecord scope' do
|
514
|
+
MyArtist = Artist.disposable_copy
|
515
|
+
let(:klass) { Song.disposable_copy }
|
527
516
|
|
517
|
+
before do
|
528
518
|
klass.class_eval do
|
529
519
|
assignable_values_for :artist do
|
530
520
|
if ::ActiveRecord::VERSION::MAJOR < 4
|
531
|
-
MyArtist.scoped
|
521
|
+
MyArtist.scoped({})
|
532
522
|
else
|
533
523
|
MyArtist.all
|
534
524
|
end
|
535
525
|
end
|
536
526
|
end
|
527
|
+
end
|
537
528
|
|
529
|
+
it 'allows assigning a record from the scope' do
|
538
530
|
artist = MyArtist.create!
|
539
|
-
initialized_artists_count.should == 1
|
540
|
-
|
541
531
|
song = klass.new(:artist => artist)
|
532
|
+
song.should be_valid
|
533
|
+
end
|
534
|
+
|
535
|
+
it 'will not crash during validation when the assigned value is nil' do
|
536
|
+
song = klass.new
|
537
|
+
expect { song.valid? }.to_not raise_error
|
538
|
+
song.errors[:artist_id].should be_present
|
539
|
+
end
|
540
|
+
|
541
|
+
it 'should not load all records into memory' do
|
542
|
+
unless ::ActiveRecord::VERSION::MAJOR < 3 # somehow rails 2 still initializes Objects during the scope.exists?-call
|
543
|
+
initialized_artists_count = 0
|
544
|
+
|
545
|
+
MyArtist.class_eval do
|
546
|
+
after_initialize :increase_initialized_count
|
542
547
|
|
543
|
-
|
544
|
-
|
548
|
+
define_method :increase_initialized_count do
|
549
|
+
initialized_artists_count += 1
|
550
|
+
end
|
551
|
+
end
|
545
552
|
|
546
|
-
|
547
|
-
|
553
|
+
artist = MyArtist.create!
|
554
|
+
initialized_artists_count.should == 1
|
548
555
|
|
549
|
-
|
550
|
-
|
556
|
+
song = klass.new(:artist => artist)
|
557
|
+
|
558
|
+
song.valid?
|
559
|
+
initialized_artists_count.should == 1
|
560
|
+
|
561
|
+
song.assignable_artists
|
562
|
+
initialized_artists_count.should == 1
|
563
|
+
|
564
|
+
song.assignable_artists.to_a
|
565
|
+
initialized_artists_count.should == 2
|
566
|
+
end
|
551
567
|
end
|
552
568
|
end
|
553
569
|
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henning Koch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-10-
|
11
|
+
date: 2020-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -91,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
91
|
- !ruby/object:Gem::Version
|
92
92
|
version: '0'
|
93
93
|
requirements: []
|
94
|
-
rubygems_version: 3.
|
94
|
+
rubygems_version: 3.1.4
|
95
95
|
signing_key:
|
96
96
|
specification_version: 4
|
97
97
|
summary: Restrict the values assignable to ActiveRecord attributes or associations
|