Skip to content

Instantly share code, notes, and snippets.

@delba
Last active December 17, 2015 19:09
Show Gist options
  • Select an option

  • Save delba/5658761 to your computer and use it in GitHub Desktop.

Select an option

Save delba/5658761 to your computer and use it in GitHub Desktop.
Testing that a callback is triggered
require 'test_helper'
class AnswerTest < ActiveSupport::TestCase
def setup
Answer.before_save do
instance_variable_set :@first_callback, true
end
@answer = Answer.create!
end
test "callbacks are cumulative" do
Answer.before_save do
instance_variable_set :@second_callback, true
end
@answer.save
assert @answer.instance_variable_get(:@first_callback)
assert @answer.instance_variable_get(:@second_callback)
end
test "toggle_accept! skip callbacks" do
Answer.before_save do
instance_variable_set :@callback_called, true
end
@answer.toggle_accept!
refute @answer.instance_variable_get(:@callback_called)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment