Skip to content

Commit

Permalink
add specs to users controller, closes #108
Browse files Browse the repository at this point in the history
  • Loading branch information
npauzenga committed Jan 30, 2016
1 parent cd3f9cf commit 9e7ec4d
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 19 deletions.
6 changes: 3 additions & 3 deletions config/schema/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@
"links": [
{
"description": "Create a new user.",
"href": "/users",
"href": "/user",
"method": "POST",
"rel": "create",
"schema": {
Expand Down Expand Up @@ -785,7 +785,7 @@
},
{
"description": "Delete an existing user.",
"href": "/users/{(%23%2Fdefinitions%2Fuser%2Fdefinitions%2Fidentity)}",
"href": "/user/{(%23%2Fdefinitions%2Fuser%2Fdefinitions%2Fidentity)}",
"method": "DELETE",
"http_header": {
"Authorization": "Bearer: iOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE0NTM5MzkwMjYsImF1ZCI6bnVsbCwic3ViIjoxfQ.TSgJie1vAWxR_ym_uazjKs43rpQ50OKmb2KZ2N6ALs4"
Expand Down Expand Up @@ -877,7 +877,7 @@
},
{
"description": "Update an existing user.",
"href": "/users/{(%23%2Fdefinitions%2Fuser%2Fdefinitions%2Fidentity)}",
"href": "/user/{(%23%2Fdefinitions%2Fuser%2Fdefinitions%2Fidentity)}",
"method": "PATCH",
"rel": "update",
"http_header": {
Expand Down
12 changes: 6 additions & 6 deletions config/schema/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ The User resource for the API
Create a new user.

```
POST /users
POST /user
```

#### Required Parameters
Expand All @@ -521,7 +521,7 @@ POST /users
#### Curl Example

```bash
$ curl -n -X POST http://localhost:3000/users \
$ curl -n -X POST http://localhost:3000/user \
-d '{
"id": "1294",
"first_name": "Nate",
Expand Down Expand Up @@ -553,14 +553,14 @@ HTTP/1.1 201 Created
Delete an existing user.

```
DELETE /users/{user_id_or_email}
DELETE /user/{user_id_or_email}
```


#### Curl Example

```bash
$ curl -n -X DELETE http://localhost:3000/users/$USER_ID_OR_EMAIL \
$ curl -n -X DELETE http://localhost:3000/user/$USER_ID_OR_EMAIL \
-H "Content-Type: application/json" \
-H "Authorization: Bearer: iOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE0NTM5MzkwMjYsImF1ZCI6bnVsbCwic3ViIjoxfQ.TSgJie1vAWxR_ym_uazjKs43rpQ50OKmb2KZ2N6ALs4"
```
Expand Down Expand Up @@ -663,7 +663,7 @@ HTTP/1.1 200 OK
Update an existing user.

```
PATCH /users/{user_id_or_email}
PATCH /user/{user_id_or_email}
```

#### Required Parameters
Expand All @@ -684,7 +684,7 @@ PATCH /users/{user_id_or_email}
#### Curl Example

```bash
$ curl -n -X PATCH http://localhost:3000/users/$USER_ID_OR_EMAIL \
$ curl -n -X PATCH http://localhost:3000/user/$USER_ID_OR_EMAIL \
-d '{
"id": "1294",
"first_name": "Nate",
Expand Down
6 changes: 3 additions & 3 deletions config/schema/schemata/user.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
"links": [
{
"description": "Create a new user.",
"href": "/users",
"href": "/user",
"method": "POST",
"rel": "create",
"schema": {
Expand All @@ -134,7 +134,7 @@
},
{
"description": "Delete an existing user.",
"href": "/users/{(%2Fschemata%2Fuser%23%2Fdefinitions%2Fidentity)}",
"href": "/user/{(%2Fschemata%2Fuser%23%2Fdefinitions%2Fidentity)}",
"method": "DELETE",
"http_header": {
"Authorization": "Bearer: iOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE0NTM5MzkwMjYsImF1ZCI6bnVsbCwic3ViIjoxfQ.TSgJie1vAWxR_ym_uazjKs43rpQ50OKmb2KZ2N6ALs4"
Expand Down Expand Up @@ -192,7 +192,7 @@
},
{
"description": "Update an existing user.",
"href": "/users/{(%2Fschemata%2Fuser%23%2Fdefinitions%2Fidentity)}",
"href": "/user/{(%2Fschemata%2Fuser%23%2Fdefinitions%2Fidentity)}",
"method": "PATCH",
"rel": "update",
"http_header": {
Expand Down
1 change: 0 additions & 1 deletion spec/acceptance/profiles_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,3 @@ def schema_path
end
end
end

12 changes: 6 additions & 6 deletions spec/controllers/profiles_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
let(:last_request) { request }

describe "GET #show" do
let(:user) { create(:confirmed_user) }
let(:params) { { id: user.id } }
let(:show_profile_input) { { id: params.fetch(:id).to_s} }
let(:user) { create(:confirmed_user) }
let(:params) { { id: user.id } }
let(:show_profile_input) { { id: params.fetch(:id).to_s } }

let(:show_profile_context) do
Interactor::Context.new(errors: :val, user: user)
Expand Down Expand Up @@ -93,9 +93,9 @@

it "render the profiles as JSON" do
get :index
expect(json["data"][0].has_value?(user.id.to_s)).to be_truthy
expect(json["data"][1].has_value?(user2.id.to_s)).to be_truthy
expect(json["data"][2].has_value?(user3.id.to_s)).to be_truthy
expect(json["data"][0].value?(user.id.to_s)).to be_truthy
expect(json["data"][1].value?(user2.id.to_s)).to be_truthy
expect(json["data"][2].value?(user3.id.to_s)).to be_truthy
end

it "conforms to JSON schema" do
Expand Down
15 changes: 15 additions & 0 deletions spec/controllers/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@
post :create, params
expect(json["jwt"]).to include("token")
end

it "conforms to JSON schema" do
post :create, params
assert_schema_conform
end
end

context "when CreateUser is a failure" do
Expand Down Expand Up @@ -175,6 +180,16 @@
patch :update, params
expect(response).to have_http_status(200)
end

it "renders the user as json" do
post :update, params
expect(serialize(user)).to eq(response.body)
end

it "conforms to JSON schema" do
post :update, params
assert_schema_conform
end
end

context "when Update User fails" do
Expand Down

0 comments on commit 9e7ec4d

Please sign in to comment.