Skip to content

Conversation

amyschools
Copy link
Contributor

What's in this PR?

Adding api_case.ex helpers.

References

Closes #418

Progress on: #413

Copy link

@sbatson5 sbatson5 left a comment

Choose a reason for hiding this comment

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

Just a couple of questions, but this looks great! 👍 :shipit:


first_result
|> assert_result_id(project_category_1.id)
|> assert_jsonapi_relationship("project", project.id)
Copy link

Choose a reason for hiding this comment

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

Do we no longer want to test the relationships are valid?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think since they are already tested in the model test, we decided to take them out of the controller tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you agree with that?

Copy link

Choose a reason for hiding this comment

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

That makes sense to me. Thanks for clarifying!

data = conn |> post(path, payload) |> json_response(422)
assert data["errors"] != %{}
test "renders 422 when data is invalid", %{conn: conn} do
invalid_attrs = %{}
Copy link

Choose a reason for hiding this comment

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

Do we need to assign invalid_attrs? On the two tests below we simply call request_create(%{}). Thoughts on removing this or possibly declaring @invalid_attrs up top and reusing it in the tests below as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the other controller tests we were declaring @invalid_attrs at the top and using it in the 422 test, but since it's the only place we end up using it @joshsmith said this might be a little cleaner.

I think this difference with the request_create for the 401 and 403 tests we don't even hit the attributes before it halts with an error, so an empty attribute map is kind of just placeholding instead of being invalid.

Copy link

Choose a reason for hiding this comment

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

Gotcha. Do we need to even pass anything in the tests below, then? Can we just do conn |> request_create |> json_response(401) ?

Copy link
Contributor Author

@amyschools amyschools Nov 2, 2016

Choose a reason for hiding this comment

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

@mackenziehicks and I were asking all the same questions yesterday! In the api_case helper for request_create you have to pass in attributes, unlike for request_delete where you have an option to just use the conn.

      def request_create(conn, attrs) do
        path = conn |> path_for(:create)
        payload = json_payload(factory_name, attrs)
        conn |> post(path, payload)
      end
      def request_delete(conn), do: conn |> request_delete(default_record)
      def request_delete(conn, :not_found), do: conn |> request_delete(-1)
      def request_delete(conn, resource_or_id) do
        path = conn |> path_for(:delete, resource_or_id)
        conn |> delete(path)
      end
    end
  end

Copy link

Choose a reason for hiding this comment

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

Ah, thanks for explaining!

What are your thoughts on adding a default to request_create?

def request_create(conn, attrs \\ %{})?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I'm dumb and hadn't considered this. Yes, this makes sense.

Choose a reason for hiding this comment

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

@joshsmith I think we should add it for update too.

Right now the test looks like this:
assert conn |> request_update({@valid_attrs}) |> json_response(401)
but we haven't actually added anything to update, so do we need to pass in @valid_attrs?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I'd add it for update, too.

Copy link
Contributor

@begedin begedin left a comment

Choose a reason for hiding this comment

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

Minor change and then good for me.

project = insert(:project)
project_category_1 = insert(:project_category, project: project, category: arts)
project_category_2 = insert(:project_category, project: project, category: society)
[project_category_1, project_category_2] = insert_pair(:project_category)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as comment, while this is good, it could be rewritten in one line as

[project_category_1, project_category_2 | _] = insert_list(3, : project_category_1)

We don't really need to pre-insert the category, or the project. The factory should do that part for us.

@amyschools amyschools force-pushed the 418-projectcategory-controller-test branch from a9592cb to b3a3f2e Compare November 3, 2016 17:30
@coveralls
Copy link

Coverage Status

Coverage remained the same at 95.153% when pulling b3a3f2e on 418-projectcategory-controller-test into f9eef9d on develop.

@amyschools amyschools force-pushed the 418-projectcategory-controller-test branch from b3a3f2e to 3358049 Compare November 3, 2016 17:43
@coveralls
Copy link

Coverage Status

Coverage remained the same at 95.153% when pulling 3358049 on 418-projectcategory-controller-test into f9eef9d on develop.

@amyschools amyschools merged commit 3c24fad into develop Nov 3, 2016
@amyschools amyschools deleted the 418-projectcategory-controller-test branch November 3, 2016 17:48
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