mongoid_delorean 1.1.1 → 1.2.0
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 +7 -0
- data/.gitignore +2 -18
- data/.travis.yml +7 -0
- data/Gemfile +0 -3
- data/README.md +7 -1
- data/Rakefile +5 -6
- data/lib/mongoid/delorean/trackable.rb +19 -11
- data/lib/mongoid/delorean/version.rb +1 -1
- data/mongoid_delorean.gemspec +3 -0
- data/spec/mongoid/delorean/trackable_spec.rb +7 -1
- data/spec/support/models.rb +9 -1
- metadata +52 -14
- data/Gemfile.lock +0 -44
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA1:
         | 
| 3 | 
            +
              metadata.gz: 6046b3012b6e28a626ce3601fa23e58298e9fe91
         | 
| 4 | 
            +
              data.tar.gz: 4ec10da2a928268a7327040ad719b230a338f796
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: 8786110df221df1adcd8ca77c475c4a556f8e9245ebc5ff547f3db18083d040022fef15f38d338a1bf5110ef10691c5d45989c74060c3b017c91206b2af1d361
         | 
| 7 | 
            +
              data.tar.gz: d8e501f26a7b05e8c6af845badc918b9b52fa6dbc9ccc64bb4ef142c64a2e859a2291732a2f0e65bc3a672492b72a47437711c4f3cbc5d0c10ee2fa670a6c36b
         | 
    
        data/.gitignore
    CHANGED
    
    
    
        data/.travis.yml
    ADDED
    
    
    
        data/Gemfile
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -4,7 +4,7 @@ A simple Mongoid 3 versioning system that works with embedded documents. | |
| 4 4 |  | 
| 5 5 | 
             
            Tracking document changes can be really important to a lot of systems, unfortunately all of the Mongoid versioning plugins either only work with Mongoid 2.x, don't handle embedded document changes, or worse, just don't work. <code>Mongoid::Delorean</code> solves those problems.
         | 
| 6 6 |  | 
| 7 | 
            -
            <code>Mongoid::Delorean</code> is a simple plugin that does just what it sets out to do. It stores each version of your document as you make changes and then allows you to revert to earlier versions of the document. | 
| 7 | 
            +
            <code>Mongoid::Delorean</code> is a simple plugin that does just what it sets out to do. It stores each version of your document as you make changes and then allows you to revert to earlier versions of the document.
         | 
| 8 8 |  | 
| 9 9 | 
             
            If this wasn't great already, <code>Mongoid::Delorean</code> will even track changes made to any embedded documents, or documents that those embedded documents may have, and so on.
         | 
| 10 10 |  | 
| @@ -100,3 +100,9 @@ a.version # => 1 | |
| 100 100 | 
             
            4. Commit your changes (`git commit -am 'Add some feature'`)
         | 
| 101 101 | 
             
            5. Push to the branch (`git push origin my-new-feature`)
         | 
| 102 102 | 
             
            6. Create new Pull Request
         | 
| 103 | 
            +
             | 
| 104 | 
            +
            ## Contributors
         | 
| 105 | 
            +
             | 
| 106 | 
            +
            * Mark Bates
         | 
| 107 | 
            +
            * Nick Muerdter
         | 
| 108 | 
            +
            * Felipe Rodrigues
         | 
    
        data/Rakefile
    CHANGED
    
    | @@ -1,9 +1,8 @@ | |
| 1 | 
            -
            require 'bundler' | 
| 1 | 
            +
            require 'bundler'
         | 
| 2 2 | 
             
            Bundler::GemHelper.install_tasks
         | 
| 3 3 |  | 
| 4 | 
            -
             | 
| 5 | 
            -
             | 
| 4 | 
            +
            require 'rspec/core/rake_task'
         | 
| 5 | 
            +
            RSpec::Core::RakeTask.new('spec')
         | 
| 6 6 |  | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 9 | 
            -
            end
         | 
| 7 | 
            +
            desc "Run tests"
         | 
| 8 | 
            +
            task :default => :spec
         | 
| @@ -52,7 +52,7 @@ module Mongoid | |
| 52 52 | 
             
                  end
         | 
| 53 53 |  | 
| 54 54 | 
             
                  module CommonEmbeddedMethods
         | 
| 55 | 
            -
             | 
| 55 | 
            +
             | 
| 56 56 | 
             
                    def save_version
         | 
| 57 57 | 
             
                      self._parent.save_version if self._parent.respond_to?(:save_version)
         | 
| 58 58 | 
             
                    end
         | 
