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 (466/400 (116%)) allowed.  Message will be reattempted later

------- This is a copy of the message, including all the headers. ------
Received: from github-smtp2-ext1.iad.github.net ([192.30.252.192]:60102 helo=github-smtp2a-ext-cp1-prd.iad.github.net)
	by zurich.footholds.net with esmtps (UNKNOWN:DHE-RSA-AES256-GCM-SHA384:256)
	(Exim 4.82)
	(envelope-from <noreply@github.com>)
	id 1WzpXw-00009n-Nk
	for alex@alexskene.com; Wed, 25 Jun 2014 16:55:40 +0100
Date: Wed, 25 Jun 2014 08:55:33 -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/r14195101@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_53aaf0f5c998b_36223fb9f97cb29c12295e";
 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-14195101-7ac8574ca09a7987221ac12743e9fde56c8881fc-510285@reply.github.com>,
 <https://github.com/notifications/unsubscribe/510285__eyJzY29wZSI6Ik5ld3NpZXM6TXV0ZSIsImV4cGlyZXMiOjE3MTkzMzA5MzMsImRhdGEiOnsiaWQiOjM1MzExOTc0fX0=--99c44c7c22b85c26d07934837fe8efaf9b1bdd07>
X-Auto-Response-Suppress: All
X-GitHub-Recipient-Address: alex@alexskene.com


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

>  
> -        new_request.title.should == request_data["title"]
> -        new_request.last_event_forming_initial_request.outgoing_message.body.should == request_data["body"].strip
> +        it 'should not allow other people\'s requests to be updated' do
> +            request_id = _create_request
> +            n_incoming_messages = IncomingMessage.count
> +            n_outgoing_messages = OutgoingMessage.count
> +
> +            post :add_correspondence,
> +                 :k => public_bodies(:humpadink_public_body).api_key,
> +                 :id => request_id,
> +                 :correspondence_json => {
> +                     "direction" => "request",
> +                     "sent_at" => Time.now.iso8601,

Prefer single-quoted strings when you don't need string interpolation or special symbols.

---
Reply to this email directly or view it on GitHub:
https://github.com/mysociety/alaveteli/pull/1631/files#r14195101
----==_mimepart_53aaf0f5c998b_36223fb9f97cb29c12295e
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;  
&gt; -        new_request.title.should == request_data[&quot;title&quot;]
&gt; -        new_request.last_event_forming_initial_request.outgoing_message.body.should == request_data[&quot;body&quot;].strip
&gt; +        it &#39;should not allow other people\&#39;s requests to be updated&#39; do
&gt; +            request_id = _create_request
&gt; +            n_incoming_messages = IncomingMessage.count
&gt; +            n_outgoing_messages = OutgoingMessage.count
&gt; +
&gt; +            post :add_correspondence,
&gt; +                 :k =&gt; public_bodies(:humpadink_public_body).api_key,
&gt; +                 :id =&gt; request_id,
&gt; +                 :correspondence_json =&gt; {
&gt; +                     &quot;direction&quot; =&gt; &quot;request&quot;,
&gt; +                     &quot;sent_at&quot; =&gt; Time.now.iso8601,
</pre>
<p>Prefer single-quoted strings when you don't need string interpolation or special symbols.</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#r14195101">view it on GitHub</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/510285__eyJzY29wZSI6Ik5ld3NpZXM6QmVhY29uIiwiZXhwaXJlcyI6MTcxOTMzMDkzMywiZGF0YSI6eyJpZCI6MzUzMTE5NzR9fQ==--38e242918d02663d98fcbcf62c53b88f022bc654.gif" width="1" /></p>
----==_mimepart_53aaf0f5c998b_36223fb9f97cb29c12295e--