From 916fd18da585bf52787d5cfac0c707bd1853426c Mon Sep 17 00:00:00 2001 From: Eric Schultz Date: Tue, 30 Mar 2021 15:59:14 -0500 Subject: [PATCH] Rubocop spec/models/supporter_note_spec.rb --- .rubocop.yml | 1 - spec/models/supporter_note_spec.rb | 209 +++++++++++++++-------------- 2 files changed, 111 insertions(+), 99 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 458968d6..1c97c093 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -594,7 +594,6 @@ AllCops: - 'spec/models/campaign_gift_purchase_spec.rb' - 'spec/models/custom_field_master_spec.rb' - 'spec/models/user_spec.rb' - - 'spec/models/supporter_note_spec.rb' - 'spec/models/modern_campaign_gift_spec.rb' - 'spec/models/import_request_spec.rb' - 'spec/models/nonprofit_spec.rb' diff --git a/spec/models/supporter_note_spec.rb b/spec/models/supporter_note_spec.rb index 13d91322..368cd674 100644 --- a/spec/models/supporter_note_spec.rb +++ b/spec/models/supporter_note_spec.rb @@ -3,110 +3,123 @@ # License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later # Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE require 'rails_helper' - +# rubocop:disable RSpec/MessageSpies +# rubocop:disable RSpec/ExampleLength +# rubocop:disable RSpec/MultipleExpectations RSpec.describe SupporterNote, type: :model do - include_context :shared_donation_charge_context - let(:content) { "CONTENT"} - let(:content2) {"CONTENT2"} + include_context :shared_donation_charge_context + let(:content) { 'CONTENT' } + let(:content2) { 'CONTENT2' } - let(:supporter_note) { supporter.supporter_notes.create(content: content, user: user) } + let(:supporter_note) { supporter.supporter_notes.create(content: content, user: user) } - it 'creates' do - expect(supporter_note.errors).to be_empty - end + it 'creates' do + expect(supporter_note.errors).to be_empty + end - it 'announces created' do - expect(Houdini.event_publisher).to receive(:announce).with(:supporter_created, anything) - expect(Houdini.event_publisher).to receive(:announce).with(:supporter_address_created, anything) - expect(Houdini.event_publisher).to receive(:announce).with(:supporter_note_created, { - 'id' => match_houid('objevt'), - 'object' => 'object_event', - 'type' => 'supporter_note.created', - 'data' => { - 'object' => { - 'id'=> kind_of(Numeric), - 'deleted' => false, - 'content' => content, - 'nonprofit'=> { - 'id' => nonprofit.id, - 'name' => nonprofit.name, - 'object' => 'nonprofit' - }, - 'object' => 'supporter_note', - 'user' => { - 'id' => user.id, - 'object' => 'user' - }, - 'supporter' => supporter_to_builder_base.merge({'name' => "Fake Supporter Name"}) - } - } - }) + it 'announces created' do + expect(Houdini.event_publisher).to receive(:announce).with(:supporter_created, anything) + expect(Houdini.event_publisher).to receive(:announce).with(:supporter_address_created, anything) + expect(Houdini.event_publisher).to receive(:announce).with( + :supporter_note_created, + { + 'id' => match_houid('objevt'), + 'object' => 'object_event', + 'type' => 'supporter_note.created', + 'data' => { + 'object' => { + 'id' => kind_of(Numeric), + 'deleted' => false, + 'content' => content, + 'nonprofit' => { + 'id' => nonprofit.id, + 'name' => nonprofit.name, + 'object' => 'nonprofit' + }, + 'object' => 'supporter_note', + 'user' => { + 'id' => user.id, + 'object' => 'user' + }, + 'supporter' => supporter_to_builder_base.merge({ 'name' => 'Fake Supporter Name' }) + } + } + } + ) - supporter_note - end + supporter_note + end - it 'announces updated' do - expect(Houdini.event_publisher).to receive(:announce).with(:supporter_created, anything) - expect(Houdini.event_publisher).to receive(:announce).with(:supporter_address_created, anything) - expect(Houdini.event_publisher).to receive(:announce).with(:supporter_note_created, anything).ordered - expect(Houdini.event_publisher).to receive(:announce).with(:supporter_note_updated, { - 'id' => match_houid('objevt'), - 'object' => 'object_event', - 'type' => 'supporter_note.updated', - 'data' => { - 'object' => { - 'id'=> kind_of(Numeric), - 'deleted' => false, - 'content' => content2, - 'nonprofit'=> { - 'id' => nonprofit.id, - 'name' => nonprofit.name, - 'object' => 'nonprofit' - }, - 'object' => 'supporter_note', - 'user' => { - 'id' => user.id, - 'object' => 'user' - }, - 'supporter' => supporter_to_builder_base.merge({'name' => "Fake Supporter Name"}) - } - } - }).ordered + it 'announces updated' do + expect(Houdini.event_publisher).to receive(:announce).with(:supporter_created, anything) + expect(Houdini.event_publisher).to receive(:announce).with(:supporter_address_created, anything) + expect(Houdini.event_publisher).to receive(:announce).with(:supporter_note_created, anything).ordered + expect(Houdini.event_publisher).to receive(:announce).with( + :supporter_note_updated, + { + 'id' => match_houid('objevt'), + 'object' => 'object_event', + 'type' => 'supporter_note.updated', + 'data' => { + 'object' => { + 'id' => kind_of(Numeric), + 'deleted' => false, + 'content' => content2, + 'nonprofit' => { + 'id' => nonprofit.id, + 'name' => nonprofit.name, + 'object' => 'nonprofit' + }, + 'object' => 'supporter_note', + 'user' => { + 'id' => user.id, + 'object' => 'user' + }, + 'supporter' => supporter_to_builder_base.merge({ 'name' => 'Fake Supporter Name' }) + } + } + } + ).ordered - supporter_note - supporter_note.content = content2 - supporter_note.save! - end - - it 'announces deleted' do - expect(Houdini.event_publisher).to receive(:announce).with(:supporter_created, anything) - expect(Houdini.event_publisher).to receive(:announce).with(:supporter_address_created, anything) - expect(Houdini.event_publisher).to receive(:announce).with(:supporter_note_created, anything).ordered - expect(Houdini.event_publisher).to receive(:announce).with(:supporter_note_deleted, { - 'id' => match_houid('objevt'), - 'object' => 'object_event', - 'type' => 'supporter_note.deleted', - 'data' => { - 'object' => { - 'id'=> kind_of(Numeric), - 'deleted' => true, - 'content' => content, - 'nonprofit'=> { - 'id' => nonprofit.id, - 'name' => nonprofit.name, - 'object' => 'nonprofit' - }, - 'object' => 'supporter_note', - 'user' => { - 'id' => user.id, - 'object' => 'user' - }, - 'supporter' => supporter_to_builder_base.merge({'name' => "Fake Supporter Name"}) - } - } - }).ordered - - supporter_note.discard! + supporter_note + supporter_note.content = content2 + supporter_note.save! + end - end + it 'announces deleted' do + allow(Houdini.event_publisher) + expect(Houdini.event_publisher).to receive(:announce).with(:supporter_created, anything) + expect(Houdini.event_publisher).to receive(:announce).with(:supporter_address_created, anything) + expect(Houdini.event_publisher).to receive(:announce).with(:supporter_note_created, anything).ordered + expect(Houdini.event_publisher).to receive(:announce).with( + :supporter_note_deleted, + { + 'id' => match_houid('objevt'), + 'object' => 'object_event', + 'type' => 'supporter_note.deleted', + 'data' => { + 'object' => { + 'id' => kind_of(Numeric), + 'deleted' => true, + 'content' => content, + 'nonprofit' => { + 'id' => nonprofit.id, + 'name' => nonprofit.name, + 'object' => 'nonprofit' + }, + 'object' => 'supporter_note', + 'user' => { + 'id' => user.id, + 'object' => 'user' + }, + 'supporter' => supporter_to_builder_base.merge({ 'name' => 'Fake Supporter Name' }) + } + } + } + ).ordered + + supporter_note.discard! + end end + +# rubocop:enable all