Skip to content

Refactor Project Controller Tests - #438

Merged
amyschools merged 1 commit into
developfrom
437-project-controller-test
Nov 11, 2016
Merged

amyschools merged 1 commit into
developfrom
437-project-controller-test

Conversation

@amyschools

Copy link
Copy Markdown
Contributor

What's in this PR?

Add api_case.ex helpers to Project controller tests.

References

Closes #437

Progress on: #413

@amyschools amyschools self-assigned this Nov 4, 2016
@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.2%) to 93.689% when pulling 3972bb5 on 437-project-controller-test into 604f6df on develop.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.2%) to 93.689% when pulling 486c596 on 437-project-controller-test into 604f6df on develop.

@mackenziehicks mackenziehicks left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@sbatson5 sbatson5 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just 1 suggestion. This is looking great 👍

assert data["attributes"]["title"] == "Test project"
assert data["attributes"]["description"] == "Test project description"
assert data["attributes"]["long-description-markdown"] == "A markdown **description**"
assert data["relationships"]["organization"]["data"]["id"] == Integer.to_string(project.organization_id)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks so much better 👏

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

This is what I love the most about these.

@@ -30,24 +21,12 @@ defmodule CodeCorps.ProjectControllerTest do
project_1 = insert(:project, title: "Test Project 1", organization: organization)
project_2 = insert(:project, title: "Test Project 2", organization: organization)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the titles here necessary? Thoughts on reducing this to insert_pair and letting the factory generate the titles? Since we aren't testing for them, I'm not sure we need them to be unique.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed here.

@joshsmith joshsmith left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some changes here. Remember to ask yourself where the dividing line is on what you're testing.

data =
conn
|> json_response(200)
|> Map.get("data")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spacing on this is off now that data was removed. Make sure to watch your alignment.

slug: "test-project")
project = insert(:project, title: "Test project", slug: "test-project")

conn = get conn, "/test-organization/test-project"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is confusing and brittle because we're relying on test-organization from the factory, but specifying test-project.

I think I would rather do:

organization = insert(:organization)
project = insert(:project, organization: organization)

path = "#{organization.slug}/#{project.slug}"

What do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's much better!!


describe "create" do
@tag :authenticated
@tag authenticated: :admin

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should just be @tag :authenticated if you're relying on insert(:organization_membership, role: "admin"), otherwise you're going to defer to the site admin authentication since it takes precedence.

path = conn |> project_path(:create)
assert conn |> post(path, payload) |> json_response(403)
attrs = @invalid_attrs |> Map.merge(%{organization: organization})
assert conn |> request_create(attrs) |> json_response(403)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you doing this extra work here? Would request_create on its own not work?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was having trouble getting this test to pass and this was the only solution that worked. I couldn't figure out why the usual request_create wasn't working so I just included the attributes. I'll look at it again today.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the error I'm getting: ** (FunctionClauseError) no function clause matching in CodeCorps.Helpers.Policy.get_membership/2

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay we'll dig into it when we pair.

test "renders 403 when not authorized", %{conn: conn} do
organization = insert(:organization)
attrs = @invalid_attrs |> Map.merge(%{organization: organization})
assert conn |> request_update(attrs) |> json_response(403)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, why not just request_update?

@@ -30,24 +21,12 @@ defmodule CodeCorps.ProjectControllerTest do
project_1 = insert(:project, title: "Test Project 1", organization: organization)
project_2 = insert(:project, title: "Test Project 2", organization: organization)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed here.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.3%) to 94.175% when pulling 9e1587b on 437-project-controller-test into 604f6df on develop.

@sbatson5 sbatson5 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still LGTM 👍

@begedin begedin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@amyschools
amyschools force-pushed the 437-project-controller-test branch from 9e1587b to 1cf4a86 Compare November 11, 2016 20:50
@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.2%) to 93.7% when pulling 1cf4a86 on 437-project-controller-test into e492da7 on develop.

@amyschools
amyschools merged commit 1928206 into develop Nov 11, 2016
@amyschools
amyschools deleted the 437-project-controller-test branch November 11, 2016 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants