Skip to content

Instantly share code, notes, and snippets.

@ecoologic
Last active October 4, 2015 09:10
Show Gist options
  • Save ecoologic/8ec356ca7053ed3e9bb7 to your computer and use it in GitHub Desktop.
Save ecoologic/8ec356ca7053ed3e9bb7 to your computer and use it in GitHub Desktop.
Rails seeds specs example
# Wrap in transaction, it's quicker
# and if something fails it will be easier to re-run them separately
ActiveRecord::Base.transaction do
User.create!(email: "a@b.c", etc: :etc) # Don't use FactoryGirl
end
# And they can be tested as follows
# spec/db/seed_spec.rb
require "rails_helper"
describe "Seeds" do
before { require "#{Rails.root}/db/seeds.rb" }
it "creats the seeds" do
expect(User.count).to eq 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment