assignable_values 0.16.3 → 0.16.4
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/CHANGELOG.md +9 -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 +7 -1
- data/lib/assignable_values/version.rb +1 -1
- data/spec/assignable_values/active_record_spec.rb +20 -0
- metadata +1 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: fcf4880911a30c8f39fe52bb5b018226a899b7ea1b6fa0f4b232d54e198abf83
         | 
| 4 | 
            +
              data.tar.gz: cb52c389c399947480293f65a69d29a2ca6f7ac02de1d743d52a68a1593ba6c2
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: c68e65b8fd131d928af7e0ebe32999ade79163cc44059718c8032d17ca2331abfbf1d0c1babe35378f0816edd22ba67e5c6c7ad296348e0608ea492ed7d72383
         | 
| 7 | 
            +
              data.tar.gz: '08479bf3b543772e9a8810c4cdec60d72979fa152bc445c4e4f7029e5c4909b02c1484f8a40d0044b091e0ece3f068859ebb026ae797912d0d829da9fd682ded'
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -8,18 +8,27 @@ 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.4 - 2020-10-15
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            ### Compatible changes
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            - No longer crashes value blocks return `nil`.
         | 
| 16 | 
            +
             | 
| 17 | 
            +
             | 
| 11 18 | 
             
            ## 0.16.3 - 2020-10-15
         | 
| 12 19 |  | 
| 13 20 | 
             
            ### Compatible changes
         | 
| 14 21 |  | 
| 15 22 | 
             
            - No longer crashes when assigning `nil` to an attribute with assignable values that are provided as a scope.
         | 
| 16 23 |  | 
| 24 | 
            +
             | 
| 17 25 | 
             
            ## 0.16.2 - 2020-10-06
         | 
| 18 26 |  | 
| 19 27 | 
             
            ### Compatible changes
         | 
| 20 28 |  | 
| 21 29 | 
             
            - when given a scope, do not load all records to memory during validation
         | 
| 22 30 |  | 
| 31 | 
            +
             | 
| 23 32 | 
             
            ## 0.16.1 - 2019-05-14
         | 
| 24 33 |  | 
| 25 34 | 
             
            ### 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
    
    
| @@ -236,11 +236,17 @@ module AssignableValues | |
| 236 236 | 
             
                    end
         | 
| 237 237 |  | 
| 238 238 | 
             
                    def assignable_values_from_record_or_delegate(record)
         | 
| 239 | 
            -
                      if delegate?
         | 
| 239 | 
            +
                      assignable_values = if delegate?
         | 
| 240 240 | 
             
                        assignable_values_from_delegate(record)
         | 
| 241 241 | 
             
                      else
         | 
| 242 242 | 
             
                        record.instance_exec(&@values)
         | 
| 243 243 | 
             
                      end
         | 
| 244 | 
            +
             | 
| 245 | 
            +
                      if is_scope?(assignable_values)
         | 
| 246 | 
            +
                        assignable_values
         | 
| 247 | 
            +
                      else
         | 
| 248 | 
            +
                        Array(assignable_values)
         | 
| 249 | 
            +
                      end
         | 
| 244 250 | 
             
                    end
         | 
| 245 251 |  | 
| 246 252 | 
             
                    def delegate(record)
         | 
| @@ -808,6 +808,26 @@ describe AssignableValues::ActiveRecord do | |
| 808 808 | 
             
                    klass.new.assignable_genres.should == %w[pop rock]
         | 
| 809 809 | 
             
                  end
         | 
| 810 810 |  | 
| 811 | 
            +
                  it 'returns an array when the value block returns a single value' do
         | 
| 812 | 
            +
                    klass = Song.disposable_copy do
         | 
| 813 | 
            +
                      assignable_values_for :genre do
         | 
| 814 | 
            +
                        'techno'
         | 
| 815 | 
            +
                      end
         | 
| 816 | 
            +
                    end
         | 
| 817 | 
            +
             | 
| 818 | 
            +
                    klass.new.assignable_genres.should == ['techno']
         | 
| 819 | 
            +
                  end
         | 
| 820 | 
            +
             | 
| 821 | 
            +
                  it 'returns an empty array when the value block returns nothing' do
         | 
| 822 | 
            +
                    klass = Song.disposable_copy do
         | 
| 823 | 
            +
                      assignable_values_for :genre do
         | 
| 824 | 
            +
                        nil
         | 
| 825 | 
            +
                      end
         | 
| 826 | 
            +
                    end
         | 
| 827 | 
            +
             | 
| 828 | 
            +
                    klass.new.assignable_genres.should == []
         | 
| 829 | 
            +
                  end
         | 
| 830 | 
            +
             | 
| 811 831 | 
             
                  it 'should prepend a previously saved value to the top of the list, even if is no longer allowed' do
         | 
| 812 832 | 
             
                    klass = Song.disposable_copy do
         | 
| 813 833 | 
             
                      assignable_values_for :genre do
         |