Sha256: 67d913b5b68d5656d1161f7725c2bd71bb9c7af5cdc5f4ca4d3cb0efb9f36446

Contents?: true

Size: 1.21 KB

Versions: 7

Compression:

Stored size: 1.21 KB

Contents

require 'spec_helper'

describe 'DirtyWithCallbacks' do
  it 'should update its changes/previous_changes before after_create/after_update callbacks' do
    history = {}

    document = Doc {
      key :x, String

      after_save {
        history[:after_save] = {
          changes: changes,
          previous_changes: previous_changes,
        }
      }
      after_create {
        history[:after_create] = {
          changes: changes,
          previous_changes: previous_changes,
        }
      }
      after_update {
        history[:after_update] = {
          changes: changes,
          previous_changes: previous_changes,
        }
      }
    }

    d = document.new(x: 'hello')
    d.save

    history.should == {
      after_save: {
        changes: {},
        previous_changes: {'x' => [nil, 'hello']},
      },
      after_create: {
        changes: {},
        previous_changes: {'x' => [nil, 'hello']},
      },
    }
    history.clear

    d.x = 'world'
    d.save!

    history.should == {
      after_save: {
        changes: {},
        previous_changes: {'x' => ['hello', 'world']},
      },
      after_update: {
        changes: {},
        previous_changes: {'x' => ['hello', 'world']},
      },
    }
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
mongo_mapper-0.17.0 spec/functional/dirty_with_callbacks_spec.rb
mongo_mapper-0.16.0 spec/functional/dirty_with_callbacks_spec.rb
mongo_mapper-0.15.6 spec/functional/dirty_with_callbacks_spec.rb
mongo_mapper-0.15.5 spec/functional/dirty_with_callbacks_spec.rb
mongo_mapper-0.15.4 spec/functional/dirty_with_callbacks_spec.rb
mongo_mapper-0.15.3 spec/functional/dirty_with_callbacks_spec.rb
mongo_mapper-0.15.2 spec/functional/dirty_with_callbacks_spec.rb