Skip to content

Instantly share code, notes, and snippets.

@runningferret
Created April 22, 2015 03:53
Show Gist options
  • Save runningferret/8fc78086595f9f0967e1 to your computer and use it in GitHub Desktop.
Save runningferret/8fc78086595f9f0967e1 to your computer and use it in GitHub Desktop.
Use Minitest and ActiveRecord4 to load fixtures, without Rails
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
@fcastellanos
Copy link

How would you access let's say users(:user_1) having the users.yml file?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment