govuk-client-url_arbiter 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -36,7 +36,7 @@ module GOVUK
36
36
  def url_arbiter_has_registration_for(path, publishing_app)
37
37
  data = url_arbiter_data_for(path, "publishing_app" => publishing_app)
38
38
  error_data = data.merge({
39
- "errors" => {"base" => ["is already reserved by the #{publishing_app} application"]},
39
+ "errors" => {"path" => ["is already reserved by the #{publishing_app} application"]},
40
40
  })
41
41
 
42
42
  stub_request(:get, "#{URL_ARBITER_ENDPOINT}/paths#{path}").
@@ -50,6 +50,21 @@ module GOVUK
50
50
  to_return(:status => 200, :body => data.to_json, :headers => {:content_type => "application/json"})
51
51
  end
52
52
 
53
+ # Stub out call to simulate url-arbiter returning a validation error
54
+ # for a given path.
55
+ #
56
+ # @param path [String] The path being reserved
57
+ # @param error_details [Hash{String => Array<String>}] Error details to be
58
+ # returned in the stubbed response. If unspecified, a generic error
59
+ # message will be added.
60
+ def url_arbiter_returns_validation_error_for(path, error_details = nil)
61
+ error_details ||= {"base" => ["computer says no"]}
62
+ error_data = url_arbiter_data_for(path).merge("errors" => error_details)
63
+
64
+ stub_request(:put, "#{URL_ARBITER_ENDPOINT}/paths#{path}").
65
+ to_return(:status => 422, :body => error_data.to_json, :headers => {:content_type => "application/json"})
66
+ end
67
+
53
68
  # Generate sample url-arbiter data for a given path.
54
69
  #
55
70
  # @param path [String] The path being requested
@@ -1,7 +1,7 @@
1
1
  module GOVUK
2
2
  module Client
3
3
  class URLArbiter
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.2"
5
5
  end
6
6
  end
7
7
  end
@@ -23,6 +23,7 @@ module GOVUK
23
23
  # @param path [String] the path to fetch
24
24
  # @return [Response, nil] Details of the reserved path, or +nil+ if the path wasn't found.
25
25
  def path(path)
26
+ check_path(path)
26
27
  get_json("/paths#{path}")
27
28
  end
28
29
 
@@ -34,11 +35,18 @@ module GOVUK
34
35
  # @raise [Errors::Conflict] if the path is already reserved by another app.
35
36
  # @raise [Errors::UnprocessableEntity] for any validation errors.
36
37
  def reserve_path(path, details)
38
+ check_path(path)
37
39
  put_json!("/paths#{path}", details)
38
40
  end
39
41
 
40
42
  private
41
43
 
44
+ def check_path(path)
45
+ unless path && path.start_with?("/")
46
+ raise ArgumentError, "Path must start with a '/'"
47
+ end
48
+ end
49
+
42
50
  def get_json(path)
43
51
  response = RestClient.get(@base_url.merge(path).to_s)
44
52
  Response.new(response.code, response.body)
@@ -19,6 +19,24 @@ describe GOVUK::Client::URLArbiter do
19
19
  expect(response).to eq(data)
20
20
  end
21
21
 
22
+ it "should raise an error if the path is nil" do
23
+ expect {
24
+ response = client.path(nil)
25
+ }.to raise_error(ArgumentError)
26
+ end
27
+
28
+ it "should raise an error if the path is empty" do
29
+ expect {
30
+ response = client.path("")
31
+ }.to raise_error(ArgumentError)
32
+ end
33
+
34
+ it "should raise an error if the path doesn't start with a slash" do
35
+ expect {
36
+ response = client.path("bacon")
37
+ }.to raise_error(ArgumentError)
38
+ end
39
+
22
40
  it "should return nil on 404" do
23
41
  stub_request(:get, "#{base_url}/paths/foo/bar").
24
42
  to_return(:status => 404)
@@ -67,6 +85,24 @@ describe GOVUK::Client::URLArbiter do
67
85
  expect(response).to eq(data)
68
86
  end
69
87
 
88
+ it "should raise an error if the path is nil" do
89
+ expect {
90
+ response = client.reserve_path(nil, {})
91
+ }.to raise_error(ArgumentError)
92
+ end
93
+
94
+ it "should raise an error if the path is empty" do
95
+ expect {
96
+ response = client.reserve_path("", {})
97
+ }.to raise_error(ArgumentError)
98
+ end
99
+
100
+ it "should raise an error if the path doesn't start with a slash" do
101
+ expect {
102
+ response = client.reserve_path("bacon", {})
103
+ }.to raise_error(ArgumentError)
104
+ end
105
+
70
106
  it "should raise a conflict error if the path is already reserved" do
71
107
  data = url_arbiter_data_for("/foo/bar").merge({
72
108
  "errors" => {"base" => ["is already reserved by the 'bar_publisher' app"]},
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk-client-url_arbiter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-09-03 00:00:00.000000000 Z
12
+ date: 2014-09-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -162,7 +162,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
162
162
  version: '0'
163
163
  segments:
164
164
  - 0
165
- hash: 1429177817123946626
165
+ hash: 3700616753026108825
166
166
  required_rubygems_version: !ruby/object:Gem::Requirement
167
167
  none: false
168
168
  requirements:
@@ -171,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
171
  version: '0'
172
172
  segments:
173
173
  - 0
174
- hash: 1429177817123946626
174
+ hash: 3700616753026108825
175
175
  requirements: []
176
176
  rubyforge_project:
177
177
  rubygems_version: 1.8.23.2