2014-09-02 18:07:02 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe EventCreateService do
|
|
|
|
let(:service) { described_class.new }
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
describe 'Issues' do
|
2016-08-24 12:49:21 +05:30
|
|
|
describe '#open_issue' do
|
2014-09-02 18:07:02 +05:30
|
|
|
let(:issue) { create(:issue) }
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it { expect(service.open_issue(issue, issue.author)).to be_truthy }
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it "creates new event" do
|
2014-09-02 18:07:02 +05:30
|
|
|
expect { service.open_issue(issue, issue.author) }.to change { Event.count }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
describe '#close_issue' do
|
2014-09-02 18:07:02 +05:30
|
|
|
let(:issue) { create(:issue) }
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it { expect(service.close_issue(issue, issue.author)).to be_truthy }
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it "creates new event" do
|
2014-09-02 18:07:02 +05:30
|
|
|
expect { service.close_issue(issue, issue.author) }.to change { Event.count }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
describe '#reopen_issue' do
|
2014-09-02 18:07:02 +05:30
|
|
|
let(:issue) { create(:issue) }
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it { expect(service.reopen_issue(issue, issue.author)).to be_truthy }
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it "creates new event" do
|
2014-09-02 18:07:02 +05:30
|
|
|
expect { service.reopen_issue(issue, issue.author) }.to change { Event.count }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'Merge Requests' do
|
2016-08-24 12:49:21 +05:30
|
|
|
describe '#open_mr' do
|
2014-09-02 18:07:02 +05:30
|
|
|
let(:merge_request) { create(:merge_request) }
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it { expect(service.open_mr(merge_request, merge_request.author)).to be_truthy }
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it "creates new event" do
|
2014-09-02 18:07:02 +05:30
|
|
|
expect { service.open_mr(merge_request, merge_request.author) }.to change { Event.count }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
describe '#close_mr' do
|
2014-09-02 18:07:02 +05:30
|
|
|
let(:merge_request) { create(:merge_request) }
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it { expect(service.close_mr(merge_request, merge_request.author)).to be_truthy }
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it "creates new event" do
|
2014-09-02 18:07:02 +05:30
|
|
|
expect { service.close_mr(merge_request, merge_request.author) }.to change { Event.count }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
describe '#merge_mr' do
|
2014-09-02 18:07:02 +05:30
|
|
|
let(:merge_request) { create(:merge_request) }
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it { expect(service.merge_mr(merge_request, merge_request.author)).to be_truthy }
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it "creates new event" do
|
2014-09-02 18:07:02 +05:30
|
|
|
expect { service.merge_mr(merge_request, merge_request.author) }.to change { Event.count }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
describe '#reopen_mr' do
|
2014-09-02 18:07:02 +05:30
|
|
|
let(:merge_request) { create(:merge_request) }
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it { expect(service.reopen_mr(merge_request, merge_request.author)).to be_truthy }
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it "creates new event" do
|
2014-09-02 18:07:02 +05:30
|
|
|
expect { service.reopen_mr(merge_request, merge_request.author) }.to change { Event.count }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'Milestone' do
|
|
|
|
let(:user) { create :user }
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
describe '#open_milestone' do
|
2014-09-02 18:07:02 +05:30
|
|
|
let(:milestone) { create(:milestone) }
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it { expect(service.open_milestone(milestone, user)).to be_truthy }
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it "creates new event" do
|
2014-09-02 18:07:02 +05:30
|
|
|
expect { service.open_milestone(milestone, user) }.to change { Event.count }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
describe '#close_mr' do
|
2014-09-02 18:07:02 +05:30
|
|
|
let(:milestone) { create(:milestone) }
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it { expect(service.close_milestone(milestone, user)).to be_truthy }
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it "creates new event" do
|
2014-09-02 18:07:02 +05:30
|
|
|
expect { service.close_milestone(milestone, user) }.to change { Event.count }
|
|
|
|
end
|
|
|
|
end
|
2015-09-25 12:07:36 +05:30
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
describe '#destroy_mr' do
|
2015-09-25 12:07:36 +05:30
|
|
|
let(:milestone) { create(:milestone) }
|
|
|
|
|
|
|
|
it { expect(service.destroy_milestone(milestone, user)).to be_truthy }
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it "creates new event" do
|
2015-09-25 12:07:36 +05:30
|
|
|
expect { service.destroy_milestone(milestone, user) }.to change { Event.count }
|
|
|
|
end
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe '#push', :clean_gitlab_redis_shared_state do
|
|
|
|
let(:project) { create(:project) }
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
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
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it 'creates a new event' do
|
2017-09-10 17:25:29 +05:30
|
|
|
expect { service.push(project, user, push_data) }.to change { Event.count }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates the push event payload' do
|
|
|
|
expect(PushEventPayloadService).to receive(:new)
|
|
|
|
.with(an_instance_of(PushEvent), push_data)
|
|
|
|
.and_call_original
|
|
|
|
|
|
|
|
service.push(project, user, push_data)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates user last activity' do
|
2017-09-10 17:25:29 +05:30
|
|
|
expect { service.push(project, user, push_data) }
|
2018-11-18 11:00:15 +05:30
|
|
|
.to change { user.last_activity_on }.to(Date.today)
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it 'caches the last push event for the user' do
|
|
|
|
expect_any_instance_of(Users::LastPushEventService)
|
|
|
|
.to receive(:cache_last_push_event)
|
|
|
|
.with(an_instance_of(PushEvent))
|
|
|
|
|
|
|
|
service.push(project, user, push_data)
|
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
it 'does not create any event data when an error is raised' do
|
|
|
|
payload_service = double(:service)
|
|
|
|
|
|
|
|
allow(payload_service).to receive(:execute)
|
|
|
|
.and_raise(RuntimeError)
|
|
|
|
|
|
|
|
allow(PushEventPayloadService).to receive(:new)
|
|
|
|
.and_return(payload_service)
|
|
|
|
|
|
|
|
expect { service.push(project, user, push_data) }
|
|
|
|
.to raise_error(RuntimeError)
|
|
|
|
|
|
|
|
expect(Event.count).to eq(0)
|
|
|
|
expect(PushEventPayload.count).to eq(0)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'Project' do
|
|
|
|
let(:user) { create :user }
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:project) { create(:project) }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
describe '#join_project' do
|
|
|
|
subject { service.join_project(project, user) }
|
|
|
|
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
it { expect { subject }.to change { Event.count }.from(0).to(1) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#expired_leave_project' do
|
|
|
|
subject { service.expired_leave_project(project, user) }
|
|
|
|
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
it { expect { subject }.to change { Event.count }.from(0).to(1) }
|
|
|
|
end
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|