Updated

spec/jobs / debated_petitions_job_spec.rb

F
179 lines of codes
0 methods
N/A complexity/method
6 churn
330.17 complexity
364 duplications
require 'rails_helper' RSpec.describe DebatedPetitionsJob, type: :job do context "for a petition with a scheduled debate date in the winter" do
  1. Similar code found in 4 nodes Locations: 0 1 2 3
let(:petition) { FactoryBot.build(:open_petition, debate_state: "scheduled", scheduled_debate_date: "2015-12-29" ) } let(:open_at) { "2015-12-01T10:00:00Z".in_time_zone } before do travel_to(open_at) { petition.save } travel_to(now) end after do travel_back end context "and the debate date has not passed" do let(:now) { "2015-12-28T07:15:00Z".in_time_zone } it "does not change the petition debate state" do expect{ perform_enqueued_jobs { described_class.perform_later(Date.tomorrow.iso8601) } }.not_to change{ petition.reload.debate_state } end end context "and the debate date has passed" do let(:now) { "2015-12-29T07:15:00Z".in_time_zone } it "does change the petition debate state" do
  1. context(for a petition with a scheduled debate date in the winter)::context(and the debate date has passed)::it#does change the petition debate state has a flog score of 28
expect{ perform_enqueued_jobs { described_class.perform_later(Date.tomorrow.iso8601) } }.to change{ petition.reload.debate_state }.from("scheduled").to("debated") end end end context "for an archived petition with a scheduled debate date in the winter" do
  1. Similar code found in 4 nodes Locations: 0 1 2 3
let(:petition) { FactoryBot.build(:archived_petition, debate_state: "scheduled", scheduled_debate_date: "2015-12-29" ) } let(:opened_at) { "2015-12-01T10:00:00Z".in_time_zone } before do travel_to(opened_at) { petition.save } travel_to(now) end after do travel_back end context "and the debate date has not passed" do let(:now) { "2015-12-28T07:15:00Z".in_time_zone } it "does not change the petition debate state" do expect{ perform_enqueued_jobs { described_class.perform_later(Date.tomorrow.iso8601) } }.not_to change{ petition.reload.debate_state } end end context "and the debate date has passed" do let(:now) { "2015-12-29T07:15:00Z".in_time_zone } it "does change the petition debate state" do
  1. context(for an archived petition with a scheduled debate date in the winter)::context(and the debate date has passed)::it#does change the petition debate state has a flog score of 28
expect{ perform_enqueued_jobs { described_class.perform_later(Date.tomorrow.iso8601) } }.to change{ petition.reload.debate_state }.from("scheduled").to("debated") end end end context "for a petition with a scheduled debate date in the summer" do
  1. Similar code found in 4 nodes Locations: 0 1 2 3
let(:petition) { FactoryBot.build(:open_petition, debate_state: "scheduled", scheduled_debate_date: "2016-06-29" ) } let(:open_at) { "2016-06-01T10:00:00Z".in_time_zone } before do travel_to(open_at) { petition.save } travel_to(now) end after do travel_back end context "and the debate date has not passed" do let(:now) { "2016-06-28T07:15:00Z".in_time_zone } it "does not change the petition debate state" do expect{ perform_enqueued_jobs { described_class.perform_later(Date.tomorrow.iso8601) } }.not_to change{ petition.reload.debate_state } end end context "and the debate date has passed" do let(:now) { "2016-06-29T07:15:00Z".in_time_zone } it "does change the petition debate state" do
  1. context(for a petition with a scheduled debate date in the summer)::context(and the debate date has passed)::it#does change the petition debate state has a flog score of 28
expect{ perform_enqueued_jobs { described_class.perform_later(Date.tomorrow.iso8601) } }.to change{ petition.reload.debate_state }.from("scheduled").to("debated") end end end context "for an archived petition with a scheduled debate date in the summer" do
  1. Similar code found in 4 nodes Locations: 0 1 2 3
let(:petition) { FactoryBot.build(:archived_petition, debate_state: "scheduled", scheduled_debate_date: "2016-06-29" ) } let(:opened_at) { "2016-06-01T10:00:00Z".in_time_zone } before do travel_to(opened_at) { petition.save } travel_to(now) end after do travel_back end context "and the debate date has not passed" do let(:now) { "2016-06-28T07:15:00Z".in_time_zone } it "does not change the petition debate state" do expect{ perform_enqueued_jobs { described_class.perform_later(Date.tomorrow.iso8601) } }.not_to change{ petition.reload.debate_state } end end context "and the debate date has passed" do let(:now) { "2016-06-29T07:15:00Z".in_time_zone } it "does change the petition debate state" do
  1. context(for an archived petition with a scheduled debate date in the summer)::context(and the debate date has passed)::it#does change the petition debate state has a flog score of 28
expect{ perform_enqueued_jobs { described_class.perform_later(Date.tomorrow.iso8601) } }.to change{ petition.reload.debate_state }.from("scheduled").to("debated") end end end end