mongoid_listable 0.2.5 → 0.2.6
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 +15 -0
- data/lib/mongoid/listable.rb +2 -2
- data/lib/mongoid/listable/callbacks.rb +2 -1
- data/lib/mongoid/listable/version.rb +1 -1
- data/spec/mongoid_listable_spec.rb +27 -1
- metadata +5 -13
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,15 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            !binary "U0hBMQ==":
         | 
| 3 | 
            +
              metadata.gz: !binary |-
         | 
| 4 | 
            +
                OGRmODIzNGZkMzFlYmQyM2M2NDBlZDRkYmE0NDNmMWFjNjE1ZTA2Yg==
         | 
| 5 | 
            +
              data.tar.gz: !binary |-
         | 
| 6 | 
            +
                YzlkMTZhNDRkOTczNmU2MDlhMmRjNmY5ZTRiYjY3NTc0NzEwNDljOQ==
         | 
| 7 | 
            +
            SHA512:
         | 
| 8 | 
            +
              metadata.gz: !binary |-
         | 
| 9 | 
            +
                N2NjZTgxZjAyOWQwMWU3M2M3OGQ4OWNiZmU1YTI2ZGVmNjVmNTMzNmNjYThk
         | 
| 10 | 
            +
                NzhhNjJjM2Y4NDAxNWEyODA2YTEyYTg3NWIwYjJmMWMyYjUwZDhmMjY1MTgx
         | 
| 11 | 
            +
                NTBiYjVjZDc5M2Y4OGUwZTk4YzdmYWUyMDRkN2Q2MTc0NGI3MDY=
         | 
| 12 | 
            +
              data.tar.gz: !binary |-
         | 
| 13 | 
            +
                YmYzMWEwZDJjMmQzNDAxNjM0YTUwMWUxYmQ1Zjk0NWRmODNhZTZjNTE4ZGJm
         | 
| 14 | 
            +
                OTZiYjdlYTI0Mjg2YmM1Zjg0Nzg2ZDU5ZjZkMDI5NzJkYmM5NmU2YmJiY2Vi
         | 
| 15 | 
            +
                YmJhZTBjMGRlNGVhNDdjZDdiZThiNGFlM2NkN2Q3ZDEwODgxYTE=
         | 
    
        data/lib/mongoid/listable.rb
    CHANGED
    
    | @@ -48,7 +48,7 @@ module Mongoid | |
| 48 48 | 
             
                          else                
         | 
| 49 49 | 
             
                            self.class
         | 
| 50 50 | 
             
                          end
         | 
| 51 | 
            -
                  klass.where(field.exists => true).ne | 
| 51 | 
            +
                  klass.where(field.exists => true).ne(id: id)
         | 
| 52 52 | 
             
                end
         | 
| 53 53 |  | 
| 54 54 | 
             
                def embedded_one?
         | 
| @@ -68,7 +68,7 @@ module Mongoid | |
| 68 68 | 
             
                # @param [ Integer ] start The starting position
         | 
| 69 69 | 
             
                #
         | 
| 70 70 | 
             
                # @since 0.1.0
         | 
| 71 | 
            -
                def reposition objects, field, start
         | 
| 71 | 
            +
                def reposition objects, field, start      
         | 
| 72 72 | 
             
                  objects.each_with_index do |object, index|
         | 
| 73 73 | 
             
                    object.set field, start + index
         | 
| 74 74 | 
             
                  end
         | 
| @@ -154,7 +154,8 @@ module Mongoid | |
| 154 154 | 
             
                  # @since 0.1.0
         | 
| 155 155 | 
             
                  def change_on name
         | 
| 156 156 | 
             
                    from, to = send "#{name}_change"
         | 
| 157 | 
            -
                    from ||=  | 
| 157 | 
            +
                    from ||= siblings(name).count
         | 
| 158 | 
            +
                    to ||= siblings(name).count + 1
         | 
| 158 159 | 
             
                    to = if to > siblings(name).count + 1
         | 
| 159 160 | 
             
                           siblings(name).count + 1
         | 
| 160 161 | 
             
                         elsif to < 1
         | 
| @@ -81,6 +81,15 @@ describe Mongoid::Listable do | |
| 81 81 | 
             
                  expect(Item.send(SCOPE).where(FIELD => 4).first).to eq(item)
         | 
| 82 82 | 
             
                end
         | 
| 83 83 |  | 
| 84 | 
            +
                it 'should maintain order when moving two objects\' positions' do
         | 
| 85 | 
            +
                  item_1 = Item.send(SCOPE).where(FIELD => 8).first
         | 
| 86 | 
            +
                  item_2 = Item.send(SCOPE).where(FIELD => 9).first
         | 
| 87 | 
            +
                  item_1.update_attribute FIELD, 2
         | 
| 88 | 
            +
                  item_2.update_attribute FIELD, 6
         | 
| 89 | 
            +
                  expect(Item.send(SCOPE).where(FIELD => 2).first).to eq(item_1)
         | 
| 90 | 
            +
                  expect(Item.send(SCOPE).where(FIELD => 6).first).to eq(item_2)
         | 
| 91 | 
            +
                end
         | 
| 92 | 
            +
             | 
| 84 93 | 
             
                it 'should do nothing when assigning object to same position' do
         | 
| 85 94 | 
             
                  item = Item.send(SCOPE).where(FIELD => 5).first
         | 
| 86 95 | 
             
                  item.update_attribute FIELD, 5
         | 
| @@ -95,10 +104,15 @@ describe Mongoid::Listable do | |
| 95 104 |  | 
| 96 105 | 
             
                it 'should compensate for updated positions that are lower than bounds' do
         | 
| 97 106 | 
             
                  item = Item.send(SCOPE).where(FIELD => 5).first
         | 
| 98 | 
            -
                  item.update_attribute FIELD,  | 
| 107 | 
            +
                  item.update_attribute FIELD, 0
         | 
| 99 108 | 
             
                  expect(Item.send(SCOPE).first).to eq(item)
         | 
| 100 109 | 
             
                end
         | 
| 101 110 |  | 
| 111 | 
            +
                it 'should compensate for updated positions that are nil' do 
         | 
| 112 | 
            +
                  item = Item.send(SCOPE).where(FIELD => 5).first
         | 
| 113 | 
            +
                  item.update_attribute FIELD, nil
         | 
| 114 | 
            +
                  expect(Item.send(SCOPE).last).to eq(item)
         | 
| 115 | 
            +
                end
         | 
| 102 116 | 
             
              end
         | 
| 103 117 |  | 
| 104 118 | 
             
              describe 'lists' do
         | 
| @@ -202,6 +216,12 @@ describe Mongoid::Listable do | |
| 202 216 | 
             
                    section.update_attribute :article_position, -100
         | 
| 203 217 | 
             
                    expect(Article.first.sections.first).to eq(section)
         | 
| 204 218 | 
             
                  end
         | 
| 219 | 
            +
             | 
| 220 | 
            +
                  it 'should compensate for updated positions that are nil' do 
         | 
| 221 | 
            +
                    section = Article.first.sections.where(article_position: 5).first
         | 
| 222 | 
            +
                    section.update_attribute :article_position, nil
         | 
| 223 | 
            +
                    expect(Article.first.sections.last).to eq(section)
         | 
| 224 | 
            +
                  end
         | 
| 205 225 |  | 
| 206 226 | 
             
                end
         | 
| 207 227 |  | 
| @@ -321,6 +341,12 @@ describe Mongoid::Listable do | |
| 321 341 | 
             
                    expect(User.first.photos.first).to eq(photo)
         | 
| 322 342 | 
             
                  end
         | 
| 323 343 |  | 
| 344 | 
            +
                  it 'should compensate for updated positions that are nil' do 
         | 
| 345 | 
            +
                    photo = User.first.photos.where(user_position: 5).first
         | 
| 346 | 
            +
                    photo.update_attribute :user_position, nil
         | 
| 347 | 
            +
                    expect(User.first.photos.last).to eq(photo)
         | 
| 348 | 
            +
                  end
         | 
| 349 | 
            +
             | 
| 324 350 | 
             
                end
         | 
| 325 351 |  | 
| 326 352 | 
             
              end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,20 +1,18 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: mongoid_listable
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.2. | 
| 5 | 
            -
              prerelease: 
         | 
| 4 | 
            +
              version: 0.2.6
         | 
| 6 5 | 
             
            platform: ruby
         | 
| 7 6 | 
             
            authors:
         | 
| 8 7 | 
             
            - richardcalahan
         | 
| 9 8 | 
             
            autorequire: 
         | 
| 10 9 | 
             
            bindir: bin
         | 
| 11 10 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2013-12- | 
| 11 | 
            +
            date: 2013-12-13 00:00:00.000000000 Z
         | 
| 13 12 | 
             
            dependencies:
         | 
| 14 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 14 | 
             
              name: mongoid
         | 
| 16 15 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 17 | 
            -
                none: false
         | 
| 18 16 | 
             
                requirements:
         | 
| 19 17 | 
             
                - - ! '>='
         | 
| 20 18 | 
             
                  - !ruby/object:Gem::Version
         | 
| @@ -22,7 +20,6 @@ dependencies: | |
| 22 20 | 
             
              type: :runtime
         | 
| 23 21 | 
             
              prerelease: false
         | 
| 24 22 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 25 | 
            -
                none: false
         | 
| 26 23 | 
             
                requirements:
         | 
| 27 24 | 
             
                - - ! '>='
         | 
| 28 25 | 
             
                  - !ruby/object:Gem::Version
         | 
| @@ -30,7 +27,6 @@ dependencies: | |
| 30 27 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 31 28 | 
             
              name: bundler
         | 
| 32 29 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 33 | 
            -
                none: false
         | 
| 34 30 | 
             
                requirements:
         | 
| 35 31 | 
             
                - - ~>
         | 
| 36 32 | 
             
                  - !ruby/object:Gem::Version
         | 
| @@ -38,7 +34,6 @@ dependencies: | |
| 38 34 | 
             
              type: :development
         | 
| 39 35 | 
             
              prerelease: false
         | 
| 40 36 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 41 | 
            -
                none: false
         | 
| 42 37 | 
             
                requirements:
         | 
| 43 38 | 
             
                - - ~>
         | 
| 44 39 | 
             
                  - !ruby/object:Gem::Version
         | 
| @@ -46,7 +41,6 @@ dependencies: | |
| 46 41 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 47 42 | 
             
              name: rake
         | 
| 48 43 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 49 | 
            -
                none: false
         | 
| 50 44 | 
             
                requirements:
         | 
| 51 45 | 
             
                - - ! '>='
         | 
| 52 46 | 
             
                  - !ruby/object:Gem::Version
         | 
| @@ -54,7 +48,6 @@ dependencies: | |
| 54 48 | 
             
              type: :development
         | 
| 55 49 | 
             
              prerelease: false
         | 
| 56 50 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 57 | 
            -
                none: false
         | 
| 58 51 | 
             
                requirements:
         | 
| 59 52 | 
             
                - - ! '>='
         | 
| 60 53 | 
             
                  - !ruby/object:Gem::Version
         | 
| @@ -95,27 +88,26 @@ files: | |
| 95 88 | 
             
            homepage: ''
         | 
| 96 89 | 
             
            licenses:
         | 
| 97 90 | 
             
            - MIT
         | 
| 91 | 
            +
            metadata: {}
         | 
| 98 92 | 
             
            post_install_message: 
         | 
| 99 93 | 
             
            rdoc_options: []
         | 
| 100 94 | 
             
            require_paths:
         | 
| 101 95 | 
             
            - lib
         | 
| 102 96 | 
             
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 103 | 
            -
              none: false
         | 
| 104 97 | 
             
              requirements:
         | 
| 105 98 | 
             
              - - ! '>='
         | 
| 106 99 | 
             
                - !ruby/object:Gem::Version
         | 
| 107 100 | 
             
                  version: '0'
         | 
| 108 101 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 109 | 
            -
              none: false
         | 
| 110 102 | 
             
              requirements:
         | 
| 111 103 | 
             
              - - ! '>='
         | 
| 112 104 | 
             
                - !ruby/object:Gem::Version
         | 
| 113 105 | 
             
                  version: '0'
         | 
| 114 106 | 
             
            requirements: []
         | 
| 115 107 | 
             
            rubyforge_project: 
         | 
| 116 | 
            -
            rubygems_version: 1. | 
| 108 | 
            +
            rubygems_version: 2.1.11
         | 
| 117 109 | 
             
            signing_key: 
         | 
| 118 | 
            -
            specification_version:  | 
| 110 | 
            +
            specification_version: 4
         | 
| 119 111 | 
             
            summary: ''
         | 
| 120 112 | 
             
            test_files:
         | 
| 121 113 | 
             
            - spec/models/article.rb
         |