2019-04-11 08:17:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-12-07 12:41:30 -05:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe MergeRequestMetricsService do
|
|
|
|
let(:metrics) { create(:merge_request).metrics }
|
|
|
|
|
|
|
|
describe '#merge' do
|
|
|
|
it 'updates metrics' do
|
|
|
|
user = create(:user)
|
|
|
|
service = described_class.new(metrics)
|
|
|
|
event = double(Event, author_id: user.id, created_at: Time.now)
|
|
|
|
|
|
|
|
service.merge(event)
|
|
|
|
|
|
|
|
expect(metrics.merged_by).to eq(user)
|
2018-06-27 12:25:25 -04:00
|
|
|
expect(metrics.merged_at).to be_like_time(event.created_at)
|
2017-12-07 12:41:30 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#close' do
|
|
|
|
it 'updates metrics' do
|
|
|
|
user = create(:user)
|
|
|
|
service = described_class.new(metrics)
|
|
|
|
event = double(Event, author_id: user.id, created_at: Time.now)
|
|
|
|
|
|
|
|
service.close(event)
|
|
|
|
|
|
|
|
expect(metrics.latest_closed_by).to eq(user)
|
2018-06-27 12:25:25 -04:00
|
|
|
expect(metrics.latest_closed_at).to be_like_time(event.created_at)
|
2017-12-07 12:41:30 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#reopen' do
|
|
|
|
it 'updates metrics' do
|
|
|
|
service = described_class.new(metrics)
|
|
|
|
|
|
|
|
service.reopen
|
|
|
|
|
|
|
|
expect(metrics.latest_closed_by).to be_nil
|
|
|
|
expect(metrics.latest_closed_at).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|