Last active
July 9, 2020 23:00
-
-
Save joshmcarthur/718ff20d1d5f0b25690d6afb568742e5 to your computer and use it in GitHub Desktop.
How to load fixtures one at a time in Rails 5
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
# 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