|
| 1 | +# encoding: utf-8 |
| 2 | + |
| 3 | +require 'spec_helper' |
| 4 | + |
| 5 | +describe Github::Client::Orgs::Hooks, '#edit' do |
| 6 | + let(:org) { 'API-sampler' } |
| 7 | + let(:hook_id) { 1 } |
| 8 | + let(:request_path) {"/orgs/#{org}/hooks/#{hook_id}" } |
| 9 | + let(:inputs) { |
| 10 | + { |
| 11 | + :name => 'web', |
| 12 | + :config => { |
| 13 | + :url => "http://something.com/webhook", |
| 14 | + :content_type => "json" |
| 15 | + }, |
| 16 | + :active => true |
| 17 | + } |
| 18 | + } |
| 19 | + |
| 20 | + before { |
| 21 | + stub_patch(request_path).with(inputs.except(:unrelated)). |
| 22 | + to_return(:body => body, :status => status, |
| 23 | + :headers => {:content_type => "application/json; charset=utf-8"}) |
| 24 | + } |
| 25 | + |
| 26 | + after { reset_authentication_for(subject) } |
| 27 | + |
| 28 | + context "resource edited successfully" do |
| 29 | + let(:body) { fixture("orgs/hook.json") } |
| 30 | + let(:status) { 200 } |
| 31 | + |
| 32 | + it "should fail to edit without 'org' parameter" do |
| 33 | + expect { subject.edit }.to raise_error(ArgumentError) |
| 34 | + end |
| 35 | + |
| 36 | + it "should fail to edit resource without 'name' parameter" do |
| 37 | + expect{ |
| 38 | + subject.edit org, hook_id, inputs.except(:name) |
| 39 | + }.to raise_error(Github::Error::RequiredParams) |
| 40 | + end |
| 41 | + |
| 42 | + it "should fail to edit resource without 'hook_id'" do |
| 43 | + expect { subject.edit org }.to raise_error(ArgumentError) |
| 44 | + end |
| 45 | + |
| 46 | + it "should fail to edit resource without 'config' parameter" do |
| 47 | + expect { |
| 48 | + subject.edit org, hook_id, inputs.except(:config) |
| 49 | + }.to raise_error(Github::Error::RequiredParams) |
| 50 | + end |
| 51 | + |
| 52 | + it "should edit the resource" do |
| 53 | + subject.edit org, hook_id, inputs |
| 54 | + a_patch(request_path).with(inputs).should have_been_made |
| 55 | + end |
| 56 | + |
| 57 | + it "should return resource" do |
| 58 | + hook = subject.edit org, hook_id, inputs |
| 59 | + hook.should be_a Github::ResponseWrapper |
| 60 | + end |
| 61 | + |
| 62 | + it "should be able to retrieve information" do |
| 63 | + hook = subject.edit org, hook_id, inputs |
| 64 | + hook.name.should == 'web' |
| 65 | + end |
| 66 | + end |
| 67 | + |
| 68 | + it_should_behave_like 'request failure' do |
| 69 | + let(:requestable) { subject.edit org, hook_id, inputs } |
| 70 | + end |
| 71 | +end # edit |
0 commit comments