| @@ -73,9 +73,13 @@ module Mongoid | |
| 73 73 | 
             
                      self.embedded_relations.each do |name, details|
         | 
| 74 74 | 
             
                        relation = self.send(name)
         | 
| 75 75 | 
             
                        relation_changes[name] = []
         | 
| 76 | 
            -
                         | 
| 77 | 
            -
             | 
| 78 | 
            -
                         | 
| 76 | 
            +
                        if details.relation == Mongoid::Relations::Embedded::One
         | 
| 77 | 
            +
                          relation_changes[name] = relation.changes_with_relations if relation
         | 
| 78 | 
            +
                        else
         | 
| 79 | 
            +
                          r_changes = relation.map {|o| o.changes_with_relations}
         | 
| 80 | 
            +
                          relation_changes[name] << r_changes unless r_changes.empty?
         | 
| 81 | 
            +
                          relation_changes[name].flatten!
         | 
| 82 | 
            +
                        end
         | 
| 79 83 | 
             
                        relation_changes.delete(name) if relation_changes[name].empty?
         | 
| 80 84 | 
             
                      end
         | 
| 81 85 |  | 
| @@ -85,15 +89,19 @@ module Mongoid | |
| 85 89 |  | 
| 86 90 | 
             
                    def attributes_with_relations
         | 
| 87 91 | 
             
                      _attributes = self.attributes.dup
         | 
| 88 | 
            -
             | 
| 92 | 
            +
             | 
| 89 93 | 
             
                      relation_attrs = {}
         | 
| 90 94 | 
             
                      self.embedded_relations.each do |name, details|
         | 
| 91 95 | 
             
                        relation = self.send(name)
         | 
| 92 | 
            -
                         | 
| 93 | 
            -
             | 
| 94 | 
            -
                         | 
| 95 | 
            -
             | 
| 96 | 
            -
             | 
| 96 | 
            +
                        if details.relation == Mongoid::Relations::Embedded::One
         | 
| 97 | 
            +
                          relation_attrs[name] = relation.attributes_with_relations if relation
         | 
| 98 | 
            +
                        else
         | 
| 99 | 
            +
                          relation_attrs[name] = []
         | 
| 100 | 
            +
                          r_attrs = relation.map {|o| o.attributes_with_relations}
         | 
| 101 | 
            +
                          relation_attrs[name] << r_attrs unless r_attrs.empty?
         | 
| 102 | 
            +
                          r_changes = relation.map {|o| o.changes}
         | 
| 103 | 
            +
                          relation_attrs[name].flatten!
         | 
| 104 | 
            +
                        end
         | 
| 97 105 | 
             
                      end
         | 
| 98 106 | 
             
                      _attributes.merge!(relation_attrs)
         | 
| 99 107 | 
             
                      return _attributes
         | 
| @@ -103,4 +111,4 @@ module Mongoid | |
| 103 111 |  | 
| 104 112 | 
             
                end
         | 
| 105 113 | 
             
              end
         | 
| 106 | 
            -
            end
         | 
| 114 | 
            +
            end
         | 
    
        data/mongoid_delorean.gemspec
    CHANGED
    
    
| @@ -151,6 +151,12 @@ describe Mongoid::Delorean::Trackable do | |
| 151 151 |  | 
| 152 152 | 
             
                  version = a.versions.last
         | 
| 153 153 | 
             
                  version.altered_attributes.should eql({"pages"=>[{"sections"=>[{"_id"=>[nil, section.id], "body"=>[nil, "some body text"]}]}], "version"=>[2, 3]})
         | 
| 154 | 
            +
             | 
| 155 | 
            +
                  footer = page.build_footer(:content => "some footer text")
         | 
| 156 | 
            +
                  a.save!
         | 
| 157 | 
            +
             | 
| 158 | 
            +
                  version = a.versions.last
         | 
| 159 | 
            +
                  version.altered_attributes.should eql({"pages"=>[{"sections"=>[{}], "footer"=>{"_id"=>[nil, footer.id], "content"=>[nil, "some footer text"]}}], "version"=>[3, 4]})
         | 
| 154 160 | 
             
                end
         | 
| 155 161 |  | 
| 156 162 | 
             
                it "tracks the full set of attributes at the time of saving" do
         | 
| @@ -234,4 +240,4 @@ describe Mongoid::Delorean::Trackable do | |
| 234 240 |  | 
| 235 241 | 
             
              end
         | 
| 236 242 |  | 
| 237 | 
            -
            end
         | 
| 243 | 
            +
            end
         | 
    
        data/spec/support/models.rb
    CHANGED
    
    | @@ -27,9 +27,17 @@ class Page | |
