active_metadata 0.8.7 → 0.8.7.1
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.
| @@ -9,10 +9,7 @@ module ActiveMetadata::Persistence::History | |
| 9 9 | 
             
                def save_history
         | 
| 10 10 | 
             
                  return if ActiveMetadata.skip_history?
         | 
| 11 11 | 
             
                  self.changes.each do |key, value|
         | 
| 12 | 
            -
                     | 
| 13 | 
            -
                    # https://github.com/rails/rails/issues/8874
         | 
| 14 | 
            -
                    return if value.compact.empty?
         | 
| 15 | 
            -
                    next if ActiveMetadata::CONFIG['history_skip_fields'].include?(key)
         | 
| 12 | 
            +
                    next if ActiveMetadata::CONFIG['history_skip_fields'].include?(key) || !change_is_valid_for_history?(value)
         | 
| 16 13 | 
             
                    ActiveMetadata::History.create! :value => value[1],:model_class => metadata_class, :model_id => metadata_id,:label => key.to_s, :created_by => current_user_id
         | 
| 17 14 | 
             
                    invalidate_history_cache_for key.to_s
         | 
| 18 15 | 
             
                    self.send(:send_notification, key, value[0], value[1], :history_message, current_user_id) unless skip_history_notification?
         | 
| @@ -35,6 +32,20 @@ module ActiveMetadata::Persistence::History | |
| 35 32 | 
             
                  ActiveMetadata::History.all(:conditions => {:model_class => metadata_class, :model_id => metadata_id,:label => field}, :order => order)
         | 
| 36 33 | 
             
                end
         | 
| 37 34 |  | 
| 35 | 
            +
                private
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                # Private
         | 
| 38 | 
            +
                #
         | 
| 39 | 
            +
                # - change The change array coming from AR changes method
         | 
| 40 | 
            +
                #
         | 
| 41 | 
            +
                # Return false if chnage has the following aspect:
         | 
| 42 | 
            +
                #  * [nil, nil]
         | 
| 43 | 
            +
                #  * ["", nil]
         | 
| 44 | 
            +
                #  * [nil, ""]
         | 
| 45 | 
            +
                def change_is_valid_for_history? change
         | 
| 46 | 
            +
                  sanitized_change = change.dup.compact
         | 
| 47 | 
            +
                  sanitized_change.empty? || (sanitized_change.size == 1 && sanitized_change[0].to_s.blank?) ? false : true
         | 
| 48 | 
            +
                end
         | 
| 38 49 |  | 
| 39 50 | 
             
              end
         | 
| 40 51 | 
             
            end
         | 
    
        data/spec/lib/history_spec.rb
    CHANGED
    
    | @@ -3,7 +3,6 @@ require "time" | |
| 3 3 |  | 
| 4 4 | 
             
            describe ActiveMetadata do
         | 
| 5 5 |  | 
| 6 | 
            -
             | 
| 7 6 | 
             
              describe "history" do
         | 
| 8 7 |  | 
| 9 8 | 
             
                before(:each) do
         | 
| @@ -28,8 +27,6 @@ describe ActiveMetadata do | |
| 28 27 | 
             
                end
         | 
| 29 28 |  | 
| 30 29 | 
             
                it "should not save the history and send any notification if new value and old are both nil" do
         | 
| 31 | 
            -
                  # see
         | 
| 32 | 
            -
                  # https://github.com/rails/rails/issues/8874
         | 
| 33 30 | 
             
                  @user = User.create!(:email => "email@email.it", :firstname => 'John', :lastname => 'smith')
         | 
| 34 31 | 
             
                  ActiveMetadata::Watcher.create! :model_class => "Document", :label => :date, :owner_id => @user.id
         | 
| 35 32 | 
             
                  @document.date = ""
         | 
| @@ -38,6 +35,15 @@ describe ActiveMetadata do | |
| 38 35 | 
             
                  @document.history_for(:date).should be_empty
         | 
