Skip to content

Instantly share code, notes, and snippets.

@barelyknown
Last active January 23, 2018 11:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barelyknown/153e94c0d847e15251a8 to your computer and use it in GitHub Desktop.
Save barelyknown/153e94c0d847e15251a8 to your computer and use it in GitHub Desktop.
Testing after_commit :do_something, on: :create
describe "#after_commit" do
context "on: :create" do
before do
expect(subject).to receive(:transaction_record_state).with(:new_record).and_return(true)
end
it "calls initiate_async" do
expect(subject).to receive(:initiate_async)
subject.run_callbacks(:commit)
end
end
context "not on: create" do
before do
expect(subject).to receive(:transaction_record_state).with(:new_record).and_return(false)
end
it "does not call initiate_async" do
expect(subject).to_not receive(:initiate_async)
subject.run_callbacks(:commit)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment