diff options
-rw-r--r-- | spec/controllers/api_controller_spec.rb | 9 | ||||
-rw-r--r-- | spec/fixtures/public_bodies.yml | 6 |
2 files changed, 11 insertions, 4 deletions
diff --git a/spec/controllers/api_controller_spec.rb b/spec/controllers/api_controller_spec.rb index 91d113dac..dec652361 100644 --- a/spec/controllers/api_controller_spec.rb +++ b/spec/controllers/api_controller_spec.rb @@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe ApiController, "when using the API" do it "should create a new request from a POST" do geraldine = public_bodies(:geraldine_public_body) - number_of_requests = InfoRequest.count(:conditions = ["public_body_id = ?", geraldine.id]) + number_of_requests = InfoRequest.count(:conditions => ["public_body_id = ?", geraldine.id]) request_data = { "title" => "Tell me about your chickens", @@ -15,12 +15,13 @@ describe ApiController, "when using the API" do post :create_request, :k => geraldine.api_key, :request_json => request_data.to_json response.should be_success - response.headers["Content-Type"].should == "application/json" + + response.content_type.should == "application/json" - response_body = response.body.from_json + response_body = ActiveSupport::JSON.decode(response.body) response_body["url"].should =~ /^http/ - InfoRequest.count(:conditions = ["public_body_id = ?", geraldine.id]).should == number_of_requests + 1 + InfoRequest.count(:conditions => ["public_body_id = ?", geraldine.id]).should == number_of_requests + 1 new_request = InfoRequest.find(response_body["id"]) new_request.user_id.should be_nil diff --git a/spec/fixtures/public_bodies.yml b/spec/fixtures/public_bodies.yml index a0893f1e5..367e0fc50 100644 --- a/spec/fixtures/public_bodies.yml +++ b/spec/fixtures/public_bodies.yml @@ -10,6 +10,7 @@ geraldine_public_body: short_name: TGQ url_name: tgq created_at: 2007-10-24 10:51:01.161639 + api_key: 1 humpadink_public_body: name: "Department for Humpadinking" first_letter: D @@ -23,6 +24,7 @@ humpadink_public_body: url_name: dfh created_at: 2007-10-25 10:51:01.161639 notes: An albatross told me!!! + api_key: 2 forlorn_public_body: name: "Department of Loneliness" first_letter: D @@ -36,6 +38,7 @@ forlorn_public_body: url_name: lonely created_at: 2011-01-26 14:11:02.12345 notes: A very lonely public body that no one has corresponded with + api_key: 3 silly_walks_public_body: id: 5 version: 1 @@ -49,6 +52,7 @@ silly_walks_public_body: url_name: msw created_at: 2007-10-25 10:51:01.161639 notes: You know the one. + api_key: 4 sensible_walks_public_body: id: 6 version: 1 @@ -62,3 +66,5 @@ sensible_walks_public_body: last_edit_comment: Another stunning innovation from your friendly national government last_edit_editor: robin created_at: 2008-10-25 10:51:01.161639 + api_key: 5 + |