travis-api/spec/integration/v2/hooks_spec.rb
Piotr Sarnacki c6e3c29a57 Load the data for integration tests upfront
We can do it, because we use :transaction strategy with DatabaseCleaner,
which starts transaction before each test and rollbacks after it. That
way data before each test is consistent.

The big advantage of such approach is that tests are fast now - we need
to only load Scenario data once.

One of the drawbacks, on the other hand, is that we need to always load
this data, even if no integration tests need running.

We can try to be smart about it and check if any integration tests are
loaded.
2013-01-26 00:00:42 +01:00

45 lines
1.5 KiB
Ruby

require 'spec_helper'
require 'travis/testing/payloads'
describe 'Hooks' do
before(:each) do
user.permissions.create repository: repo, admin: true
end
let(:user) { User.where(login: 'svenfuchs').first }
let(:repo) { Repository.first }
let(:token) { Travis::Api::App::AccessToken.create(user: user, app_id: -1) }
let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.2+json', 'HTTP_AUTHORIZATION' => "token #{token}" } }
it 'GET /hooks' do
response = get '/hooks', {}, headers
response.should deliver_json_for(user.service_hooks, version: 'v2', type: 'hooks')
end
describe 'PUT /hooks' do # TODO really should be /hooks/1
let(:hook) { user.service_hooks.first }
let(:target) { "repos/#{hook.owner_name}/#{hook.name}/hooks" }
let :payload do
{
:name => 'travis',
:events => Travis::Github::Services::SetHook::EVENTS,
:active => true,
:config => { :user => user.login, :token => user.tokens.first.token, :domain => 'listener.travis-ci.org' }
}
end
before(:each) do
Travis.config.stubs(:service_hook_url).returns('listener.travis-ci.org')
end
it 'sets the hook' do
GH.stubs(:[]).returns([])
GH.expects(:post).with(target, payload).returns(GH.load(PAYLOADS[:github][:hook_active]))
response = put 'hooks', { hook: { id: hook.id, active: 'true' } }, headers
repo.reload.active?.should be_true
response.should be_successful
end
end
end