From 9f0088396e259aa80656bed897a0fa2ce97ca29d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 26 Sep 2019 19:26:52 +0200 Subject: [PATCH] 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. --- spec/models/legislation/process_spec.rb | 41 +++++++++++++------------ 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/spec/models/legislation/process_spec.rb b/spec/models/legislation/process_spec.rb index 049ea8bf9..fdfa606f9 100644 --- a/spec/models/legislation/process_spec.rb +++ b/spec/models/legislation/process_spec.rb @@ -96,19 +96,28 @@ describe Legislation::Process do end describe "filter scopes" do - let!(:process_1) { create(:legislation_process, start_date: Date.current - 2.days, - end_date: Date.current + 1.day) } - let!(:process_2) { create(:legislation_process, start_date: Date.current + 1.day, - end_date: Date.current + 3.days) } - let!(:process_3) { create(:legislation_process, start_date: Date.current - 4.days, - end_date: Date.current - 3.days) } + describe "open and past filters" do + let!(:process_1) { create(:legislation_process, start_date: Date.current - 2.days, + end_date: Date.current + 1.day) } + let!(:process_2) { create(:legislation_process, start_date: Date.current + 1.day, + 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 - open_processes = ::Legislation::Process.open + it "filters open" do + open_processes = ::Legislation::Process.open - expect(open_processes).to include(process_1) - expect(open_processes).not_to include(process_2) - expect(open_processes).not_to include(process_3) + expect(open_processes).to eq [process_1] + expect(open_processes).not_to include [process_2] + 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 it "filters draft phase" do @@ -141,19 +150,11 @@ describe Legislation::Process do 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 include(process_with_draft_disabled) + expect(processes_not_in_draft).to match_array [process_before_draft, 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_only_today) 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 describe "#status" do