Skip to content

Commit

Permalink
add test to ensure seed is idempotent
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienpoly committed Oct 19, 2023
1 parent a121a87 commit 1f6b223
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,4 @@
end

# reindex all talk in MeiliSearch
Talk.reindex!
Talk.reindex! unless Rails.env.test?
22 changes: 22 additions & 0 deletions test/tasks/db_seed_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require "test_helper"

class DbSeedTest < ActiveSupport::TestCase
setup do
@event = events(:one)
Rails.application.load_tasks
Rake::Task["db:environment:set"].reenable
Rake::Task["db:schema:load"].invoke
end

test "db:seed runs successfully" do
assert_nothing_raised do
Rake::Task["db:seed"].invoke
end

# Ensuring idempotency
assert_no_difference "Talk.maximum(:created_at)" do
Rake::Task["db:seed"].reenable
Rake::Task["db:seed"].invoke
end
end
end

0 comments on commit 1f6b223

Please sign in to comment.