Skip to content

Instantly share code, notes, and snippets.

@joshmcarthur
Last active July 9, 2020 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshmcarthur/718ff20d1d5f0b25690d6afb568742e5 to your computer and use it in GitHub Desktop.
Save joshmcarthur/718ff20d1d5f0b25690d6afb568742e5 to your computer and use it in GitHub Desktop.
How to load fixtures one at a time in Rails 5
# When Rails loads fixtures, it does so via a big multi-insert. If there is something wrong with a
# fixture, it's extremely difficult to find out _which_ fixture is wrong.
# This can be run in a binding.pry OR in a Rails console.
require "active_record/fixtures"
all = fixture_set_names = Dir["spec/fixtures/**/*.yml"].map { |f| File.basename f, '.yml' }
all.each do |fix|
puts fix; ActiveRecord::FixtureSet.create_fixtures("#{Rails.root}/spec/fixtures", [fix])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment