Created
June 26, 2012 15:49
-
-
Save mudge/2996609 to your computer and use it in GitHub Desktop.
A bare-bones spec helper for testing Active Record classes without the rest of Rails.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "active_record" | |
require "database_cleaner" | |
require "rspec/rails/extensions" | |
# Note that this *will not load your Rails configuration* which means things like | |
# mass assignment protection by default, etc. will not be set. | |
RSpec.configure do |config| | |
config.before(:suite) do | |
ActiveRecord::Base.configurations = | |
YAML.load_file(File.expand_path("../../config/database.yml", __FILE__)) | |
ActiveRecord::Base.establish_connection("test") | |
DatabaseCleaner.strategy = :transaction | |
DatabaseCleaner.clean_with(:truncation) | |
end | |
config.before(:each) do | |
DatabaseCleaner.start | |
end | |
config.after(:each) do | |
DatabaseCleaner.clean | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment