diff options
Diffstat (limited to 'spec/models/event_spec.rb')
-rw-r--r-- | spec/models/event_spec.rb | 53 |
1 files changed, 46 insertions, 7 deletions
diff --git a/spec/models/event_spec.rb b/spec/models/event_spec.rb index 4c2d44a3e12..6430fc2ffc8 100644 --- a/spec/models/event_spec.rb +++ b/spec/models/event_spec.rb @@ -115,6 +115,18 @@ RSpec.describe Event, feature_category: :user_profile do end end + describe '.for_merge_request' do + let(:mr_event) { create(:event, :for_merge_request, project: project) } + + before do + create(:event, :for_issue, project: project) + end + + it 'returns events for MergeRequest target_type' do + expect(described_class.for_merge_request).to contain_exactly(mr_event) + end + end + describe '.created_at' do it 'can find the right event' do time = 1.day.ago @@ -128,6 +140,21 @@ RSpec.describe Event, feature_category: :user_profile do end end + describe '.created_between' do + it 'returns events created between given timestamps' do + start_time = 2.days.ago + end_time = Date.today + + create(:event, created_at: 3.days.ago) + e1 = create(:event, created_at: 2.days.ago) + e2 = create(:event, created_at: 1.day.ago) + + found = described_class.created_between(start_time, end_time) + + expect(found).to contain_exactly(e1, e2) + end + end + describe '.for_fingerprint' do let_it_be(:with_fingerprint) { create(:event, fingerprint: 'aaa', project: project) } @@ -152,16 +179,28 @@ RSpec.describe Event, feature_category: :user_profile do end describe '.contributions' do - let!(:merge_request_event) { create(:event, :created, :for_merge_request, project: project) } - let!(:issue_event) { create(:event, :created, :for_issue, project: project) } + let!(:merge_request_events) do + %i[created closed merged approved].map do |action| + create(:event, :for_merge_request, action: action, project: project) + end + end + let!(:work_item_event) { create(:event, :created, :for_work_item, project: project) } - let!(:design_event) { create(:design_event, project: project) } + let!(:issue_events) do + %i[created closed].map { |action| create(:event, :for_issue, action: action, project: project) } + end + + let!(:push_event) { create_push_event(project, project.owner) } + let!(:comment_event) { create(:event, :commented, project: project) } + + before do + create(:design_event, project: project) # should not be in scope + end - it 'returns events for MergeRequest, Issue and WorkItem' do + it 'returns events for MergeRequest, Issue, WorkItem and push, comment events' do expect(described_class.contributions).to contain_exactly( - merge_request_event, - issue_event, - work_item_event + *merge_request_events, *issue_events, work_item_event, + push_event, comment_event ) end end |