Phoenix: Mix phx.gen.live generates invalid tests when a unique constraint is present

Created on 17 Jan 2021  路  6Comments  路  Source: phoenixframework/phoenix

Environment

  • Elixir version (elixir -v):
  • Phoenix version (mix deps): 1.5.7
  • NodeJS version (node -v):
  • NPM version (npm -v):
  • Operating system:

Expected behavior

All tests pass.

Actual behavior

1) test Index saves new registry (PourWeb.RegistryLiveTest)
     test/pour_web/live/registry_live_test.exs:32
     ** (RuntimeError) LiveView did not redirect
     code: |> follow_redirect(conn, Routes.registry_index_path(conn, :index))
     stacktrace:
       test/pour_web/live/registry_live_test.exs:48: (test)

Generated with mix phx.gen.live Registries Registry registries name:string:unique type:string. This happens because the setup and the test both generate a registry with @create_attrs, which then triggers the unique constraint.

Most helpful comment

@josevalim Just a quick heads up... my plan for my next PR is to update the phx.gen.* generators to start using the new test fixture module, which should solve this issue.

All 6 comments

@feliperenan do you want to pick this one up? :)

@josevalim Just a quick heads up... my plan for my next PR is to update the phx.gen.* generators to start using the new test fixture module, which should solve this issue.

@aaronrenner beautiful!

I'm also getting failing tests upon running the generator, due to conflicting HTML escaping. Is it somehow related? Otherwise I can make another issue.

image

I see the same things as @a8t.

This issue is solved on master by this PR: https://github.com/phoenixframework/phoenix/pull/3829. Maybe close this one @josevalim? 馃

Was this page helpful?
0 / 5 - 0 ratings