Skip to content

Commit

Permalink
Router client no longer commits routes by default.
Browse files Browse the repository at this point in the history
This reverses the sense of the option parameter to allow optionally
requesting to commit as well.  This is a breaking change, and will be
released as a major version bump.

The reason for this is that everywhere we use this at the moment, we're
registering more than one route, and therefore using the skip_commit
option.  It therefore makes sense to make this behaviour the default.
  • Loading branch information
alext committed Jun 17, 2014
1 parent ab2090f commit f7a6f5e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
7 changes: 3 additions & 4 deletions lib/gds_api/router.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require_relative 'base'
#require_relative 'exceptions'

class GdsApi::Router < GdsApi::Base

Expand All @@ -25,20 +24,20 @@ def get_route(path, type)

def add_route(path, type, backend_id, options = {})
response = put_json!("#{endpoint}/routes", :route => {:incoming_path => path, :route_type => type, :handler => "backend", :backend_id => backend_id})
commit_routes unless options[:skip_commit]
commit_routes if options[:commit]
response
end

def add_redirect_route(path, type, destination, redirect_type = "permanent", options = {})
response = put_json!("#{endpoint}/routes", :route => {:incoming_path => path, :route_type => type, :handler => "redirect",
:redirect_to => destination, :redirect_type => redirect_type})
commit_routes unless options[:skip_commit]
commit_routes if options[:commit]
response
end

def delete_route(path, type, options = {})
response = delete_json!("#{endpoint}/routes?incoming_path=#{CGI.escape(path)}&route_type=#{CGI.escape(type)}")
commit_routes unless options[:skip_commit]
commit_routes if options[:commit]
response
end

Expand Down
26 changes: 13 additions & 13 deletions test/router_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,17 +199,17 @@
assert_equal "foo", response.backend_id

assert_requested(req)
assert_requested(@commit_req)
assert_not_requested(@commit_req)
end

it "should not commit the routes when asked not to" do
it "should commit the routes when asked to" do
req = WebMock.stub_request(:put, "#{@base_api_url}/routes").
to_return(:status => 201, :body => {}.to_json, :headers => {"Content-type" => "application/json"})

@api.add_route("/foo", "exact", "foo", :skip_commit => true)
@api.add_route("/foo", "exact", "foo", :commit => true)

assert_requested(req)
assert_not_requested(@commit_req)
assert_requested(@commit_req)
end

it "should raise an error if creating/updating the route fails" do
Expand Down Expand Up @@ -248,7 +248,7 @@
assert_equal "/bar", response.redirect_to

assert_requested(req)
assert_requested(@commit_req)
assert_not_requested(@commit_req)
end

it "should allow creating/updating a temporary redirect route" do
Expand All @@ -262,17 +262,17 @@
assert_equal "/bar", response.redirect_to

assert_requested(req)
assert_requested(@commit_req)
assert_not_requested(@commit_req)
end

it "should not commit the routes when asked not to" do
it "should commit the routes when asked to" do
req = WebMock.stub_request(:put, "#{@base_api_url}/routes").
to_return(:status => 201, :body =>{}.to_json, :headers => {"Content-type" => "application/json"})

@api.add_redirect_route("/foo", "exact", "/bar", "temporary", :skip_commit => true)
@api.add_redirect_route("/foo", "exact", "/bar", "temporary", :commit => true)

assert_requested(req)
assert_not_requested(@commit_req)
assert_requested(@commit_req)
end

it "should raise an error if creating/updating the redirect route fails" do
Expand Down Expand Up @@ -311,18 +311,18 @@
assert_equal "foo", response.backend_id

assert_requested(req)
assert_requested(@commit_req)
assert_not_requested(@commit_req)
end

it "should not commit the routes when asked not to" do
it "should commit the routes when asked to" do
req = WebMock.stub_request(:delete, "#{@base_api_url}/routes").
with(:query => {"incoming_path" => "/foo", "route_type" => "exact"}).
to_return(:status => 200, :body => {}.to_json, :headers => {"Content-type" => "application/json"})

@api.delete_route("/foo", "exact", :skip_commit => true)
@api.delete_route("/foo", "exact", :commit => true)

assert_requested(req)
assert_not_requested(@commit_req)
assert_requested(@commit_req)
end

it "should raise HTTPNotFound if nothing found" do
Expand Down

0 comments on commit f7a6f5e

Please sign in to comment.