slack_service_spec.rb 1.32 KB
Newer Older
1 2 3 4
# == Schema Information
#
# Table name: services
#
Valery Sizov's avatar
Valery Sizov committed
5 6 7 8 9 10 11 12
#  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
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#

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

Marin Jankovski's avatar
Marin Jankovski committed
29
      it { should validate_presence_of :webhook }
30 31 32 33
    end
  end

  describe "Execute" do
34 35
    let(:slack)   { SlackService.new }
    let(:user)    { create(:user) }
36
    let(:project) { create(:project) }
37
    let(:sample_data) { Gitlab::PushDataBuilder.build_sample(project, user) }
38
    let(:webhook_url) { 'https://hooks.slack.com/services/SVRWFV0VVAR97N/B02R25XN3/ZBqu7xMupaEEICInN685' }
39 40 41 42 43 44

    before do
      slack.stub(
        project: project,
        project_id: project.id,
        service_hook: true,
45
        webhook: webhook_url
46 47
      )

48
      WebMock.stub_request(:post, webhook_url)
49 50 51 52 53
    end

    it "should call Slack API" do
      slack.execute(sample_data)

54
      WebMock.should have_requested(:post, webhook_url).once
55
    end
56 57
  end
end