Skip to content

Commit

Permalink
Test after_save
Browse files Browse the repository at this point in the history
* Also cover the case when some callbacks didn't get called
  • Loading branch information
ujihisa authored and a2ikm committed Dec 14, 2020
1 parent c981569 commit 2a69c8d
Showing 1 changed file with 42 additions and 5 deletions.
47 changes: 42 additions & 5 deletions spec/functional/dirty_with_callbacks_spec.rb
Expand Up @@ -2,21 +2,58 @@

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 {
changes.should == {}
previous_changes.should == {'x' => [nil, 'hello']}
history[:after_create] = {
changes: changes,
previous_changes: previous_changes,
}
}
after_update {
changes.should == {}
previous_changes.should == {'x' => ['hello', 'world']}
history[:after_update] = {
changes: changes,
previous_changes: previous_changes,
}
}
}

d = document.create(x: 'hello')
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

0 comments on commit 2a69c8d

Please sign in to comment.