Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/services/event_create_service_spec.rb')
-rw-r--r--spec/services/event_create_service_spec.rb78
1 files changed, 49 insertions, 29 deletions
diff --git a/spec/services/event_create_service_spec.rb b/spec/services/event_create_service_spec.rb
index 9f2c3fec62c..eb738ac80b1 100644
--- a/spec/services/event_create_service_spec.rb
+++ b/spec/services/event_create_service_spec.rb
@@ -113,40 +113,21 @@ describe EventCreateService do
end
end
- describe '#push', :clean_gitlab_redis_shared_state do
- let(:project) { create(:project) }
- let(:user) { create(:user) }
-
- let(:push_data) do
- {
- commits: [
- {
- id: '1cf19a015df3523caf0a1f9d40c98a267d6a2fc2',
- message: 'This is a commit'
- }
- ],
- before: '0000000000000000000000000000000000000000',
- after: '1cf19a015df3523caf0a1f9d40c98a267d6a2fc2',
- total_commits_count: 1,
- ref: 'refs/heads/my-branch'
- }
- end
-
+ shared_examples_for 'service for creating a push event' do |service_class|
it 'creates a new event' do
- expect { service.push(project, user, push_data) }.to change { Event.count }
+ expect { subject }.to change { Event.count }
end
it 'creates the push event payload' do
- expect(PushEventPayloadService).to receive(:new)
+ expect(service_class).to receive(:new)
.with(an_instance_of(PushEvent), push_data)
.and_call_original
- service.push(project, user, push_data)
+ subject
end
it 'updates user last activity' do
- expect { service.push(project, user, push_data) }
- .to change { user.last_activity_on }.to(Date.today)
+ expect { subject }.to change { user.last_activity_on }.to(Date.today)
end
it 'caches the last push event for the user' do
@@ -154,7 +135,7 @@ describe EventCreateService do
.to receive(:cache_last_push_event)
.with(an_instance_of(PushEvent))
- service.push(project, user, push_data)
+ subject
end
it 'does not create any event data when an error is raised' do
@@ -163,17 +144,56 @@ describe EventCreateService do
allow(payload_service).to receive(:execute)
.and_raise(RuntimeError)
- allow(PushEventPayloadService).to receive(:new)
+ allow(service_class).to receive(:new)
.and_return(payload_service)
- expect { service.push(project, user, push_data) }
- .to raise_error(RuntimeError)
-
+ expect { subject }.to raise_error(RuntimeError)
expect(Event.count).to eq(0)
expect(PushEventPayload.count).to eq(0)
end
end
+ describe '#push', :clean_gitlab_redis_shared_state do
+ let(:project) { create(:project) }
+ let(:user) { create(:user) }
+
+ let(:push_data) do
+ {
+ commits: [
+ {
+ id: '1cf19a015df3523caf0a1f9d40c98a267d6a2fc2',
+ message: 'This is a commit'
+ }
+ ],
+ before: '0000000000000000000000000000000000000000',
+ after: '1cf19a015df3523caf0a1f9d40c98a267d6a2fc2',
+ total_commits_count: 1,
+ ref: 'refs/heads/my-branch'
+ }
+ end
+
+ subject { service.push(project, user, push_data) }
+
+ it_behaves_like 'service for creating a push event', PushEventPayloadService
+ end
+
+ describe '#bulk_push', :clean_gitlab_redis_shared_state do
+ let(:project) { create(:project) }
+ let(:user) { create(:user) }
+
+ let(:push_data) do
+ {
+ action: :created,
+ ref_count: 4,
+ ref_type: :branch
+ }
+ end
+
+ subject { service.bulk_push(project, user, push_data) }
+
+ it_behaves_like 'service for creating a push event', BulkPushEventPayloadService
+ end
+
describe 'Project' do
let(:user) { create :user }
let(:project) { create(:project) }