aboutsummaryrefslogtreecommitdiffstats
path: root/spec/controllers
diff options
context:
space:
mode:
authorRobin Houston <robin.houston@gmail.com>2012-09-07 12:52:27 +0100
committerRobin Houston <robin.houston@gmail.com>2012-09-07 12:52:27 +0100
commit2882543a8fcad4c38a9b45fa7e493ea04ee02d65 (patch)
tree7357dd048ec0315b7417f260b28d75867cb66619 /spec/controllers
parentc690679f5e55d908a0f91b0d9b3276ae3f748b2d (diff)
parent47f6141fd2ccf52c9149fe91893907db8894d65a (diff)
Merge branch 'master' into wdtk
Diffstat (limited to 'spec/controllers')
-rw-r--r--spec/controllers/api_controller_spec.rb77
1 files changed, 57 insertions, 20 deletions
diff --git a/spec/controllers/api_controller_spec.rb b/spec/controllers/api_controller_spec.rb
index 98751a93a..925b7adb4 100644
--- a/spec/controllers/api_controller_spec.rb
+++ b/spec/controllers/api_controller_spec.rb
@@ -149,16 +149,19 @@ describe ApiController, "when using the API" do
n_incoming_messages = IncomingMessage.count
n_outgoing_messages = OutgoingMessage.count
- expect {
- post :add_correspondence,
- :k => public_bodies(:geraldine_public_body).api_key,
- :id => info_requests(:naughty_chicken_request).id,
- :correspondence_json => {
- "direction" => "request",
- "sent_at" => Time.now.iso8601,
- "body" => "xxx"
- }.to_json
- }.to raise_error ActiveRecord::RecordNotFound
+ request_id = info_requests(:naughty_chicken_request).id
+ post :add_correspondence,
+ :k => public_bodies(:geraldine_public_body).api_key,
+ :id => request_id,
+ :correspondence_json => {
+ "direction" => "request",
+ "sent_at" => Time.now.iso8601,
+ "body" => "xxx"
+ }.to_json
+
+ response.status.should == "500 Internal Server Error"
+ ActiveSupport::JSON.decode(response.body)["errors"].should == [
+ "Request #{request_id} cannot be updated using the API"]
IncomingMessage.count.should == n_incoming_messages
OutgoingMessage.count.should == n_outgoing_messages
@@ -169,16 +172,18 @@ describe ApiController, "when using the API" do
n_incoming_messages = IncomingMessage.count
n_outgoing_messages = OutgoingMessage.count
- expect {
- post :add_correspondence,
- :k => public_bodies(:humpadink_public_body).api_key,
- :id => request_id,
- :correspondence_json => {
- "direction" => "request",
- "sent_at" => Time.now.iso8601,
- "body" => "xxx"
- }.to_json
- }.to raise_error ActiveRecord::RecordNotFound
+ post :add_correspondence,
+ :k => public_bodies(:humpadink_public_body).api_key,
+ :id => request_id,
+ :correspondence_json => {
+ "direction" => "request",
+ "sent_at" => Time.now.iso8601,
+ "body" => "xxx"
+ }.to_json
+
+ response.status.should == "500 Internal Server Error"
+ ActiveSupport::JSON.decode(response.body)["errors"].should == [
+ "You do not own request #{request_id}"]
IncomingMessage.count.should == n_incoming_messages
OutgoingMessage.count.should == n_outgoing_messages
@@ -314,4 +319,36 @@ describe ApiController, "when using the API" do
response.should be_success
assigns[:event_data].should == [first_event]
end
+
+ it "should return a JSON 404 error for non-existent requests" do
+ request_id = 123459876 # Let's hope this doesn't exist!
+ sent_at = "2012-05-28T12:35:39+01:00"
+ response_body = "Thank you for your request for information, which we are handling in accordance with the Freedom of Information Act 2000. You will receive a response within 20 working days or before the next full moon, whichever is sooner.\n\nYours sincerely,\nJohn Gandermulch,\nExample Council FOI Officer\n"
+ post :add_correspondence,
+ :k => public_bodies(:geraldine_public_body).api_key,
+ :id => request_id,
+ :correspondence_json => {
+ "direction" => "response",
+ "sent_at" => sent_at,
+ "body" => response_body
+ }.to_json
+ response.status.should == "404 Not Found"
+ ActiveSupport::JSON.decode(response.body)["errors"].should == ["Could not find request 123459876"]
+ end
+
+ it "should return a JSON 500 error if we try to add correspondence to a request we don't own" do
+ request_id = info_requests(:naughty_chicken_request).id
+ sent_at = "2012-05-28T12:35:39+01:00"
+ response_body = "Thank you for your request for information, which we are handling in accordance with the Freedom of Information Act 2000. You will receive a response within 20 working days or before the next full moon, whichever is sooner.\n\nYours sincerely,\nJohn Gandermulch,\nExample Council FOI Officer\n"
+ post :add_correspondence,
+ :k => public_bodies(:geraldine_public_body).api_key,
+ :id => request_id,
+ :correspondence_json => {
+ "direction" => "response",
+ "sent_at" => sent_at,
+ "body" => response_body
+ }.to_json
+ response.status.should == "500 Internal Server Error"
+ ActiveSupport::JSON.decode(response.body)["errors"].should == ["Request #{request_id} cannot be updated using the API"]
+ end
end