Skip to content

Instantly share code, notes, and snippets.

@ClayShentrup
Created December 2, 2015 20:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ClayShentrup/026550c3feb247829fb3 to your computer and use it in GitHub Desktop.
Save ClayShentrup/026550c3feb247829fb3 to your computer and use it in GitHub Desktop.
Testing that code executes within a block, e.g. transaction or time zone
it('uses the client time zone') do
allow(described_class).to receive(:delete_cache) do
fail unless Time.zone == client_time_zone
end
allow(described_class).to receive(:create_cache) do
fail unless Time.zone == client_time_zone
end
update_for_year
end
it('uses a transaction') do
test_transaction = ActiveRecord::Base.connection.current_transaction
allow(described_class).to receive(:delete_cache) do
fail if ActiveRecord::Base.connection.current_transaction ==
test_transaction
end
allow(described_class).to receive(:create_cache) do
fail if ActiveRecord::Base.connection.current_transaction ==
test_transaction
end
update_for_year
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment