From 0c5f801c19fc14c4cb6aa9e76ac902c6179913a2 Mon Sep 17 00:00:00 2001 From: Marko Lovic Date: Wed, 1 Aug 2018 17:53:33 +0200 Subject: [PATCH] Keep DB clean after running budget stats spec This spec was leaving the DB "dirty" because it was creating records in a before(:all) hook. These records are not cleaned up automatically when using the :transaction strategy for DatabaseCleaner. Using before(:each), however, causes another problem. Some of the code depends on the heading id being 1 (see app/models/budget/ballot/line.rb#L48). Because of SQL auto-increment, this is only the case the first time the hook is run, as different id's are assigned on subsequent runs. This is fixed by forcing the id to always be 1. --- spec/models/budget/stats_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/budget/stats_spec.rb b/spec/models/budget/stats_spec.rb index 9a12e7269..ba5e642bb 100644 --- a/spec/models/budget/stats_spec.rb +++ b/spec/models/budget/stats_spec.rb @@ -2,7 +2,7 @@ require "rails_helper" describe Budget::Stats do - before(:all) do + before(:each) do @budget = create(:budget) @group = create(:budget_group, budget: @budget) @heading = create(:budget_heading, group: @group, price: 1000)