| 27 27 |  | 
| 28 28 | 
             
              embedded_in :article, inverse_of: :pages
         | 
| 29 29 | 
             
              embeds_many :sections
         | 
| 30 | 
            +
              embeds_one :footer
         | 
| 30 31 | 
             
            end
         | 
| 31 32 |  | 
| 33 | 
            +
            class Footer
         | 
| 34 | 
            +
              include Mongoid::Document
         | 
| 35 | 
            +
              include Mongoid::Timestamps
         | 
| 32 36 |  | 
| 37 | 
            +
              field :content, type: String
         | 
| 38 | 
            +
             | 
| 39 | 
            +
              embedded_in :page
         | 
| 40 | 
            +
            end
         | 
| 33 41 |  | 
| 34 42 | 
             
            class User
         | 
| 35 43 | 
             
              include Mongoid::Document
         | 
| @@ -38,4 +46,4 @@ class User | |
| 38 46 |  | 
| 39 47 | 
             
              field :name, type: String
         | 
| 40 48 | 
             
              field :age, type: Integer
         | 
| 41 | 
            -
            end
         | 
| 49 | 
            +
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,32 +1,71 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: mongoid_delorean
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1. | 
| 5 | 
            -
              prerelease: 
         | 
| 4 | 
            +
              version: 1.2.0
         | 
| 6 5 | 
             
            platform: ruby
         | 
| 7 6 | 
             
            authors:
         | 
| 8 7 | 
             
            - Mark Bates
         | 
| 9 8 | 
             
            autorequire: 
         | 
| 10 9 | 
             
            bindir: bin
         | 
| 11 10 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date:  | 
| 11 | 
            +
            date: 2013-12-18 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
         | 
| 21 19 | 
             
                    version: 3.0.0
         | 
| 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
         | 
| 29 26 | 
             
                    version: 3.0.0
         | 
| 27 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 28 | 
            +
              name: rake
         | 
| 29 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 | 
            +
                requirements:
         | 
| 31 | 
            +
                - - '>='
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            +
                    version: '0'
         | 
| 34 | 
            +
              type: :development
         | 
| 35 | 
            +
              prerelease: false
         | 
| 36 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 | 
            +
                requirements:
         | 
| 38 | 
            +
                - - '>='
         | 
| 39 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            +
                    version: '0'
         | 
| 41 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 42 | 
            +
              name: rspec
         | 
| 43 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 | 
            +
                requirements:
         | 
| 45 | 
            +
                - - '>='
         | 
| 46 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 47 | 
            +
                    version: '0'
         | 
| 48 | 
            +
              type: :development
         | 
| 49 | 
            +
              prerelease: false
         | 
| 50 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 | 
            +
                requirements:
         | 
| 52 | 
            +
                - - '>='
         | 
| 53 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 54 | 
            +
                    version: '0'
         | 
| 55 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 56 | 
            +
              name: database_cleaner
         | 
| 57 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 58 | 
            +
                requirements:
         | 
| 59 | 
            +
                - - '>='
         | 
| 60 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 61 | 
            +
                    version: '0'
         | 
| 62 | 
            +
              type: :development
         | 
| 63 | 
            +
              prerelease: false
         | 
| 64 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 65 | 
            +
                requirements:
         | 
| 66 | 
            +
                - - '>='
         | 
| 67 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 68 | 
            +
                    version: '0'
         | 
| 30 69 | 
             
            description: A simple Mongoid 3 versioning system that works with embedded documents.
         | 
| 31 70 | 
             
            email:
         | 
| 32 71 | 
             
            - mark@markbates.com
         | 
| @@ -35,8 +74,8 @@ extensions: [] | |
| 35 74 | 
             
            extra_rdoc_files: []
         | 
| 36 75 | 
             
            files:
         | 
| 37 76 | 
             
            - .gitignore
         | 
| 77 | 
            +
            - .travis.yml
         | 
| 38 78 | 
             
            - Gemfile
         | 
| 39 | 
            -
            - Gemfile.lock
         | 
| 40 79 | 
             
            - LICENSE.txt
         | 
| 41 80 | 
             
            - README.md
         | 
| 42 81 | 
             
            - Rakefile
         | 
| @@ -53,27 +92,26 @@ files: | |
| 53 92 | 
             
            - spec/support/models.rb
         | 
| 54 93 | 
             
            homepage: ''
         | 
| 55 94 | 
             
            licenses: []
         | 
| 95 | 
            +
            metadata: {}
         | 
