summaryrefslogtreecommitdiff
path: root/spec/models
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/event_collection_spec.rb81
-rw-r--r--spec/models/event_spec.rb21
-rw-r--r--spec/models/release_spec.rb10
-rw-r--r--spec/models/releases/evidence_spec.rb (renamed from spec/models/evidence_spec.rb)2
4 files changed, 93 insertions, 21 deletions
diff --git a/spec/models/event_collection_spec.rb b/spec/models/event_collection_spec.rb
index e6f80a4c4d0..6d1954700bf 100644
--- a/spec/models/event_collection_spec.rb
+++ b/spec/models/event_collection_spec.rb
@@ -8,22 +8,68 @@ describe EventCollection do
let_it_be(:project) { create(:project_empty_repo, group: group) }
let_it_be(:projects) { Project.where(id: project.id) }
let_it_be(:user) { create(:user) }
+ let_it_be(:merge_request) { create(:merge_request) }
context 'with project events' do
- before do
- 20.times do
- event = create(:push_event, project: project, author: user)
-
- create(:push_event_payload, event: event)
+ let_it_be(:push_event_payloads) do
+ Array.new(9) do
+ create(:push_event_payload,
+ event: create(:push_event, project: project, author: user))
end
-
- create(:closed_issue_event, project: project, author: user)
end
- it 'returns an Array of events' do
+ let_it_be(:merge_request_events) { create_list(:event, 10, :commented, project: project, target: merge_request) }
+ let_it_be(:closed_issue_event) { create(:closed_issue_event, project: project, author: user) }
+ let_it_be(:wiki_page_event) { create(:wiki_page_event, project: project) }
+ let(:push_events) { push_event_payloads.map(&:event) }
+
+ it 'returns an Array of events', :aggregate_failures do
+ most_recent_20_events = [
+ wiki_page_event,
+ closed_issue_event,
+ *push_events,
+ *merge_request_events
+ ].sort_by(&:id).reverse.take(20)
events = described_class.new(projects).to_a
expect(events).to be_an_instance_of(Array)
+ expect(events).to match_array(most_recent_20_events)
+ end
+
+ context 'the wiki_events feature flag is disabled' do
+ before do
+ stub_feature_flags(wiki_events: false)
+ end
+
+ it 'omits the wiki page events when using to_a' do
+ events = described_class.new(projects).to_a
+
+ expect(events).not_to include(wiki_page_event)
+ end
+
+ it 'omits the wiki page events when using all_project_events' do
+ events = described_class.new(projects).all_project_events
+
+ expect(events).not_to include(wiki_page_event)
+ end
+ end
+
+ context 'the wiki_events feature flag is enabled' do
+ before do
+ stub_feature_flags(wiki_events: true)
+ end
+
+ it 'includes the wiki page events when using to_a' do
+ events = described_class.new(projects).to_a
+
+ expect(events).to include(wiki_page_event)
+ end
+
+ it 'includes the wiki page events when using all_project_events' do
+ events = described_class.new(projects).all_project_events
+
+ expect(events).to include(wiki_page_event)
+ end
end
it 'applies a limit to the number of events' do
@@ -44,12 +90,25 @@ describe EventCollection do
expect(events).to be_empty
end
- it 'allows filtering of events using an EventFilter' do
+ it 'allows filtering of events using an EventFilter, returning single item' do
filter = EventFilter.new(EventFilter::ISSUE)
events = described_class.new(projects, filter: filter).to_a
- expect(events.length).to eq(1)
- expect(events[0].action).to eq(Event::CLOSED)
+ expect(events).to contain_exactly(closed_issue_event)
+ end
+
+ it 'allows filtering of events using an EventFilter, returning several items' do
+ filter = EventFilter.new(EventFilter::COMMENTS)
+ events = described_class.new(projects, filter: filter).to_a
+
+ expect(events).to match_array(merge_request_events)
+ end
+
+ it 'allows filtering of events using an EventFilter, returning pushes' do
+ filter = EventFilter.new(EventFilter::PUSH)
+ events = described_class.new(projects, filter: filter).to_a
+
+ expect(events).to match_array(push_events)
end
end
diff --git a/spec/models/event_spec.rb b/spec/models/event_spec.rb
index b2676a79b55..3239c7a843a 100644
--- a/spec/models/event_spec.rb
+++ b/spec/models/event_spec.rb
@@ -454,9 +454,10 @@ describe Event do
end
end
- describe '.for_wiki_page' do
+ describe 'wiki_page predicate scopes' do
let_it_be(:events) do
[
+ create(:push_event),
create(:closed_issue_event),
create(:wiki_page_event),
create(:closed_issue_event),
@@ -465,10 +466,22 @@ describe Event do
]
end
- it 'only contains the wiki page events' do
- wiki_events = events.select(&:wiki_page?)
+ describe '.for_wiki_page' do
+ it 'only contains the wiki page events' do
+ wiki_events = events.select(&:wiki_page?)
- expect(described_class.for_wiki_page).to match_array(wiki_events)
+ expect(events).not_to match_array(wiki_events)
+ expect(described_class.for_wiki_page).to match_array(wiki_events)
+ end
+ end
+
+ describe '.not_wiki_page' do
+ it 'does not contain the wiki page events' do
+ non_wiki_events = events.reject(&:wiki_page?)
+
+ expect(events).not_to match_array(non_wiki_events)
+ expect(described_class.not_wiki_page).to match_array(non_wiki_events)
+ end
end
end
diff --git a/spec/models/release_spec.rb b/spec/models/release_spec.rb
index 3884b8138be..8b1b738ab58 100644
--- a/spec/models/release_spec.rb
+++ b/spec/models/release_spec.rb
@@ -15,7 +15,7 @@ RSpec.describe Release do
it { is_expected.to have_many(:links).class_name('Releases::Link') }
it { is_expected.to have_many(:milestones) }
it { is_expected.to have_many(:milestone_releases) }
- it { is_expected.to have_one(:evidence) }
+ it { is_expected.to have_many(:evidences).class_name('Releases::Evidence') }
end
describe 'validation' do
@@ -97,7 +97,7 @@ RSpec.describe Release do
describe '#create_evidence!' do
context 'when a release is created' do
it 'creates one Evidence object too' do
- expect { release_with_evidence }.to change(Evidence, :count).by(1)
+ expect { release_with_evidence }.to change(Releases::Evidence, :count).by(1)
end
end
end
@@ -106,7 +106,7 @@ RSpec.describe Release do
it 'also deletes the associated evidence' do
release_with_evidence
- expect { release_with_evidence.destroy }.to change(Evidence, :count).by(-1)
+ expect { release_with_evidence.destroy }.to change(Releases::Evidence, :count).by(-1)
end
end
end
@@ -155,7 +155,7 @@ RSpec.describe Release do
context 'when a release was created with evidence collection' do
let!(:release) { create(:release, :with_evidence) }
- it { is_expected.to eq(release.evidence.summary_sha) }
+ it { is_expected.to eq(release.evidences.first.summary_sha) }
end
end
@@ -171,7 +171,7 @@ RSpec.describe Release do
context 'when a release was created with evidence collection' do
let!(:release) { create(:release, :with_evidence) }
- it { is_expected.to eq(release.evidence.summary) }
+ it { is_expected.to eq(release.evidences.first.summary) }
end
end
diff --git a/spec/models/evidence_spec.rb b/spec/models/releases/evidence_spec.rb
index 8f534517fc1..d38d2021117 100644
--- a/spec/models/evidence_spec.rb
+++ b/spec/models/releases/evidence_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Evidence do
+describe Releases::Evidence do
let_it_be(:project) { create(:project) }
let(:release) { create(:release, project: project) }
let(:schema_file) { 'evidences/evidence' }