update_merge_requests_worker_spec.rb 1.07 KB
Newer Older
1 2 3 4 5
require 'spec_helper'

describe UpdateMergeRequestsWorker do
  include RepoHelpers

6
  let(:project) { create(:project, :repository) }
7 8 9 10 11 12 13 14 15 16 17 18 19 20
  let(:user) { create(:user) }

  subject { described_class.new }

  describe '#perform' do
    let(:oldrev) { "123456" }
    let(:newrev) { "789012" }
    let(:ref)    { "refs/heads/test" }

    def perform
      subject.perform(project.id, user.id, oldrev, newrev, ref)
    end

    it 'executes MergeRequests::RefreshService with expected values' do
21 22 23
      expect_next_instance_of(MergeRequests::RefreshService, project, user) do |refresh_service|
        expect(refresh_service).to receive(:execute).with(oldrev, newrev, ref)
      end
24 25 26

      perform
    end
27

28 29 30 31
    context 'when slow' do
      before do
        stub_const("UpdateMergeRequestsWorker::LOG_TIME_THRESHOLD", -1)
      end
32

33 34 35 36 37
      it 'logs debug info' do
        expect(Rails.logger).to receive(:info).with(a_string_matching(/\AUpdateMergeRequestsWorker#perform.*project_id=#{project.id},user_id=#{user.id},oldrev=#{oldrev},newrev=#{newrev},ref=#{ref}/))

        perform
      end
38
    end
39 40
  end
end