Add request state updating functionality to API

WIP

Adds a new `update_state` method to the API that uses the existing API key mechanism to send a status update to a request created via an external API request. Intended usage - foi-register end-users confirming whether the information they requested has been disclosed ([the parallel work on foi-register can be found here](https://github.com/mysociety/foi-register/tree/issues/169-ask-user-to-confirm-request-state)). Status description mismatches should be handled on the foi-register side but unexpected status values are rejected with a 500 error by the API.

Adds an optional parameter to the pre-existing `add_correspondence` API method to allow it to update status (intended use - updates from a public body) if a `state` value is supplied. Again, the foi-register code is responsible for handling state description mismatches but in this case the API deals with erroneous data by ignoring that part of the request.

Apologies for having restructured `api_controller_spec` but I kept losing track of which API methods the various tests were targeting. I will be happy to change it back before finalising the Pull Request if I've caused trouble.
This message was created automatically by mail delivery software.

A message that you sent could not be delivered to one or more of its
recipients. This is a temporary error. The following address(es) deferred:

  skenaja@gmail.com
    Domain alexskene.com has exceeded the max emails per hour (413/400 (103%)) allowed.  Message will be reattempted later

------- This is a copy of the message, including all the headers. ------
Received: from o4.sgmail.github.com ([192.254.112.99]:38263)
	by zurich.footholds.net with smtps (UNKNOWN:DHE-RSA-AES128-GCM-SHA256:128)
	(Exim 4.82)
	(envelope-from <bounces+848413-9a96-alex=alexskene.com@sgmail.github.com>)
	id 1WzpXs-0008Rk-9F
	for alex@alexskene.com; Wed, 25 Jun 2014 16:55:36 +0100
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sgmail.github.com; 
	h=from:reply-to:to:in-reply-to:references:subject:mime-version:content-type:content-transfer-encoding:list-id:list-archive:list-post:list-unsubscribe; 
	s=smtpapi; bh=x+fFJt9OdHobaO8VN8gztojciJU=; b=ELFzNw3bMVv9dftCjB
	MjlBbDcEwSZOS00gTqh+DYlepGe0BXCV5mvNQCqQcu097YodLI2aVDqzJky0zXTV
	l14xvPK4lFnBbR7Yq9UHBdj/sbOPHyYL1nuGIU7ujya8nmIfrNCm4L7qy2x7k9RK
	liKwPFytCSmXqDwCCtEw1MYds=
Received: by mf172.sendgrid.net with SMTP id mf172.9204.53AAF0EE10
        Wed, 25 Jun 2014 15:55:26 +0000 (UTC)
Received: from github-smtp2a-ext-cp1-prd.iad.github.net (github-smtp2a-ext-cp1-prd.iad.github.net [192.30.253.16])
	by ismtpd-009.iad1.sendgrid.net (SG) with ESMTP id 146d3bd22ed.557a.33b1ba
	for <alex@alexskene.com>; Wed, 25 Jun 2014 10:55:26 -0500 (CST)
Date: Wed, 25 Jun 2014 08:55:26 -0700
From: Hound <notifications@github.com>
Reply-To: mysociety/alaveteli <reply@reply.github.com>
To: mysociety/alaveteli <alaveteli@noreply.github.com>
Message-ID: <mysociety/alaveteli/pull/1631/r14195040@github.com>
In-Reply-To: <mysociety/alaveteli/pull/1631@github.com>
References: <mysociety/alaveteli/pull/1631@github.com>
Subject: Re: [alaveteli] Add request state updating functionality to API
 (#1631)
Mime-Version: 1.0
Content-Type: multipart/alternative;
 boundary="--==_mimepart_53aaf0ee35815_55ad3f977b85b2c042656b";
 charset=UTF-8
Content-Transfer-Encoding: 7bit
Precedence: list
X-GitHub-Recipient: skenaja
List-ID: mysociety/alaveteli <alaveteli.mysociety.github.com>
List-Archive: https://github.com/mysociety/alaveteli
List-Post: <mailto:reply@reply.github.com>
List-Unsubscribe: <mailto:unsub+p-14195040-31a91c83719c01f40aa9312f9e0d8a7d0c105214-510285@reply.github.com>,
 <https://github.com/notifications/unsubscribe/510285__eyJzY29wZSI6Ik5ld3NpZXM6TXV0ZSIsImV4cGlyZXMiOjE3MTkzMzA5MjYsImRhdGEiOnsiaWQiOjM1MzExOTc0fX0=--feda2b4e490461c6d176ad69b3dcfa035c4bd563>
X-Auto-Response-Suppress: All
X-GitHub-Recipient-Address: alex@alexskene.com
X-SG-EID: hQ+xzKT9K37JzZfKEXr3QNageyq61ruQMWnl5rBwpIIdfhDlVFrxvgUcLR6nPOr/1ZCixWhaI8iVvlV1vEzq2iOP0mTZwlAbRBtnACFmhzm4Dt0VlgtWFwbEGGyqxyVjuCGQDUXIKmbZkkhBN+CewL0JCU8AqaGtCkqaOAha3mI=

----==_mimepart_53aaf0ee35815_55ad3f977b85b2c042656b
Content-Type: text/plain;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

> +            post :add_correspondence,
> +                 :k => public_bodies(:geraldine_public_body).api_key,
> +                 :id => info_requests(:external_request).id,
> +                 :correspondence_json => {
> +                     "direction" => "request",
> +                     "sent_at" => Time.now.iso8601,
> +                     "body" => "Are you joking, or are you serious?"
> +                 }.to_json,
> +                 :attachments => [
> +                     fixture_file_upload("/files/tfl.pdf")
> +                 ]
> +
> +            # Make sure it worked
> +            response.status.should == 500
> +            errors = ActiveSupport::JSON.decode(response.body)["errors"]
> +            errors.should == ["You cannot attach files to messages in the 'request' direction"]

Line is too long. [95/80]

---
Reply to this email directly or view it on GitHub:
https://github.com/mysociety/alaveteli/pull/1631/files#r14195040
----==_mimepart_53aaf0ee35815_55ad3f977b85b2c042656b
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

<p>In spec/controllers/api_controller_spec.rb:</p>
<pre style='color:#555'>&gt; +            post :add_correspondence,
&gt; +                 :k =&gt; public_bodies(:geraldine_public_body).api_key,
&gt; +                 :id =&gt; info_requests(:external_request).id,
&gt; +                 :correspondence_json =&gt; {
&gt; +                     &quot;direction&quot; =&gt; &quot;request&quot;,
&gt; +                     &quot;sent_at&quot; =&gt; Time.now.iso8601,
&gt; +                     &quot;body&quot; =&gt; &quot;Are you joking, or are you serious?&quot;
&gt; +                 }.to_json,
&gt; +                 :attachments =&gt; [
&gt; +                     fixture_file_upload(&quot;/files/tfl.pdf&quot;)
&gt; +                 ]
&gt; +
&gt; +            # Make sure it worked
&gt; +            response.status.should == 500
&gt; +            errors = ActiveSupport::JSON.decode(response.body)[&quot;errors&quot;]
&gt; +            errors.should == [&quot;You cannot attach files to messages in the &#39;request&#39; direction&quot;]
</pre>
<p>Line is too long. [95/80]</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">&mdash;<br>Reply to this email directly or <a href="https://github.com/mysociety/alaveteli/pull/1631/files#r14195040">view it on GitHub</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/510285__eyJzY29wZSI6Ik5ld3NpZXM6QmVhY29uIiwiZXhwaXJlcyI6MTcxOTMzMDkyNiwiZGF0YSI6eyJpZCI6MzUzMTE5NzR9fQ==--843305172b17c3ff16cd966b8ccf2fc27c7e80dc.gif" width="1" /></p>
----==_mimepart_53aaf0ee35815_55ad3f977b85b2c042656b--