Updated

spec/jobs / deliver_petition_email_job_spec.rb

D
50 lines of codes
0 methods
N/A complexity/method
3 churn
107.95 complexity
139 duplications
require 'rails_helper' require_relative 'shared_examples' RSpec.describe DeliverPetitionEmailJob, type: :job do let(:requested_at) { Time.current.change(usec: 0) }
  1. Similar code found in 2 nodes Locations: 0 1
let(:requested_at_as_string) { requested_at.getutc.iso8601(6) } let(:petition) { FactoryBot.create(:debated_petition) } let(:signature) { FactoryBot.create(:validated_signature, petition: petition) } let(:email) { FactoryBot.create(:petition_email, petition: petition) } let(:timestamp_name) { 'petition_email' } let :arguments do { signature: signature, timestamp_name: timestamp_name, petition: petition, requested_at: requested_at_as_string, email: email } end before do petition.set_email_requested_at_for(timestamp_name, to: requested_at) end it_behaves_like "a job to send an signatory email" context "when the signature is the creator" do before do allow(signature).to receive(:creator?).and_return(true) end it "uses the correct mailer method to generate the email" do
  1. context(when the signature is the creator)::it#uses the correct mailer method to generate the email has a flog score of 27
expect(subject).to receive_message_chain(:mailer, :email_creator).with(petition, signature, email).and_return double.as_null_object subject.perform(**arguments) end end context "when the signature is not the creator" do before do allow(signature).to receive(:creator?).and_return(false) end it "uses the correct mailer method to generate the email" do
  1. context(when the signature is not the creator)::it#uses the correct mailer method to generate the email has a flog score of 27
expect(subject).to receive_message_chain(:mailer, :email_signer).with(petition, signature, email).and_return double.as_null_object subject.perform(**arguments) end end end