Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds Repo.slug/1 helper function #24

Merged
merged 2 commits into from Jun 10, 2018

Conversation

tallysmartins
Copy link
Member

@coveralls
Copy link

coveralls commented May 31, 2018

Coverage Status

Coverage increased (+0.3%) to 63.243% when pulling 586336c on tallysmartins:repo_slug into 0e3616f on elixir-bench:master.

Copy link
Member

@PragTob PragTob left a comment

Choose a reason for hiding this comment

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

Looking good, only real minor musing about testing

@@ -16,4 +16,8 @@ defmodule ElixirBench.Repos.Repo do
|> cast(attrs, [:owner, :name])
|> validate_required([:owner, :name])
end

def slug(%Repo{} = repo) do
Copy link
Member

Choose a reason for hiding this comment

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

I wanted to ask if we need to match on repo here, but it's done in other parts of the code base as well 🤔

Upside I see is that it fails early when we don't pass a repo, downside is we can't pass a normal map.

Intuitively I wouldn't match on it but it also makes sense so 🤷‍♂️

Any input @michalmuskala ? ;P

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I also wanted to ask you when to do or not this kind of match.. in the ElixirBench.Benchmarks module, for example, some methods does this kind of match like in submit_job(%Job{} = job, results) but others don't def create_job(repo, attrs)

I think we can remove the match indeed. This matches should be used in cases where different types make calls to the same method but with different behaviors, right?

Copy link
Member

Choose a reason for hiding this comment

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

yeah I think we can remove it until michal tells us otherwise :)

end

test "delete_repo/1 deletes the repo" do
repo = repo_fixture()
assert {:ok, %Repo{}} = Repos.delete_repo(repo)
assert Repos.fetch_repo_by_slug(repo.owner <> "/" <> repo.name) == {:error, :not_found}
assert Repos.fetch_repo_by_slug(Repos.Repo.slug(repo)) == {:error, :not_found}
Copy link
Member

Choose a reason for hiding this comment

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

in general one should be careful with using own application code in assertions. Because that's easily how bugs bubble up and aren't detected.

For the assertions, as I assume the name is constant we could just put the verbatim repo slug in a module attribute `@repo_slug "my-cool/repo-slug"

Copy link
Member Author

Choose a reason for hiding this comment

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

Didn't get the point. You mean not to use in tests or just inside an assertion? I make use of this method in schema_test as well, should I also remove from it?

Copy link
Member

Choose a reason for hiding this comment

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

Hey, yeah don't use it in assertion or well... mostly don't. You want your "test code" and production code not to be interdependent so much (other than the thing under test of course)

Imagine you break Repo.slug - all the tests using it would be broken as well!

@PragTob PragTob merged commit f9ed129 into elixir-bench:master Jun 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create a Repo.slug helper function
3 participants