Skip to content

Instantly share code, notes, and snippets.

@joonyou
Created May 7, 2010 16:35
Show Gist options
  • Save joonyou/393685 to your computer and use it in GitHub Desktop.
Save joonyou/393685 to your computer and use it in GitHub Desktop.
RSec DB transaction
%w(rubygems active_record spec sqlite3).each {|lib| require lib}
ActiveRecord::Base.establish_connection({:adapter => 'sqlite3',
:database => 'rtest.sqlite3'
})
# ActiveRecord transactional specs (without Rails)
Spec::Runner.configure do |config|
config.before do
ActiveRecord::Base.connection.begin_db_transaction
ActiveRecord::Base.connection.increment_open_transactions
end
config.after do
if ActiveRecord::Base.connection.open_transactions != 0
ActiveRecord::Base.connection.rollback_db_transaction
ActiveRecord::Base.connection.decrement_open_transactions
end
end
end
class Joon < ActiveRecord::Base
end
describe "test to see if the data saves" do
it "should remove the data once this is done" do
Joon.new({:name => 'Sydney', :status => 'daughter'}).save
Joon.all.size.should eql(3)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment