debian-mirror-gitlab/spec/models/integrations/flowdock_spec.rb

61 lines
1.5 KiB
Ruby
Raw Normal View History

2019-05-18 00:54:41 +05:30
# frozen_string_literal: true
2015-04-26 12:48:37 +05:30
require 'spec_helper'
2021-09-04 01:27:46 +05:30
RSpec.describe Integrations::Flowdock do
2015-04-26 12:48:37 +05:30
describe "Associations" do
it { is_expected.to belong_to :project }
it { is_expected.to have_one :service_hook }
end
2016-06-02 11:05:42 +05:30
describe 'Validations' do
context 'when service is active' do
2017-09-10 17:25:29 +05:30
before do
subject.active = true
end
2016-06-02 11:05:42 +05:30
it { is_expected.to validate_presence_of(:token) }
end
context 'when service is inactive' do
2017-09-10 17:25:29 +05:30
before do
subject.active = false
end
2016-06-02 11:05:42 +05:30
it { is_expected.not_to validate_presence_of(:token) }
end
end
2015-04-26 12:48:37 +05:30
describe "Execute" do
let(:user) { create(:user) }
2017-08-17 22:00:37 +05:30
let(:project) { create(:project, :repository) }
2021-09-04 01:27:46 +05:30
let(:sample_data) { Gitlab::DataBuilder::Push.build_sample(project, user) }
let(:api_url) { 'https://api.flowdock.com/v1/messages' }
subject(:flowdock_integration) { described_class.new }
2015-04-26 12:48:37 +05:30
before do
2021-09-04 01:27:46 +05:30
allow(flowdock_integration).to receive_messages(
2015-04-26 12:48:37 +05:30
project_id: project.id,
project: project,
service_hook: true,
token: 'verySecret'
)
2021-09-04 01:27:46 +05:30
WebMock.stub_request(:post, api_url)
2015-04-26 12:48:37 +05:30
end
2016-09-13 17:45:13 +05:30
it "calls FlowDock API" do
2021-09-04 01:27:46 +05:30
flowdock_integration.execute(sample_data)
sample_data[:commits].each do |commit|
2015-09-11 14:41:01 +05:30
# One request to Flowdock per new commit
2021-09-04 01:27:46 +05:30
next if commit[:id] == sample_data[:before]
2018-03-17 18:26:18 +05:30
2021-09-04 01:27:46 +05:30
expect(WebMock).to have_requested(:post, api_url).with(
2015-09-11 14:41:01 +05:30
body: /#{commit[:id]}.*#{project.path}/
).once
end
2015-04-26 12:48:37 +05:30
end
end
end