gds-api-adapters 7.3.0 → 7.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -64,8 +64,8 @@ module GdsApi
64
64
  # Define "safe" methods for each supported HTTP method
65
65
  #
66
66
  # Each "bang method" tries to make a request, but raises an exception if
67
- # the response is not successful. These methods discard those exceptions
68
- # and return nil.
67
+ # the response is not successful. These methods discard the HTTPNotFound
68
+ # exceptions (and return nil), and pass through all other exceptions.
69
69
  [:get, :post, :put, :delete].each do |http_method|
70
70
  method_name = "#{http_method}_json"
71
71
  define_method method_name do |url, *args, &block|
@@ -2,7 +2,11 @@ require_relative 'base'
2
2
 
3
3
  class GdsApi::Support < GdsApi::Base
4
4
  def create_foi_request(request_details)
5
- post_json("#{base_url}/foi_requests", { :foi_request => request_details })
5
+ post_json!("#{base_url}/foi_requests", { :foi_request => request_details })
6
+ end
7
+
8
+ def create_problem_report(request_details)
9
+ post_json!("#{base_url}/problem_reports", { :problem_report => request_details })
6
10
  end
7
11
 
8
12
  private
@@ -4,10 +4,14 @@ module GdsApi
4
4
  SUPPORT_ENDPOINT = Plek.current.find('support')
5
5
 
6
6
  def stub_support_foi_request_creation(request_details = nil)
7
- body_expectation = {"foi_request" => request_details}.to_json
7
+ post_stub = stub_http_request(:post, "#{SUPPORT_ENDPOINT}/foi_requests")
8
+ post_stub.with(:body => {"foi_request" => request_details}) unless request_details.nil?
9
+ post_stub.to_return(:status => 201)
10
+ end
8
11
 
9
- post_stub = stub_request(:post, "#{SUPPORT_ENDPOINT}/foi_requests")
10
- post_stub.with(:body => {"foi_request" => request_details}.to_json) unless request_details.nil?
12
+ def stub_support_problem_report_creation(request_details = nil)
13
+ post_stub = stub_http_request(:post, "#{SUPPORT_ENDPOINT}/problem_reports")
14
+ post_stub.with(:body => { problem_report: request_details }) unless request_details.nil?
11
15
  post_stub.to_return(:status => 201)
12
16
  end
13
17
 
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = '7.3.0'
2
+ VERSION = '7.4.0'
3
3
  end
@@ -1,13 +1,16 @@
1
1
  require 'test_helper'
2
2
  require 'gds_api/support'
3
+ require 'gds_api/test_helpers/support'
3
4
 
4
5
  describe GdsApi::Support do
6
+ include GdsApi::TestHelpers::Support
7
+
5
8
  before do
6
9
  @base_api_url = Plek.current.find("support")
7
10
  @api = GdsApi::Support.new(@base_api_url)
8
11
  end
9
12
 
10
- it "can create an asset with a file" do
13
+ it "can create an FOI request" do
11
14
  request_details = {"foi_request"=>{"requester"=>{"name"=>"A", "email"=>"a@b.com"}, "details"=>"abc"}}
12
15
 
13
16
  stub_post = stub_request(:post, "#{@base_api_url}/foi_requests").
@@ -18,4 +21,28 @@ describe GdsApi::Support do
18
21
 
19
22
  assert_requested(stub_post)
20
23
  end
24
+
25
+ it "throws an exception when the support app isn't available" do
26
+ support_isnt_available
27
+
28
+ assert_raises(GdsApi::HTTPErrorResponse) { @api.create_foi_request({}) }
29
+ end
30
+
31
+ it "can report a problem" do
32
+ request_details = {certain: "details"}
33
+
34
+ stub_post = stub_request(:post, "#{@base_api_url}/problem_reports").
35
+ with(:body => {"problem_report" => request_details}.to_json).
36
+ to_return(:status => 201)
37
+
38
+ @api.create_problem_report(request_details)
39
+
40
+ assert_requested(stub_post)
41
+ end
42
+
43
+ it "throws an exception when the support app isn't available" do
44
+ support_isnt_available
45
+
46
+ assert_raises(GdsApi::HTTPErrorResponse) { @api.create_problem_report({}) }
47
+ end
21
48
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: gds-api-adapters
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 7.3.0
5
+ version: 7.4.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - James Stewart
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2013-08-12 00:00:00 Z
13
+ date: 2013-08-21 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: plek
@@ -260,7 +260,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
260
260
  requirements:
261
261
  - - ">="
262
262
  - !ruby/object:Gem::Version
263
- hash: -933955563815808271
263
+ hash: 167124885650140799
264
264
  segments:
265
265
  - 0
266
266
  version: "0"
@@ -269,7 +269,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
269
269
  requirements:
270
270
  - - ">="
271
271
  - !ruby/object:Gem::Version
272
- hash: -933955563815808271
272
+ hash: 167124885650140799
273
273
  segments:
274
274
  - 0
275
275
  version: "0"