Updated

spec/jobs / close_petitions_job_spec.rb

D
75 lines of codes
0 methods
N/A complexity/method
4 churn
154.9 complexity
164 duplications
require 'rails_helper' RSpec.describe ClosePetitionsJob, type: :job do context "for a petition opened in the winter" do
  1. Similar code found in 2 nodes Locations: 0 1
let!(:petition) { FactoryBot.create(:open_petition, open_at: "2015-12-29T10:00:00Z") } around do |example| travel_to(now) example.run travel_back end context "and the closing date has not passed" do let(:now) { "2016-06-28T07:00:00Z".in_time_zone } it "does not change the petition state" do
  1. context(for a petition opened in the winter)::context(and the closing date has not passed)::it#does not change the petition state has a flog score of 26
expect{ perform_enqueued_jobs { described_class.perform_later(Date.tomorrow.beginning_of_day.iso8601) } }.not_to change{ petition.reload.state } end end context "and the closing date has passed" do let(:now) { "2016-06-29T07:00:00Z".in_time_zone } it "does change the petition debate state" do
  1. context(for a petition opened in the winter)::context(and the closing date has passed)::it#does change the petition debate state has a flog score of 31
expect{ perform_enqueued_jobs { described_class.perform_later(Date.tomorrow.beginning_of_day.iso8601) } }.to change{ petition.reload.state }.from("open").to("closed") end end end context "for a petition opened in the summer" do
  1. Similar code found in 2 nodes Locations: 0 1
let!(:petition) { FactoryBot.create(:open_petition, open_at: "2016-06-29T10:00:00Z") } around do |example| travel_to(now) example.run travel_back end context "and the debate date has not passed" do let(:now) { "2016-12-28T07:00:00Z".in_time_zone } it "does not change the petition state" do
  1. context(for a petition opened in the summer)::context(and the debate date has not passed)::it#does not change the petition state has a flog score of 26
expect{ perform_enqueued_jobs { described_class.perform_later(Date.tomorrow.beginning_of_day.iso8601) } }.not_to change{ petition.reload.state } end end context "and the debate date has passed" do let(:now) { "2016-12-29T07:00:00Z".in_time_zone } it "does change the petition state" do
  1. context(for a petition opened in the summer)::context(and the debate date has passed)::it#does change the petition state has a flog score of 31
expect{ perform_enqueued_jobs { described_class.perform_later(Date.tomorrow.beginning_of_day.iso8601) } }.to change{ petition.reload.state }.from("open").to("closed") end end end end