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.
This commit is contained in:
Marko Lovic
2018-08-01 17:53:33 +02:00
committed by Javi Martín
parent 3291b3274a
commit 0c5f801c19

View File

@@ -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)