Created
April 22, 2015 03:53
-
-
Save runningferret/8fc78086595f9f0967e1 to your computer and use it in GitHub Desktop.
Use Minitest and ActiveRecord4 to load fixtures, without Rails
This file contains 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
Bulk of this snagged from: https://gist.github.com/guilleiguaran/56a3879da5f6b6f467ce | |
Fixtures bit snagged from: https://github.com/cucumber/cucumber/wiki/Fixtures | |
require 'active_record' | |
require 'active_record/fixtures' | |
class MiniTest::Spec | |
ActiveRecord::Base.establish_connection( | |
:adapter => "sqlite3", | |
:database => "./db/development.sqlite3" | |
) | |
ActiveRecord::Migration.check_pending! | |
include ActiveRecord::TestFixtures | |
ActiveRecord::FixtureSet.reset_cache | |
fixtures_folder = File.join(File.dirname(__FILE__), 'fixtures') | |
the_fixtures = Dir[File.join(fixtures_folder, '*.yml')].map {|f| File.basename(f, '.yml') } | |
ActiveRecord::FixtureSet.create_fixtures(fixtures_folder, the_fixtures) | |
alias :method_name :name if defined? :name | |
self.fixture_path = File.join(File.dirname(__FILE__), 'fixtures') | |
self.use_instantiated_fixtures = false | |
self.use_transactional_fixtures = true | |
fixtures :all | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How would you access let's say
users(:user_1)
having theusers.yml
file?