diff options
| author | Robin Houston <robin.houston@gmail.com> | 2012-05-24 13:25:53 +0100 | 
|---|---|---|
| committer | Robin Houston <robin.houston@gmail.com> | 2012-06-06 19:34:57 +0100 | 
| commit | 8263c7a92c8ef4313a65dc6bfd75b6eca1250ebc (patch) | |
| tree | 8d308d3727d22f25debe5bc1965e602ac3c7110d | |
| parent | 67d2a6c466a1167fa0343e256d73bc89ec27ebdf (diff) | |
Test for creating a new request via the API
This is not yet implemented. Test first!
| -rw-r--r-- | spec/controllers/api_controller_spec.rb | 33 | 
1 files changed, 33 insertions, 0 deletions
| diff --git a/spec/controllers/api_controller_spec.rb b/spec/controllers/api_controller_spec.rb new file mode 100644 index 000000000..91d113dac --- /dev/null +++ b/spec/controllers/api_controller_spec.rb @@ -0,0 +1,33 @@ +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]) +         +        request_data = { +            "title" => "Tell me about your chickens", +            "body" => "Dear Sir,\n\nI should like to know about your chickens.\n\nYours in faith,\nBob\n", +             +            "external_url" => "http://www.example.gov.uk/foi/chickens_23", +            "external_user_name" => "Bob Smith", +        } +         +        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_body = response.body.from_json +        response_body["url"].should =~ /^http/ +         +        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 +        new_request.external_user_name.should == request_data["external_user_name"] +        new_request.external_url.should == request_data["external_url"] +         +        new_request.title.should == request_data["title"] +        new_request.last_event_forming_initial_request.outgoing_message.body.should == request_data["body"] +    end +end | 
