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

------- This is a copy of the message, including all the headers. ------
Received: from github-smtp2-ext3.iad.github.net ([192.30.252.194]:37235 helo=github-smtp2b-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 1WzpXr-0008Te-U3
	for alex@alexskene.com; Wed, 25 Jun 2014 16:55:36 +0100
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/r14195047@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_53aaf0ef128b5_358e3fb9f97cb29c125196";
 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-14195047-e91acb210aae6164c39fa4d5578381a72786be8a-510285@reply.github.com>,
 <https://github.com/notifications/unsubscribe/510285__eyJzY29wZSI6Ik5ld3NpZXM6TXV0ZSIsImV4cGlyZXMiOjE3MTkzMzA5MjcsImRhdGEiOnsiaWQiOjM1MzExOTc0fX0=--b86e78ac55576816689e7cfb289c30aba60e4704>
X-Auto-Response-Suppress: All
X-GitHub-Recipient-Address: alex@alexskene.com


----==_mimepart_53aaf0ef128b5_358e3fb9f97cb29c125196
Content-Type: text/plain;
 charset=UTF-8
Content-Transfer-Encoding: quoted-printable

> -        get :show_request,
> -            :k =3D> public_bodies(:geraldine_public_body).api_key,
> -            :id =3D> info_request.id
> -
> -        response.should be_success
> -        assigns[:request].id.should =3D=3D info_request.id
> -
> -        r =3D ActiveSupport::JSON.decode(response.body)
> -        r["title"].should =3D=3D info_request.title
> -        # Let=E2=80=99s not test all the fields here, because it would=

> -        # essentially just be a matter of copying the code that
> -        # assigns them and changing assignment to an equality
> -        # check, which does not really test anything at all.
> -    end
> +            response.status.should =3D=3D 404
> +            ActiveSupport::JSON.decode(response.body)["errors"].should=
 =3D=3D ["Could not find request 123459876"]

Line is too long. [110/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#r14195047=

----==_mimepart_53aaf0ef128b5_358e3fb9f97cb29c125196
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<p>In spec/controllers/api_controller_spec.rb:</p>
<pre style=3D'color:#555'>&gt; -        get :show_request,
&gt; -            :k =3D&gt; public_bodies(:geraldine_public_body).api_ke=
y,
&gt; -            :id =3D&gt; info_request.id
&gt; -
&gt; -        response.should be_success
&gt; -        assigns[:request].id.should =3D=3D info_request.id
&gt; -
&gt; -        r =3D ActiveSupport::JSON.decode(response.body)
&gt; -        r[&quot;title&quot;].should =3D=3D info_request.title
&gt; -        # Let=E2=80=99s not test all the fields here, because it wo=
uld
&gt; -        # essentially just be a matter of copying the code that
&gt; -        # assigns them and changing assignment to an equality
&gt; -        # check, which does not really test anything at all.
&gt; -    end
&gt; +            response.status.should =3D=3D 404
&gt; +            ActiveSupport::JSON.decode(response.body)[&quot;errors&=
quot;].should =3D=3D [&quot;Could not find request 123459876&quot;]
</pre>
<p>Line is too long. [110/80]<br>Prefer single-quoted strings when you do=
n't need string interpolation or special symbols.</p>

<p style=3D"font-size:small;-webkit-text-size-adjust:none;color:#666;">&m=
dash;<br>Reply to this email directly or <a href=3D"https://github.com/my=
society/alaveteli/pull/1631/files#r14195047">view it on GitHub</a>.<img a=
lt=3D"" height=3D"1" src=3D"https://github.com/notifications/beacon/51028=
5__eyJzY29wZSI6Ik5ld3NpZXM6QmVhY29uIiwiZXhwaXJlcyI6MTcxOTMzMDkyNywiZGF0YS=
I6eyJpZCI6MzUzMTE5NzR9fQ=3D=3D--f84597d265d4889123fb2a3ecce125a31003e32c.=
gif" width=3D"1" /></p>=

----==_mimepart_53aaf0ef128b5_358e3fb9f97cb29c125196--