-
-
Save clowder/3049680 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
# Note that this *will not load your Rails configuration* which means things like | |
# mass assignment protection by default, etc. will not be set. | |
require "active_record" | |
ActiveRecord::Base.configurations = YAML.load_file(File.expand_path("../../config/database.yml", __FILE__)) | |
ActiveRecord::Base.establish_connection("test") | |
# Stick your ActiveRecord junk (i.e. extensions) here | |
require "database_cleaner" | |
require "rspec/rails/extensions" | |
RSpec.configure do |config| | |
config.before(:suite) do | |
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