diff options
Diffstat (limited to 'spec/support/shared_examples/models/resource_event_shared_examples.rb')
-rw-r--r-- | spec/support/shared_examples/models/resource_event_shared_examples.rb | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/spec/support/shared_examples/models/resource_event_shared_examples.rb b/spec/support/shared_examples/models/resource_event_shared_examples.rb index 038ff33c68a..1409f7caea8 100644 --- a/spec/support/shared_examples/models/resource_event_shared_examples.rb +++ b/spec/support/shared_examples/models/resource_event_shared_examples.rb @@ -10,6 +10,8 @@ RSpec.shared_examples 'a resource event' do let_it_be(:issue2) { create(:issue, author: user1) } let_it_be(:issue3) { create(:issue, author: user2) } + let(:resource_event) { described_class.name.demodulize.underscore.to_sym } + describe 'importable' do it { is_expected.to respond_to(:importing?) } it { is_expected.to respond_to(:imported?) } @@ -36,9 +38,9 @@ RSpec.shared_examples 'a resource event' do let!(:created_at2) { 2.days.ago } let!(:created_at3) { 3.days.ago } - let!(:event1) { create(described_class.name.underscore.to_sym, issue: issue1, created_at: created_at1) } - let!(:event2) { create(described_class.name.underscore.to_sym, issue: issue2, created_at: created_at2) } - let!(:event3) { create(described_class.name.underscore.to_sym, issue: issue2, created_at: created_at3) } + let!(:event1) { create(resource_event, issue: issue1, created_at: created_at1) } + let!(:event2) { create(resource_event, issue: issue2, created_at: created_at2) } + let!(:event3) { create(resource_event, issue: issue2, created_at: created_at3) } it 'returns the expected events' do events = described_class.created_after(created_at3) @@ -62,9 +64,10 @@ RSpec.shared_examples 'a resource event for issues' do let_it_be(:issue2) { create(:issue, author: user1) } let_it_be(:issue3) { create(:issue, author: user2) } - let_it_be(:event1) { create(described_class.name.underscore.to_sym, issue: issue1) } - let_it_be(:event2) { create(described_class.name.underscore.to_sym, issue: issue2) } - let_it_be(:event3) { create(described_class.name.underscore.to_sym, issue: issue1) } + let_it_be(:resource_event) { described_class.name.demodulize.underscore.to_sym } + let_it_be(:event1) { create(resource_event, issue: issue1) } + let_it_be(:event2) { create(resource_event, issue: issue2) } + let_it_be(:event3) { create(resource_event, issue: issue1) } describe 'associations' do it { is_expected.to belong_to(:issue) } @@ -93,9 +96,9 @@ RSpec.shared_examples 'a resource event for issues' do end describe '.by_created_at_earlier_or_equal_to' do - let_it_be(:event1) { create(described_class.name.underscore.to_sym, issue: issue1, created_at: '2020-03-10') } - let_it_be(:event2) { create(described_class.name.underscore.to_sym, issue: issue2, created_at: '2020-03-10') } - let_it_be(:event3) { create(described_class.name.underscore.to_sym, issue: issue1, created_at: '2020-03-12') } + let_it_be(:event1) { create(resource_event, issue: issue1, created_at: '2020-03-10') } + let_it_be(:event2) { create(resource_event, issue: issue2, created_at: '2020-03-10') } + let_it_be(:event3) { create(resource_event, issue: issue1, created_at: '2020-03-12') } it 'returns the expected events' do events = described_class.by_created_at_earlier_or_equal_to('2020-03-11 23:59:59') @@ -112,7 +115,7 @@ RSpec.shared_examples 'a resource event for issues' do if described_class.method_defined?(:issuable) describe '#issuable' do - let_it_be(:event1) { create(described_class.name.underscore.to_sym, issue: issue2) } + let_it_be(:event1) { create(resource_event, issue: issue2) } it 'returns the expected issuable' do expect(event1.issuable).to eq(issue2) @@ -125,6 +128,7 @@ RSpec.shared_examples 'a resource event for merge requests' do let_it_be(:user1) { create(:user) } let_it_be(:user2) { create(:user) } + let_it_be(:resource_event) { described_class.name.demodulize.underscore.to_sym } let_it_be(:merge_request1) { create(:merge_request, author: user1) } let_it_be(:merge_request2) { create(:merge_request, author: user1) } let_it_be(:merge_request3) { create(:merge_request, author: user2) } @@ -134,9 +138,9 @@ RSpec.shared_examples 'a resource event for merge requests' do end describe '.by_merge_request' do - let_it_be(:event1) { create(described_class.name.underscore.to_sym, merge_request: merge_request1) } - let_it_be(:event2) { create(described_class.name.underscore.to_sym, merge_request: merge_request2) } - let_it_be(:event3) { create(described_class.name.underscore.to_sym, merge_request: merge_request1) } + let_it_be(:event1) { create(resource_event, merge_request: merge_request1) } + let_it_be(:event2) { create(resource_event, merge_request: merge_request2) } + let_it_be(:event3) { create(resource_event, merge_request: merge_request1) } it 'returns the expected records for an issue with events' do events = described_class.by_merge_request(merge_request1) @@ -153,7 +157,7 @@ RSpec.shared_examples 'a resource event for merge requests' do if described_class.method_defined?(:issuable) describe '#issuable' do - let_it_be(:event1) { create(described_class.name.underscore.to_sym, merge_request: merge_request2) } + let_it_be(:event1) { create(resource_event, merge_request: merge_request2) } it 'returns the expected issuable' do expect(event1.issuable).to eq(merge_request2) @@ -163,7 +167,7 @@ RSpec.shared_examples 'a resource event for merge requests' do context 'on callbacks' do it 'does not trigger note created subscription' do - event = build(described_class.name.underscore.to_sym, merge_request: merge_request1) + event = build(resource_event, merge_request: merge_request1) expect(GraphqlTriggers).not_to receive(:work_item_note_created) expect(event).not_to receive(:trigger_note_subscription_create) @@ -177,15 +181,17 @@ RSpec.shared_examples 'a note for work item resource event' do let_it_be(:project) { create(:project) } let_it_be(:work_item) { create(:work_item, :task, project: project, author: user) } + let(:resource_event) { described_class.name.demodulize.underscore.to_sym } + it 'builds synthetic note with correct synthetic_note_class' do - event = build(described_class.name.underscore.to_sym, issue: work_item) + event = build(resource_event, issue: work_item) expect(event.work_item_synthetic_system_note.class.name).to eq(event.synthetic_note_class.name) end context 'on callbacks' do it 'triggers note created subscription' do - event = build(described_class.name.underscore.to_sym, issue: work_item) + event = build(resource_event, issue: work_item) expect(GraphqlTriggers).to receive(:work_item_note_created) expect(event).to receive(:trigger_note_subscription_create).and_call_original |