gitlab-org--gitlab-foss/spec/models/slack_service_spec.rb

58 lines
1.3 KiB
Ruby
Raw Normal View History

2014-03-18 13:27:03 -04:00
# == Schema Information
#
# Table name: services
#
2014-10-09 11:22:20 -04:00
# id :integer not null, primary key
# type :string(255)
# title :string(255)
# project_id :integer not null
# created_at :datetime
# updated_at :datetime
# active :boolean default(FALSE), not null
# properties :text
2014-03-18 13:27:03 -04:00
#
require 'spec_helper'
describe SlackService do
describe "Associations" do
it { should belong_to :project }
it { should have_one :service_hook }
end
describe "Validations" do
context "active" do
before do
subject.active = true
end
2014-10-03 12:59:57 -04:00
it { should validate_presence_of :webhook }
2014-03-18 13:27:03 -04:00
end
end
describe "Execute" do
let(:slack) { SlackService.new }
let(:user) { create(:user) }
2014-03-18 13:27:03 -04:00
let(:project) { create(:project) }
2015-01-12 12:08:25 -05:00
let(:sample_data) { Gitlab::PushDataBuilder.build_sample(project, user) }
let(:webhook_url) { 'https://hooks.slack.com/services/SVRWFV0VVAR97N/B02R25XN3/ZBqu7xMupaEEICInN685' }
2014-03-18 13:27:03 -04:00
before do
slack.stub(
project: project,
project_id: project.id,
service_hook: true,
webhook: webhook_url
2014-03-18 13:27:03 -04:00
)
WebMock.stub_request(:post, webhook_url)
2014-03-18 13:27:03 -04:00
end
it "should call Slack API" do
slack.execute(sample_data)
WebMock.should have_requested(:post, webhook_url).once
end
2014-03-18 13:27:03 -04:00
end
end