gitlabhq/spec/models/web_hook_spec.rb

66 lines
1.8 KiB
Ruby
Raw Normal View History

require 'spec_helper'
2012-07-15 16:36:06 +02:00
describe ProjectHook do
describe "Associations" do
it { should belong_to :project }
end
describe "Validations" do
it { should validate_presence_of(:url) }
context "url format" do
it { should allow_value("http://example.com").for(:url) }
it { should allow_value("https://excample.com").for(:url) }
it { should allow_value("http://test.com/api").for(:url) }
it { should allow_value("http://test.com/api?key=abc").for(:url) }
it { should allow_value("http://test.com/api?key=abc&type=def").for(:url) }
it { should_not allow_value("example.com").for(:url) }
it { should_not allow_value("ftp://example.com").for(:url) }
it { should_not allow_value("herp-and-derp").for(:url) }
end
end
describe "execute" do
before(:each) do
2012-07-15 16:36:06 +02:00
@project_hook = Factory :project_hook
@project = Factory :project
2012-07-15 16:36:06 +02:00
@project.hooks << [@project_hook]
@data = { before: 'oldrev', after: 'newrev', ref: 'ref'}
2012-07-15 16:36:06 +02:00
WebMock.stub_request(:post, @project_hook.url)
end
it "POSTs to the web hook URL" do
2012-07-15 16:36:06 +02:00
@project_hook.execute(@data)
WebMock.should have_requested(:post, @project_hook.url).once
end
it "POSTs the data as JSON" do
json = @data.to_json
2012-07-15 16:36:06 +02:00
@project_hook.execute(@data)
WebMock.should have_requested(:post, @project_hook.url).with(body: json).once
end
it "catches exceptions" do
WebHook.should_receive(:post).and_raise("Some HTTP Post error")
lambda {
2012-07-15 16:36:06 +02:00
@project_hook.execute(@data)
}.should raise_error
end
end
end
2012-01-03 22:39:03 +01:00
# == Schema Information
#
# Table name: web_hooks
#
2012-06-26 20:23:09 +02:00
# id :integer(4) not null, primary key
2012-01-03 22:39:03 +01:00
# url :string(255)
2012-06-26 20:23:09 +02:00
# project_id :integer(4)
# created_at :datetime not null
# updated_at :datetime not null
2012-01-03 22:39:03 +01:00
#