diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/gitlab_net_spec.rb | 26 | ||||
-rw-r--r-- | spec/vcr_cassettes/pre-receive-not-found.yml | 42 | ||||
-rw-r--r-- | spec/vcr_cassettes/pre-receive.yml | 46 |
3 files changed, 114 insertions, 0 deletions
diff --git a/spec/gitlab_net_spec.rb b/spec/gitlab_net_spec.rb index cbcef90..c22540b 100644 --- a/spec/gitlab_net_spec.rb +++ b/spec/gitlab_net_spec.rb @@ -126,6 +126,32 @@ describe GitlabNet, vcr: true do end end + describe :pre_receive do + let(:gl_repository) { "project-1" } + let(:params) { { gl_repository: gl_repository } } + + subject { gitlab_net.pre_receive(gl_repository) } + + it 'sends the correct parameters and returns the request body parsed' do + Net::HTTP::Post.any_instance.should_receive(:set_form_data) + .with(hash_including(params)) + + VCR.use_cassette("pre-receive") { subject } + end + + it 'calls /internal/pre-receive' do + VCR.use_cassette("pre-receive") do + expect(subject['reference_counter_increased']).to be(true) + end + end + + it 'throws a NotFound error when pre-receive is not available' do + VCR.use_cassette("pre-receive-not-found") do + expect { subject }.to raise_error(GitlabNet::NotFound) + end + end + end + describe :post_receive do let(:gl_repository) { "project-1" } let(:changes) { "123456 789012 refs/heads/test\n654321 210987 refs/tags/tag" } diff --git a/spec/vcr_cassettes/pre-receive-not-found.yml b/spec/vcr_cassettes/pre-receive-not-found.yml new file mode 100644 index 0000000..5eed672 --- /dev/null +++ b/spec/vcr_cassettes/pre-receive-not-found.yml @@ -0,0 +1,42 @@ +--- +http_interactions: +- request: + method: post + uri: http://localhost:3000/api/v4/internal/pre_receive + body: + encoding: US-ASCII + string: gl_repository=project-1&secret_token=0a3938d9d95d807e94d937af3a4fbbea%0A + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + Content-Type: + - application/x-www-form-urlencoded + response: + status: + code: 404 + message: Not Found + headers: + Cache-Control: + - no-cache + Content-Length: + - '25' + Content-Type: + - application/json + Date: + - Thu, 31 Aug 2017 16:41:13 GMT + Vary: + - Origin + X-Request-Id: + - 0b845e9a-5417-488d-bc5a-07d8c585b2da + X-Runtime: + - '0.295361' + body: + encoding: UTF-8 + string: '{"error":"404 Not Found"}' + http_version: + recorded_at: Thu, 31 Aug 2017 16:41:13 GMT +recorded_with: VCR 2.4.0 diff --git a/spec/vcr_cassettes/pre-receive.yml b/spec/vcr_cassettes/pre-receive.yml new file mode 100644 index 0000000..6072d0c --- /dev/null +++ b/spec/vcr_cassettes/pre-receive.yml @@ -0,0 +1,46 @@ +--- +http_interactions: +- request: + method: post + uri: http://localhost:3000/api/v4/internal/pre_receive + body: + encoding: US-ASCII + string: gl_repository=project-1&secret_token=0a3938d9d95d807e94d937af3a4fbbea%0A + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + Content-Type: + - application/x-www-form-urlencoded + response: + status: + code: 200 + message: OK + headers: + Cache-Control: + - max-age=0, private, must-revalidate + Content-Length: + - '36' + Content-Type: + - application/json + Date: + - Thu, 31 Aug 2017 20:17:41 GMT + Etag: + - W/"7d4df85c493bd3d421351aa791a8fbf6" + Vary: + - Origin + X-Frame-Options: + - SAMEORIGIN + X-Request-Id: + - f0c84103-8dc0-48ea-a142-62554f6bca3d + X-Runtime: + - '0.612997' + body: + encoding: UTF-8 + string: '{"reference_counter_increased":true}' + http_version: + recorded_at: Thu, 31 Aug 2017 20:17:41 GMT +recorded_with: VCR 2.4.0 |