Rubocop spec/models/supporter_note_spec.rb

This commit is contained in:
Eric Schultz 2021-03-30 15:59:14 -05:00 committed by Eric Schultz
parent 83e7c33e45
commit 916fd18da5
2 changed files with 111 additions and 99 deletions

View file

@ -594,7 +594,6 @@ AllCops:
- 'spec/models/campaign_gift_purchase_spec.rb' - 'spec/models/campaign_gift_purchase_spec.rb'
- 'spec/models/custom_field_master_spec.rb' - 'spec/models/custom_field_master_spec.rb'
- 'spec/models/user_spec.rb' - 'spec/models/user_spec.rb'
- 'spec/models/supporter_note_spec.rb'
- 'spec/models/modern_campaign_gift_spec.rb' - 'spec/models/modern_campaign_gift_spec.rb'
- 'spec/models/import_request_spec.rb' - 'spec/models/import_request_spec.rb'
- 'spec/models/nonprofit_spec.rb' - 'spec/models/nonprofit_spec.rb'

View file

@ -3,110 +3,123 @@
# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later # 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 # Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
require 'rails_helper' require 'rails_helper'
# rubocop:disable RSpec/MessageSpies
# rubocop:disable RSpec/ExampleLength
# rubocop:disable RSpec/MultipleExpectations
RSpec.describe SupporterNote, type: :model do RSpec.describe SupporterNote, type: :model do
include_context :shared_donation_charge_context include_context :shared_donation_charge_context
let(:content) { "CONTENT"} let(:content) { 'CONTENT' }
let(:content2) {"CONTENT2"} 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 it 'creates' do
expect(supporter_note.errors).to be_empty expect(supporter_note.errors).to be_empty
end end
it 'announces created' do it 'announces created' do
expect(Houdini.event_publisher).to receive(:announce).with(:supporter_created, anything) 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_address_created, anything)
expect(Houdini.event_publisher).to receive(:announce).with(:supporter_note_created, { expect(Houdini.event_publisher).to receive(:announce).with(
'id' => match_houid('objevt'), :supporter_note_created,
'object' => 'object_event', {
'type' => 'supporter_note.created', 'id' => match_houid('objevt'),
'data' => { 'object' => 'object_event',
'object' => { 'type' => 'supporter_note.created',
'id'=> kind_of(Numeric), 'data' => {
'deleted' => false, 'object' => {
'content' => content, 'id' => kind_of(Numeric),
'nonprofit'=> { 'deleted' => false,
'id' => nonprofit.id, 'content' => content,
'name' => nonprofit.name, 'nonprofit' => {
'object' => 'nonprofit' 'id' => nonprofit.id,
}, 'name' => nonprofit.name,
'object' => 'supporter_note', 'object' => 'nonprofit'
'user' => { },
'id' => user.id, 'object' => 'supporter_note',
'object' => 'user' 'user' => {
}, 'id' => user.id,
'supporter' => supporter_to_builder_base.merge({'name' => "Fake Supporter Name"}) 'object' => 'user'
} },
} 'supporter' => supporter_to_builder_base.merge({ 'name' => 'Fake Supporter Name' })
}) }
}
}
)
supporter_note supporter_note
end end
it 'announces updated' do it 'announces updated' do
expect(Houdini.event_publisher).to receive(:announce).with(:supporter_created, anything) 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_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_created, anything).ordered
expect(Houdini.event_publisher).to receive(:announce).with(:supporter_note_updated, { expect(Houdini.event_publisher).to receive(:announce).with(
'id' => match_houid('objevt'), :supporter_note_updated,
'object' => 'object_event', {
'type' => 'supporter_note.updated', 'id' => match_houid('objevt'),
'data' => { 'object' => 'object_event',
'object' => { 'type' => 'supporter_note.updated',
'id'=> kind_of(Numeric), 'data' => {
'deleted' => false, 'object' => {
'content' => content2, 'id' => kind_of(Numeric),
'nonprofit'=> { 'deleted' => false,
'id' => nonprofit.id, 'content' => content2,
'name' => nonprofit.name, 'nonprofit' => {
'object' => 'nonprofit' 'id' => nonprofit.id,
}, 'name' => nonprofit.name,
'object' => 'supporter_note', 'object' => 'nonprofit'
'user' => { },
'id' => user.id, 'object' => 'supporter_note',
'object' => 'user' 'user' => {
}, 'id' => user.id,
'supporter' => supporter_to_builder_base.merge({'name' => "Fake Supporter Name"}) 'object' => 'user'
} },
} 'supporter' => supporter_to_builder_base.merge({ 'name' => 'Fake Supporter Name' })
}).ordered }
}
}
).ordered
supporter_note supporter_note
supporter_note.content = content2 supporter_note.content = content2
supporter_note.save! supporter_note.save!
end end
it 'announces deleted' do it 'announces deleted' do
expect(Houdini.event_publisher).to receive(:announce).with(:supporter_created, anything) allow(Houdini.event_publisher)
expect(Houdini.event_publisher).to receive(:announce).with(:supporter_address_created, anything) expect(Houdini.event_publisher).to receive(:announce).with(:supporter_created, anything)
expect(Houdini.event_publisher).to receive(:announce).with(:supporter_note_created, anything).ordered expect(Houdini.event_publisher).to receive(:announce).with(:supporter_address_created, anything)
expect(Houdini.event_publisher).to receive(:announce).with(:supporter_note_deleted, { expect(Houdini.event_publisher).to receive(:announce).with(:supporter_note_created, anything).ordered
'id' => match_houid('objevt'), expect(Houdini.event_publisher).to receive(:announce).with(
'object' => 'object_event', :supporter_note_deleted,
'type' => 'supporter_note.deleted', {
'data' => { 'id' => match_houid('objevt'),
'object' => { 'object' => 'object_event',
'id'=> kind_of(Numeric), 'type' => 'supporter_note.deleted',
'deleted' => true, 'data' => {
'content' => content, 'object' => {
'nonprofit'=> { 'id' => kind_of(Numeric),
'id' => nonprofit.id, 'deleted' => true,
'name' => nonprofit.name, 'content' => content,
'object' => 'nonprofit' 'nonprofit' => {
}, 'id' => nonprofit.id,
'object' => 'supporter_note', 'name' => nonprofit.name,
'user' => { 'object' => 'nonprofit'
'id' => user.id, },
'object' => 'user' 'object' => 'supporter_note',
}, 'user' => {
'supporter' => supporter_to_builder_base.merge({'name' => "Fake Supporter Name"}) 'id' => user.id,
} 'object' => 'user'
} },
}).ordered 'supporter' => supporter_to_builder_base.merge({ 'name' => 'Fake Supporter Name' })
}
}
}
).ordered
supporter_note.discard! supporter_note.discard!
end
end
end end
# rubocop:enable all