Only create records on tests using them

The test or the draft phase legislation filter was using an entirely
different set of records, but was still creating the records used in the
open and past filter as well.

This made it hard to test the filter, since it returned records from
both sets.

Grouping the past and open filters together guarantees their records
won't be created in the phase draft test, and so we can test the exact
contents of the array.
This commit is contained in:
Javi Martín
2019-09-26 19:26:52 +02:00
parent 44ffcfba2c
commit 9f0088396e

View File

@@ -96,19 +96,28 @@ describe Legislation::Process do
end end
describe "filter scopes" do describe "filter scopes" do
let!(:process_1) { create(:legislation_process, start_date: Date.current - 2.days, describe "open and past filters" do
end_date: Date.current + 1.day) } let!(:process_1) { create(:legislation_process, start_date: Date.current - 2.days,
let!(:process_2) { create(:legislation_process, start_date: Date.current + 1.day, end_date: Date.current + 1.day) }
end_date: Date.current + 3.days) } let!(:process_2) { create(:legislation_process, start_date: Date.current + 1.day,
let!(:process_3) { create(:legislation_process, start_date: Date.current - 4.days, end_date: Date.current + 3.days) }
end_date: Date.current - 3.days) } let!(:process_3) { create(:legislation_process, start_date: Date.current - 4.days,
end_date: Date.current - 3.days) }
it "filters open" do it "filters open" do
open_processes = ::Legislation::Process.open open_processes = ::Legislation::Process.open
expect(open_processes).to include(process_1) expect(open_processes).to eq [process_1]
expect(open_processes).not_to include(process_2) expect(open_processes).not_to include [process_2]
expect(open_processes).not_to include(process_3) end
it "filters past" do
past_processes = ::Legislation::Process.past
expect(past_processes).to include(process_3)
expect(past_processes).not_to include(process_2)
expect(past_processes).not_to include(process_1)
end
end end
it "filters draft phase" do it "filters draft phase" do
@@ -141,19 +150,11 @@ describe Legislation::Process do
processes_not_in_draft = ::Legislation::Process.not_in_draft processes_not_in_draft = ::Legislation::Process.not_in_draft
expect(processes_not_in_draft).to include(process_before_draft) expect(processes_not_in_draft).to match_array [process_before_draft, process_with_draft_disabled]
expect(processes_not_in_draft).to include(process_with_draft_disabled)
expect(processes_not_in_draft).not_to include(process_with_draft_enabled) expect(processes_not_in_draft).not_to include(process_with_draft_enabled)
expect(processes_not_in_draft).not_to include(process_with_draft_only_today) expect(processes_not_in_draft).not_to include(process_with_draft_only_today)
end end
it "filters past" do
past_processes = ::Legislation::Process.past
expect(past_processes).to include(process_3)
expect(past_processes).not_to include(process_2)
expect(past_processes).not_to include(process_1)
end
end end
describe "#status" do describe "#status" do