Allow setting first-time-slug - #283
Conversation
In our application we allow users to set the slug. This works fine for content that already exists (is persisted to DB), but when creating new content the slug generator will override the given slug resulting in duplicates.
sobolevn
left a comment
There was a problem hiding this comment.
If you want to, I can also add tests to demonstrate what it fixes?
Yes, please
Pull Request Test Coverage Report for Build 526a9920e83446ab385ed7c91fd6944c1cd21449-PR-283Details
💛 - Coveralls |
|
Hi @sobolevn, I've run into a little trouble with the current test setup. I feel the test cases are not cleanly separated at the moment. In the setup block of (for example of SlugGeneratorTest) we setup 1 fixture: setup do
{:ok,
%{
user: User.changeset(%User{}, @valid_attrs),
opts: [
to: :simple_slug,
slug_builder: &build_slug/2
]
}}
endand then we have a unit test to test 1 function (SlugGenerator.maybe_generate_slug/3) test "maybe_generate_slug with multiple sources", fixture do
changeset =
maybe_generate_slug(fixture.user, [:name, :company], fixture.opts)
assert changeset.changes.simple_slug == "nikita-sobolev-wemake-services"
endHowever, the User.changeset/2 function in our setup block calls the function under test (SlugGenerator.maybe_generate_slug/3) several times already, tainting our test case. In my opinion the unit test doesn't describe the correct behaviour as the slugs are already generated by the time our unit test runs. WDYT ? If you agree with me, is it ok if I propose a change in a different PR? |
|
I have a very little memory of this code base (I wrote it 8 years ago), so, please feel free to improve it :) |
Hi,
Thanks for this package, it has been helpful for us. For our use case we found one issue, this PR is meant as a starting point for discussion.
In our application we allow users to set the slug. This works fine for content that already exists (is persisted to DB), but when creating new content the slug generator will override the given slug resulting in duplicates.
If you want to, I can also add tests to demonstrate what it fixes?
Best,
Tonći ( @Tuxified )