| 56 96 | 
             
            post_install_message: 
         | 
| 57 97 | 
             
            rdoc_options: []
         | 
| 58 98 | 
             
            require_paths:
         | 
| 59 99 | 
             
            - lib
         | 
| 60 100 | 
             
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 61 | 
            -
              none: false
         | 
| 62 101 | 
             
              requirements:
         | 
| 63 | 
            -
              - -  | 
| 102 | 
            +
              - - '>='
         | 
| 64 103 | 
             
                - !ruby/object:Gem::Version
         | 
| 65 104 | 
             
                  version: '0'
         | 
| 66 105 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 67 | 
            -
              none: false
         | 
| 68 106 | 
             
              requirements:
         | 
| 69 | 
            -
              - -  | 
| 107 | 
            +
              - - '>='
         | 
| 70 108 | 
             
                - !ruby/object:Gem::Version
         | 
| 71 109 | 
             
                  version: '0'
         | 
| 72 110 | 
             
            requirements: []
         | 
| 73 111 | 
             
            rubyforge_project: 
         | 
| 74 | 
            -
            rubygems_version: 1. | 
| 112 | 
            +
            rubygems_version: 2.1.11
         | 
| 75 113 | 
             
            signing_key: 
         | 
| 76 | 
            -
            specification_version:  | 
| 114 | 
            +
            specification_version: 4
         | 
| 77 115 | 
             
            summary: A simple Mongoid 3 versioning system that works with embedded documents.
         | 
| 78 116 | 
             
            test_files:
         | 
| 79 117 | 
             
            - spec/config.yml
         | 
    
        data/Gemfile.lock
    DELETED
    
    | @@ -1,44 +0,0 @@ | |
| 1 | 
            -
            PATH
         | 
| 2 | 
            -
              remote: .
         | 
| 3 | 
            -
              specs:
         | 
| 4 | 
            -
                mongoid_delorean (1.1.1)
         | 
| 5 | 
            -
                  mongoid (>= 3.0.0)
         | 
| 6 | 
            -
             | 
| 7 | 
            -
            GEM
         | 
| 8 | 
            -
              remote: https://rubygems.org/
         | 
| 9 | 
            -
              specs:
         | 
| 10 | 
            -
                activemodel (3.2.8)
         | 
| 11 | 
            -
                  activesupport (= 3.2.8)
         | 
| 12 | 
            -
                  builder (~> 3.0.0)
         | 
| 13 | 
            -
                activesupport (3.2.8)
         | 
| 14 | 
            -
                  i18n (~> 0.6)
         | 
| 15 | 
            -
                  multi_json (~> 1.0)
         | 
| 16 | 
            -
                builder (3.0.3)
         | 
| 17 | 
            -
                database_cleaner (0.8.0)
         | 
| 18 | 
            -
                diff-lcs (1.1.3)
         | 
| 19 | 
            -
                i18n (0.6.1)
         | 
| 20 | 
            -
                mongoid (3.0.5)
         | 
| 21 | 
            -
                  activemodel (~> 3.1)
         | 
| 22 | 
            -
                  moped (~> 1.1)
         | 
| 23 | 
            -
                  origin (~> 1.0)
         | 
| 24 | 
            -
                  tzinfo (~> 0.3.22)
         | 
| 25 | 
            -
                moped (1.2.1)
         | 
| 26 | 
            -
                multi_json (1.3.6)
         | 
| 27 | 
            -
                origin (1.0.8)
         | 
| 28 | 
            -
                rspec (2.11.0)
         | 
| 29 | 
            -
                  rspec-core (~> 2.11.0)
         | 
| 30 | 
            -
                  rspec-expectations (~> 2.11.0)
         | 
| 31 | 
            -
                  rspec-mocks (~> 2.11.0)
         | 
| 32 | 
            -
                rspec-core (2.11.1)
         | 
| 33 | 
            -
                rspec-expectations (2.11.3)
         | 
| 34 | 
            -
                  diff-lcs (~> 1.1.3)
         | 
| 35 | 
            -
                rspec-mocks (2.11.2)
         | 
| 36 | 
            -
                tzinfo (0.3.33)
         | 
| 37 | 
            -
             | 
| 38 | 
            -
            PLATFORMS
         | 
| 39 | 
            -
              ruby
         | 
| 40 | 
            -
             | 
| 41 | 
            -
            DEPENDENCIES
         | 
| 42 | 
            -
              database_cleaner
         | 
| 43 | 
            -
              mongoid_delorean!
         | 
| 44 | 
            -
              rspec
         |