| 39 36 | 
             
                end
         | 
| 40 37 |  | 
| 38 | 
            +
                it "should not save the history and send any notification if changes is [nil,""]" do
         | 
| 39 | 
            +
                  @user = User.create!(:email => "email@email.it", :lastname => 'smith')
         | 
| 40 | 
            +
                  ActiveMetadata::Watcher.create! :model_class => "Document", :label => :date, :owner_id => @user.id
         | 
| 41 | 
            +
                  @document.surname = ""
         | 
| 42 | 
            +
                  @document.save
         | 
| 43 | 
            +
                  @document.notifier.should be_nil
         | 
| 44 | 
            +
                  @document.history_for(:surname).should be_empty
         | 
| 45 | 
            +
                end
         | 
| 46 | 
            +
             | 
| 41 47 | 
             
                it "should verify that history return records only for the self document" do
         | 
| 42 48 | 
             
                  # fixtures
         | 
| 43 49 | 
             
                  @another_doc = Document.create :name => "Andrea"
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: active_metadata
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.8.7
         | 
| 4 | 
            +
              version: 0.8.7.1
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| @@ -10,7 +10,7 @@ authors: | |
| 10 10 | 
             
            autorequire: 
         | 
| 11 11 | 
             
            bindir: bin
         | 
| 12 12 | 
             
            cert_chain: []
         | 
| 13 | 
            -
            date: 2013-01- | 
| 13 | 
            +
            date: 2013-01-16 00:00:00.000000000 Z
         | 
| 14 14 | 
             
            dependencies:
         | 
| 15 15 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 16 16 | 
             
              name: rails
         | 
| @@ -245,7 +245,6 @@ files: | |
| 245 245 | 
             
            - spec/dummy/public/500.html
         | 
| 246 246 | 
             
            - spec/dummy/public/favicon.ico
         | 
| 247 247 | 
             
            - spec/dummy/script/rails
         | 
| 248 | 
            -
            - spec/dummy/tmp/cache/.gitkeep
         | 
| 249 248 | 
             
            - spec/helpers/active_metadata/stream_helpers_spec.rb
         | 
| 250 249 | 
             
            - spec/lib/active_metadata_spec.rb
         | 
| 251 250 | 
             
            - spec/lib/attachments_spec.rb
         | 
| @@ -278,7 +277,7 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 278 277 | 
             
                  version: '0'
         | 
| 279 278 | 
             
                  segments:
         | 
| 280 279 | 
             
                  - 0
         | 
| 281 | 
            -
                  hash:  | 
| 280 | 
            +
                  hash: -264193675356772785
         | 
| 282 281 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 283 282 | 
             
              none: false
         | 
| 284 283 | 
             
              requirements:
         | 
| @@ -287,7 +286,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 287 286 | 
             
                  version: '0'
         | 
| 288 287 | 
             
                  segments:
         | 
| 289 288 | 
             
                  - 0
         | 
| 290 | 
            -
                  hash:  | 
| 289 | 
            +
                  hash: -264193675356772785
         | 
| 291 290 | 
             
            requirements: []
         | 
| 292 291 | 
             
            rubyforge_project: active_metadata
         | 
| 293 292 | 
             
            rubygems_version: 1.8.24
         | 
| @@ -340,7 +339,6 @@ test_files: | |
| 340 339 | 
             
            - spec/dummy/public/500.html
         | 
| 341 340 | 
             
            - spec/dummy/public/favicon.ico
         | 
| 342 341 | 
             
            - spec/dummy/script/rails
         | 
| 343 | 
            -
            - spec/dummy/tmp/cache/.gitkeep
         | 
| 344 342 | 
             
            - spec/helpers/active_metadata/stream_helpers_spec.rb
         | 
| 345 343 | 
             
            - spec/lib/active_metadata_spec.rb
         | 
| 346 344 | 
             
            - spec/lib/attachments_spec.rb
         | 
| 
            File without changes
         |