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 (427/400 (106%)) 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]:46653)
	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 1WzpXt-0008U1-Dt
	for alex@alexskene.com; Wed, 25 Jun 2014 16:55:37 +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=VZh4OacBYWB4HBrfF9DeeCq8pb8=; b=x80LMbe3UaZ14/zMpC
	ImD0+ovDHBtJuDwQpQaLIEFasii7WbKKwGFqoVMX0JdT+P3k4GkZEXBlF8pSTHek
	jakBgHiK/PMHHfZ/et4MZm2NM1coASt4/6YMAfD97AHZP2pc1X5uyojKdDogtqSS
	6ERCyVFYngqUKjSY+xwkG5rM8=
Received: by mf279.sendgrid.net with SMTP id mf279.24538.53AAF0F01
        Wed, 25 Jun 2014 15:55:28 +0000 (UTC)
Received: from github-smtp2b-ext-cp1-prd.iad.github.net (github-smtp2b-ext-cp1-prd.iad.github.net [192.30.253.17])
	by ismtpd-016.iad1.sendgrid.net (SG) with ESMTP id 146d3bd28d9.73ae.106ea8
	for <alex@alexskene.com>; Wed, 25 Jun 2014 15:55:27 +0000 (GMT)
Date: Wed, 25 Jun 2014 08:55:27 -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/r14195050@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_53aaf0ef7a84b_35873fb9f97cb29c228169";
 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-14195050-68ebe52ce0b565d762a86c8a9994526b980f425b-510285@reply.github.com>,
 <https://github.com/notifications/unsubscribe/510285__eyJzY29wZSI6Ik5ld3NpZXM6TXV0ZSIsImV4cGlyZXMiOjE3MTkzMzA5MjcsImRhdGEiOnsiaWQiOjM1MzExOTc0fX0=--b86e78ac55576816689e7cfb289c30aba60e4704>
X-Auto-Response-Suppress: All
X-GitHub-Recipient-Address: alex@alexskene.com
X-SG-EID: hQ+xzKT9K37JzZfKEXr3QNageyq61ruQMWnl5rBwpIL73wMxz7UoYpkdsLXAI6m9/b3dwIpNYv/mqDXRhO3oVbPg9IOgeaNsPe4Uba8cQfnzXf6da8ZpZ0UYhSEE/hF/U/kNFfOoxFno7i8uxA+0dqobHqI9stM0rY55FaMrTOk=

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

>  
> -    it "should show an Atom feed of new request events" do
> -        get :body_request_events,
> -            :id => public_bodies(:geraldine_public_body).id,
> -            :k => public_bodies(:geraldine_public_body).api_key,
> -            :feed_type => "atom"
> -
> -        response.should be_success
> -        response.should render_template("api/request_events")
> -        assigns[:events].size.should > 0
> -        assigns[:events].each do |event|
> -            event.info_request.public_body.should == public_bodies(:geraldine_public_body)
> -            event.outgoing_message.should_not be_nil
> -            event.event_type.should satisfy {|x| ['sent', 'followup_sent', 'resent', 'followup_resent'].include?(x)}
> +            response.status.should == 403
> +            ActiveSupport::JSON.decode(response.body)["errors"].should == ["Request #{request_id} cannot be updated using the API"]

Line is too long. [131/80]<br>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#r14195050
----==_mimepart_53aaf0ef7a84b_35873fb9f97cb29c228169
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; -    it &quot;should show an Atom feed of new request events&quot; do
&gt; -        get :body_request_events,
&gt; -            :id =&gt; public_bodies(:geraldine_public_body).id,
&gt; -            :k =&gt; public_bodies(:geraldine_public_body).api_key,
&gt; -            :feed_type =&gt; &quot;atom&quot;
&gt; -
&gt; -        response.should be_success
&gt; -        response.should render_template(&quot;api/request_events&quot;)
&gt; -        assigns[:events].size.should &gt; 0
&gt; -        assigns[:events].each do |event|
&gt; -            event.info_request.public_body.should == public_bodies(:geraldine_public_body)
&gt; -            event.outgoing_message.should_not be_nil
&gt; -            event.event_type.should satisfy {|x| [&#39;sent&#39;, &#39;followup_sent&#39;, &#39;resent&#39;, &#39;followup_resent&#39;].include?(x)}
&gt; +            response.status.should == 403
&gt; +            ActiveSupport::JSON.decode(response.body)[&quot;errors&quot;].should == [&quot;Request #{request_id} cannot be updated using the API&quot;]
</pre>
<p>Line is too long. [131/80]<br>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#r14195050">view it on GitHub</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/510285__eyJzY29wZSI6Ik5ld3NpZXM6QmVhY29uIiwiZXhwaXJlcyI6MTcxOTMzMDkyNywiZGF0YSI6eyJpZCI6MzUzMTE5NzR9fQ==--f84597d265d4889123fb2a3ecce125a31003e32c.gif" width="1" /></p>
----==_mimepart_53aaf0ef7a84b_35873fb9f97cb29c228169--