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

82 lines
2 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 }
2014-10-06 04:42:03 -04:00
let(:slack_service) { SlackService.new }
2014-03-18 13:27:03 -04:00
let(:user) { create(:user) }
let(:project) { create(:project) }
let(:sample_data) { GitPushService.new.sample_data(project, user) }
2014-10-03 12:59:57 -04:00
let(:webhook) { 'https://gitlabhq.slack.com/services/hooks?token=cdIj4r4LfXUOySDUjp0tk3OI' }
2014-10-06 04:42:03 -04:00
let(:new_webhook) { 'https://hooks.gitlabhq.slack.com/services/cdIj4r4LfXUOySDUjp0tk3OI' }
2014-03-18 13:27:03 -04:00
let(:api_url) {
2014-10-03 12:59:57 -04:00
'https://gitlabhq.slack.com/services/hooks/incoming-webhook?token=cdIj4r4LfXUOySDUjp0tk3OI'
2014-03-18 13:27:03 -04:00
}
before do
slack.stub(
project: project,
project_id: project.id,
service_hook: true,
2014-10-03 12:59:57 -04:00
webhook: webhook
2014-03-18 13:27:03 -04:00
)
WebMock.stub_request(:post, api_url)
end
it "should call Slack API" do
slack.execute(sample_data)
WebMock.should have_requested(:post, api_url).once
end
2014-10-06 04:42:03 -04:00
context 'with new webhook syntax' do
before do
slack_service.stub(
project: project,
project_id: project.id,
service_hook: true,
webhook: new_webhook
)
WebMock.stub_request(:post, api_url)
end
it "should call Slack API" do
slack_service.execute(sample_data)
WebMock.should have_requested(:post, api_url).once
end
end
2014-03-18 13:27:03 -04:00
end
end