Skip to content

Instantly share code, notes, and snippets.

@lmiller1990
Created September 28, 2018 04: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 lmiller1990/4067a8b2470f56e0bad96a055b1410c6 to your computer and use it in GitHub Desktop.
Save lmiller1990/4067a8b2470f56e0bad96a055b1410c6 to your computer and use it in GitHub Desktop.
require 'rails_helper'
describe Test::DatabasesController do
describe '/clean_database' do
it 'truncates and seeds the database' do
category = create(:category)
5.times { |i| create(:post, category: category) }
post :clean_database, params: { 'database': { 'should_seed': true } }
# Seed db/seeds/test for default seeds
# Default 2 categories and 1 post
expect(Post.count).to eq 1
expect(Category.count).to eq 2
end
it 'truncates and seeds the database' do
category = create(:category)
5.times { |i| create(:post, category: category) }
post :clean_database, params: { 'database': { 'should_seed': false } }
expect(Post.count).to eq 0
expect(Category.count).to eq 0
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment