assignable_values 0.16.2 → 0.16.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b9fa8864bca68f5d9a2c7199bd08a2c3f97bb46cc3e40b0b7860c62d9bb563bb
4
- data.tar.gz: fe00de9f990305f33905cbd8b0dcaf9fc318521b4378c344aa33bc94a536b63b
3
+ metadata.gz: 400d27572075ed4ae3361303c97ccb7acf0afb00e63cfdc8e3a667d8da73b874
4
+ data.tar.gz: 20e2628282f45a9265d036a0b3ca1078a5bb5532cf06654d05c79bd67c878d96
5
5
  SHA512:
6
- metadata.gz: 815643f34c5d95f2ed47ae5ebdec2dd31c7da83ae1ded589efebf6409789bf30f002315d94468a5e8c14f2f64412fbae025f8a0dec7c057a66826417282a0ca9
7
- data.tar.gz: 500c291826c51db9bfad4d3f222052a1b0e3c2cd59260a7db2f9ee58368d5574734cf58db92c42ec6aa34f1c5a5657d57919e8e1df2c97b05da4b4e69bb9d384
6
+ metadata.gz: 0d8d5c406b2829863c62fe04851341667ce4f49cc2e6f3c29e6e58cc4710fe70d123ac7cbc315f56f8fdd1734dcab7c5b9693186bd9b12033db3df03fd686261
7
+ data.tar.gz: d0e460d55fa4ce7d26207a239778177f56a4c1dcd73a8f7ee7aa6167094b55b75af84a0a8a9cc9e9e3a371c693b4fb813df16978057e545b4dbaa50415926668
@@ -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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- assignable_values (0.16.2)
4
+ assignable_values (0.16.3)
5
5
  activerecord (>= 2.3)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- assignable_values (0.16.2)
4
+ assignable_values (0.16.3)
5
5
  activerecord (>= 2.3)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- assignable_values (0.16.2)
4
+ assignable_values (0.16.3)
5
5
  activerecord (>= 2.3)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- assignable_values (0.16.2)
4
+ assignable_values (0.16.3)
5
5
  activerecord (>= 2.3)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- assignable_values (0.16.2)
4
+ assignable_values (0.16.3)
5
5
  activerecord (>= 2.3)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- assignable_values (0.16.2)
4
+ assignable_values (0.16.3)
5
5
  activerecord (>= 2.3)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- assignable_values (0.16.2)
4
+ assignable_values (0.16.3)
5
5
  activerecord (>= 2.3)
6
6
 
7
7
  GEM
@@ -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
@@ -1,3 +1,3 @@
1
1
  module AssignableValues
2
- VERSION = '0.16.2'
2
+ VERSION = '0.16.3'
3
3
  end
@@ -510,44 +510,60 @@ describe AssignableValues::ActiveRecord do
510
510
  record.valid?
511
511
  end
512
512
 
513
- it 'should not load all records to memory when assignable values are scoped' do
514
- unless ::ActiveRecord::VERSION::MAJOR < 3 # somehow rails 2 still initializes Objects during the scope.exists?-call
515
- initialized_artists_count = 0
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
- song.valid?
544
- initialized_artists_count.should == 1
548
+ define_method :increase_initialized_count do
549
+ initialized_artists_count += 1
550
+ end
551
+ end
545
552
 
546
- song.assignable_artists
547
- initialized_artists_count.should == 1
553
+ artist = MyArtist.create!
554
+ initialized_artists_count.should == 1
548
555
 
549
- song.assignable_artists.to_a
550
- initialized_artists_count.should == 2
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.2
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-06 00:00:00.000000000 Z
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.0.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