diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cc5161..25d892b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## v0.2.1 (TBA) + +* Improve mix task instructions + ## v0.2.0 (2019-03-09) ### Changes diff --git a/lib/mix/pow_assent.ex b/lib/mix/pow_assent.ex new file mode 100644 index 0000000..59d7a31 --- /dev/null +++ b/lib/mix/pow_assent.ex @@ -0,0 +1,40 @@ +defmodule Mix.PowAssent do + @moduledoc """ + Utilities module for mix tasks. + """ + + @doc false + @spec validate_schema_args!([binary()], binary()) :: map() | no_return + def validate_schema_args!([schema, plural | _rest] = args, task) do + cond do + not schema_valid?(schema) -> + raise_invalid_schema_args_error!("Expected the schema argument, #{inspect schema}, to be a valid module name", task) + not plural_valid?(plural) -> + raise_invalid_schema_args_error!("Expected the plural argument, #{inspect plural}, to be all lowercase using snake_case convention", task) + true -> + schema_options_from_args(args) + end + end + def validate_schema_args!([_schema | _rest], task) do + raise_invalid_schema_args_error!("Invalid arguments", task) + end + def validate_schema_args!([], _task), do: schema_options_from_args() + + defp schema_valid?(schema), do: schema =~ ~r/^[A-Z]\w*(\.[A-Z]\w*)*$/ + + defp plural_valid?(plural), do: plural =~ ~r/^[a-z\_]*$/ + + @spec raise_invalid_schema_args_error!(binary(), binary()) :: no_return() + defp raise_invalid_schema_args_error!(msg, task) do + Mix.raise(""" + #{msg} + + mix #{task} accepts both a module name and the plural of the resource: + mix #{task} UserIdentities.UserIdentity user_identities + """) + end + + defp schema_options_from_args(_opts \\ []) + defp schema_options_from_args([schema, plural | _rest]), do: %{schema_name: schema, schema_plural: plural} + defp schema_options_from_args(_any), do: %{schema_name: "UserIdentities.UserIdentity", schema_plural: "user_identities"} +end diff --git a/lib/mix/tasks/ecto/pow_assent.ecto.gen.migrations.ex b/lib/mix/tasks/ecto/pow_assent.ecto.gen.migrations.ex index 8aa0cc4..39d7b46 100644 --- a/lib/mix/tasks/ecto/pow_assent.ecto.gen.migrations.ex +++ b/lib/mix/tasks/ecto/pow_assent.ecto.gen.migrations.ex @@ -6,19 +6,29 @@ defmodule Mix.Tasks.PowAssent.Ecto.Gen.Migration do mix pow_assent.ecto.gen.migration -r MyApp.Repo - mix pow_assent.ecto.gen.migration -r MyApp.Repo CustomUserIdentity custom_user_identity + mix pow_assent.ecto.gen.migration -r MyApp.Repo Accounts.Identity identities + + This generator will add a migration file in `priv/repo/migrations` for the + `user_identities` table + + ## Arguments + + * `-r`, `--repo` - the repo module + * `--binary-id` - use binary id for primary key + * `--users-table` - what users table to reference, defaults to "users" """ use Mix.Task alias PowAssent.Ecto.UserIdentities.Schema.Migration, as: UserIdentitiesMigration - alias Mix.{Ecto, Pow, Pow.Ecto.Migration} + alias Mix.{Ecto, Pow, Pow.Ecto.Migration, PowAssent} @switches [binary_id: :boolean, users_table: :string] @default_opts [binary_id: false, users_table: "users"] + @mix_task "pow_assent.ecto.gen.migration" - @doc false + @impl true def run(args) do - Pow.no_umbrella!("pow_assent.ecto.gen.migration") + Pow.no_umbrella!(@mix_task) args |> Pow.parse_options(@switches, @default_opts) @@ -27,13 +37,9 @@ defmodule Mix.Tasks.PowAssent.Ecto.Gen.Migration do end defp parse({config, parsed, _invalid}) do - case parsed do - [_schema_name, schema_plural | _rest] -> - Map.merge(config, %{schema_plural: schema_plural}) - - _ -> - config - end + parsed + |> PowAssent.validate_schema_args!(@mix_task) + |> Map.merge(config) end defp create_migrations_files(config, args) do @@ -44,9 +50,8 @@ defmodule Mix.Tasks.PowAssent.Ecto.Gen.Migration do |> Enum.each(&create_migration_files/1) end - defp create_migration_files(%{repo: repo, binary_id: binary_id, users_table: users_table} = config) do - schema_plural = Map.get(config, :schema_plural, "user_identities") - context_base = Pow.context_app() |> Pow.context_base() |> Atom.to_string() + defp create_migration_files(%{repo: repo, binary_id: binary_id, users_table: users_table, schema_plural: schema_plural}) do + context_base = Pow.app_base(Pow.otp_app()) schema = UserIdentitiesMigration.new(context_base, schema_plural, repo: repo, binary_id: binary_id, users_table: users_table) content = UserIdentitiesMigration.gen(schema) diff --git a/lib/mix/tasks/ecto/pow_assent.ecto.gen.schema.ex b/lib/mix/tasks/ecto/pow_assent.ecto.gen.schema.ex index 7aaca47..27689c5 100644 --- a/lib/mix/tasks/ecto/pow_assent.ecto.gen.schema.ex +++ b/lib/mix/tasks/ecto/pow_assent.ecto.gen.schema.ex @@ -6,19 +6,28 @@ defmodule Mix.Tasks.PowAssent.Ecto.Gen.Schema do mix pow_assent.ecto.gen.schema -r MyApp.Repo - mix pow_assent.ecto.gen.schema -r MyApp.Repo CustomUserIdentity custom_user_identity + mix pow_assent.ecto.gen.schema -r MyApp.Repo Accounts.Identity identities + + This generator will add a schema module file in + `lib/my_app/user_identities/user_identity.ex`. + + ## Arguments + + * `--binary-id` - use binary id for primary key and references + * `--context-app` - context app to use for path and module names """ use Mix.Task alias PowAssent.Ecto.UserIdentities.Schema.Module, as: SchemaModule - alias Mix.{Generator, Pow} + alias Mix.{Generator, Pow, PowAssent} @switches [context_app: :string, binary_id: :boolean] @default_opts [binary_id: false] + @mix_task "pow_assent.ecto.gen.schema" - @doc false + @impl true def run(args) do - Pow.no_umbrella!("pow_assent.ecto.gen.schema") + Pow.no_umbrella!(@mix_task) args |> Pow.parse_options(@switches, @default_opts) @@ -27,34 +36,18 @@ defmodule Mix.Tasks.PowAssent.Ecto.Gen.Schema do end defp parse({config, parsed, _invalid}) do - case parsed do - [schema_name, schema_plural | _rest] -> - Map.merge(config, %{schema_name: schema_name, schema_plural: schema_plural}) - - _ -> - config - end + parsed + |> PowAssent.validate_schema_args!(@mix_task) + |> Map.merge(config) end - defp create_schema_file(%{binary_id: binary_id} = config) do - context_app = Map.get(config, :context_app, Pow.context_app()) - context_base = Pow.context_base(context_app) - schema_name = Map.get(config, :schema_name, "UserIdentities.UserIdentity") - schema_plural = Map.get(config, :schema_plural, "user_identities") - schema = SchemaModule.new(context_base, schema_name, schema_plural, binary_id: binary_id) - content = SchemaModule.gen(schema) - dir_name = - schema.schema_name - |> String.split(".") - |> Enum.slice(0..-2) - |> Enum.join(".") - |> Macro.underscore() - file_name = - schema.module - |> Module.split() - |> List.last() - |> Macro.underscore() - |> Kernel.<>(".ex") + defp create_schema_file(%{binary_id: binary_id, schema_name: schema_name, schema_plural: schema_plural} = config) do + context_app = Map.get(config, :context_app) || Pow.otp_app() + context_base = Pow.app_base(context_app) + schema = SchemaModule.new(context_base, schema_name, schema_plural, binary_id: binary_id) + content = SchemaModule.gen(schema) + dir_name = dir_name(schema_name) + file_name = file_name(schema.module) context_app |> Pow.context_lib_path(dir_name) @@ -64,6 +57,22 @@ defmodule Mix.Tasks.PowAssent.Ecto.Gen.Schema do |> Generator.create_file(content) end + defp dir_name(schema_name) do + schema_name + |> String.split(".") + |> Enum.slice(0..-2) + |> Enum.join(".") + |> Macro.underscore() + end + + defp file_name(module) do + module + |> Module.split() + |> List.last() + |> Macro.underscore() + |> Kernel.<>(".ex") + end + defp maybe_create_directory(path) do Generator.create_directory(path) diff --git a/lib/mix/tasks/ecto/pow_assent.ecto.install.ex b/lib/mix/tasks/ecto/pow_assent.ecto.install.ex index 86536ef..b020b25 100644 --- a/lib/mix/tasks/ecto/pow_assent.ecto.install.ex +++ b/lib/mix/tasks/ecto/pow_assent.ecto.install.ex @@ -5,26 +5,40 @@ defmodule Mix.Tasks.PowAssent.Ecto.Install do Generates user identity schema and migration file. mix pow_assent.ecto.install -r MyApp.Repo + + mix pow_assent.ecto.install -r MyApp.Repo Accounts.Identity identities + + See `Mix.Tasks.PowAssent.Ecto.Gen.Schema` and + `Mix.Tasks.PowAssent.Ecto.Gen.Migration` for more. """ use Mix.Task alias Mix.Tasks.PowAssent.Ecto.Gen.Schema, as: SchemaTask alias Mix.Tasks.PowAssent.Ecto.Gen.Migration, as: MigrationTask - alias Mix.Pow + alias Mix.{Pow, PowAssent} @switches [] @default_opts [] + @mix_task "pow_assent.ecto.install" - @doc false + @impl true def run(args) do - Pow.no_umbrella!("pow_assent.ecto.install") + Pow.no_umbrella!(@mix_task) args |> Pow.parse_options(@switches, @default_opts) + |> parse() |> run_gen_migration(args) |> run_gen_schema(args) end + + defp parse({config, parsed, _invalid}) do + PowAssent.validate_schema_args!(parsed, @mix_task) + + config + end + defp run_gen_migration(config, args) do MigrationTask.run(args) diff --git a/lib/mix/tasks/phoenix/pow_assent.phoenix.gen.templates.ex b/lib/mix/tasks/phoenix/pow_assent.phoenix.gen.templates.ex index 8838625..6d9e67a 100644 --- a/lib/mix/tasks/phoenix/pow_assent.phoenix.gen.templates.ex +++ b/lib/mix/tasks/phoenix/pow_assent.phoenix.gen.templates.ex @@ -6,9 +6,11 @@ defmodule Mix.Tasks.PowAssent.Phoenix.Gen.Templates do mix pow_assent.phoenix.gen.templates + mix pow_assent.phoenix.gen.templates --context-app my_app + ## Arguments - * `--context-app MyApp` app to use for path and module names + * `--context-app` app to use for path and module names """ use Mix.Task @@ -17,14 +19,13 @@ defmodule Mix.Tasks.PowAssent.Phoenix.Gen.Templates do @switches [context_app: :string] @default_opts [] - @doc false + @impl true def run(args) do Pow.no_umbrella!("pow_assent.phoenix.gen.templates") args |> Pow.parse_options(@switches, @default_opts) |> create_template_files() - |> print_shell_instructions() end @templates [ @@ -33,7 +34,6 @@ defmodule Mix.Tasks.PowAssent.Phoenix.Gen.Templates do defp create_template_files({config, _parsed, _invalid}) do structure = Phoenix.parse_structure(config) - context_base = structure[:context_base] web_module = structure[:web_module] web_prefix = structure[:web_prefix] @@ -42,27 +42,6 @@ defmodule Mix.Tasks.PowAssent.Phoenix.Gen.Templates do Phoenix.create_templates(Elixir.PowAssent, name, web_prefix, actions) end) - %{context_base: context_base, web_module: web_module} - end - - defp print_shell_instructions(%{context_base: context_base, web_module: web_base}) do - Mix.shell.info(""" - PowAssent Phoenix templates and views has been generated. - - Please set `web_module: #{inspect(web_base)}` in your configuration. - - defmodule #{inspect(web_base)}.Endpoint do - use #{inspect(web_base)}.Endpoint, otp_app: :#{Macro.underscore(context_base)} - - # ... - - plug #{inspect(web_base)}.Pow.Plug.Session, - repo: #{inspect(context_base)}.Repo, - user: #{inspect(context_base)}.Users.User, - web_module: #{inspect(web_base)} - - # ... - end - """) + %{structure: structure} end end diff --git a/lib/mix/tasks/pow_assent.install.ex b/lib/mix/tasks/pow_assent.install.ex index 39cbcff..33ca70b 100644 --- a/lib/mix/tasks/pow_assent.install.ex +++ b/lib/mix/tasks/pow_assent.install.ex @@ -5,11 +5,16 @@ defmodule Mix.Tasks.PowAssent.Install do Will generate PowAssent migration file. mix pow_assent.install -r MyApp.Repo + + mix pow_assent.install -r MyApp.Repo Accounts.Identity identities + + See `Mix.Tasks.PowAssent.Ecto.Install` for more. """ use Mix.Task alias Mix.Project alias Mix.Tasks.PowAssent.Ecto.Install + @mix_task "pow_assent.install" @doc false def run(args) do @@ -24,7 +29,12 @@ defmodule Mix.Tasks.PowAssent.Install do defp no_umbrella! do if Project.umbrella?() do - Mix.raise("mix pow_assent.install can't be used in umbrella apps. Run mix pow_assent.ecto.install in your ecto app directory.") + Mix.raise( + """ + mix #{@mix_task} has to be used inside an application directory, but this is an umbrella project. + + Run mix pow_assent.ecto.install inside your Ecto application directory to create schema module and migrations. + """) end :ok diff --git a/mix.exs b/mix.exs index d264cb5..d3cc7e5 100644 --- a/mix.exs +++ b/mix.exs @@ -33,7 +33,7 @@ defmodule PowAssent.MixProject do defp deps do [ - {:pow, "~> 1.0.3"}, + {:pow, "~> 1.0.4"}, {:oauther, "~> 1.1"}, diff --git a/mix.lock b/mix.lock index b545284..6464c48 100644 --- a/mix.lock +++ b/mix.lock @@ -25,7 +25,7 @@ "nimble_parsec": {:hex, :nimble_parsec, "0.4.0", "ee261bb53214943679422be70f1658fff573c5d0b0a1ecd0f18738944f818efe", [:mix], [], "hexpm"}, "oauther": {:hex, :oauther, "1.1.1", "7d8b16167bb587ecbcddd3f8792beb9ec3e7b65c1f8ebd86b8dd25318d535752", [:mix], [], "hexpm"}, "parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm"}, - "phoenix": {:hex, :phoenix, "1.4.1", "801f9d632808657f1f7c657c8bbe624caaf2ba91429123ebe3801598aea4c3d9", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 1.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 1.0 or ~> 2.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}], "hexpm"}, + "phoenix": {:hex, :phoenix, "1.4.2", "3a1250f22010daeee265923bae02f10b5434b569b999c1b18100b5da05834d93", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 1.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 1.0 or ~> 2.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}], "hexpm"}, "phoenix_ecto": {:hex, :phoenix_ecto, "4.0.0", "c43117a136e7399ea04ecaac73f8f23ee0ffe3e07acfcb8062fe5f4c9f0f6531", [:mix], [{:ecto, "~> 3.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.9", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"}, "phoenix_html": {:hex, :phoenix_html, "2.13.1", "fa8f034b5328e2dfa0e4131b5569379003f34bc1fafdaa84985b0b9d2f12e68b", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"}, "phoenix_pubsub": {:hex, :phoenix_pubsub, "1.1.2", "496c303bdf1b2e98a9d26e89af5bba3ab487ba3a3735f74bf1f4064d2a845a3e", [:mix], [], "hexpm"}, @@ -33,7 +33,7 @@ "plug_cowboy": {:hex, :plug_cowboy, "2.0.1", "d798f8ee5acc86b7d42dbe4450b8b0dadf665ce588236eb0a751a132417a980e", [:mix], [{:cowboy, "~> 2.5", [hex: :cowboy, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"}, "plug_crypto": {:hex, :plug_crypto, "1.0.0", "18e49317d3fa343f24620ed22795ec29d4a5e602d52d1513ccea0b07d8ea7d4d", [:mix], [], "hexpm"}, "postgrex": {:hex, :postgrex, "0.14.0", "f3d6ffea1ca8a156e0633900a5338a3d17b00435227726baed8982718232b694", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"}, - "pow": {:hex, :pow, "1.0.3", "35608eed84abbcfcff5bac05b722ed4a4bb865c5154066cda6816f5bcb8353c9", [:mix], [{:ecto, "~> 2.2 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.3.0 or ~> 1.4.0", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, ">= 2.0.0 and <= 3.0.0", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:plug, ">= 1.5.0 and < 1.8.0", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm"}, + "pow": {:hex, :pow, "1.0.4", "8186c3eca543b5c38511c3c684e8eec951a024a324cc7c2b07e712df8cb8c64b", [:mix], [{:ecto, "~> 2.2 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.3.0 or ~> 1.4.0", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, ">= 2.0.0 and <= 3.0.0", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:plug, ">= 1.5.0 and < 1.8.0", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm"}, "ranch": {:hex, :ranch, "1.7.1", "6b1fab51b49196860b733a49c07604465a47bdb78aa10c1c16a3d199f7f8c881", [:rebar3], [], "hexpm"}, "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.4", "f0eafff810d2041e93f915ef59899c923f4568f4585904d010387ed74988e77b", [:make, :mix, :rebar3], [], "hexpm"}, "telemetry": {:hex, :telemetry, "0.2.0", "5b40caa3efe4deb30fb12d7cd8ed4f556f6d6bd15c374c2366772161311ce377", [:mix], [], "hexpm"}, diff --git a/test/mix/tasks/ecto/pow_assent.ecto.gen.schema_test.exs b/test/mix/tasks/ecto/pow_assent.ecto.gen.schema_test.exs index eddac7a..ccf6cea 100644 --- a/test/mix/tasks/ecto/pow_assent.ecto.gen.schema_test.exs +++ b/test/mix/tasks/ecto/pow_assent.ecto.gen.schema_test.exs @@ -27,16 +27,6 @@ defmodule Mix.Tasks.PowAssent.Ecto.Gen.SchemaTest do end) end - test "generates with :context_app" do - options = ~w(--context-app pow_assent) - - File.cd!(@tmp_path, fn -> - Schema.run(options) - - assert File.exists?(@expected_file) - end) - end - test "generates with :binary_id" do options = ~w(--binary-id) diff --git a/test/mix/tasks/phoenix/pow_assent.phoenix.gen.templates_test.exs b/test/mix/tasks/phoenix/pow_assent.phoenix.gen.templates_test.exs index f1e4ff2..ed92233 100644 --- a/test/mix/tasks/phoenix/pow_assent.phoenix.gen.templates_test.exs +++ b/test/mix/tasks/phoenix/pow_assent.phoenix.gen.templates_test.exs @@ -8,7 +8,7 @@ defmodule Mix.Tasks.PowAssent.Phoenix.Gen.TemplatesTest do @expected_template_files %{ "registration" => ["add_user_id.html.eex"] } - @expected_views @expected_template_files |> Map.keys() + @expected_views Map.keys(@expected_template_files) setup do File.rm_rf!(@tmp_path) @@ -38,39 +38,6 @@ defmodule Mix.Tasks.PowAssent.Phoenix.Gen.TemplatesTest do assert ls(views_path) == expected_view_files assert view_content =~ "defmodule PowAssentWeb.PowAssent.RegistrationView do" assert view_content =~ "use PowAssentWeb, :view" - - assert_received {:mix_shell, :info, ["PowAssent Phoenix templates and views has been generated." <> msg]} - assert msg =~ "defmodule PowAssentWeb.Endpoint" - assert msg =~ "otp_app: :pow" - assert msg =~ "repo: PowAssent.Repo" - assert msg =~ "user: PowAssent.Users.User" - assert msg =~ "web_module: PowAssentWeb" - end) - end - - test "generates with :context_app" do - options = ~w(--context-app test) - - File.cd!(@tmp_path, fn -> - Templates.run(options) - - templates_path = Path.join(["lib", "test_web", "templates", "pow_assent"]) - dirs = templates_path |> File.ls!() |> Enum.sort() - - assert dirs == Map.keys(@expected_template_files) - - views_path = Path.join(["lib", "test_web", "views", "pow_assent"]) - view_content = views_path |> Path.join("registration_view.ex") |> File.read!() - - assert view_content =~ "defmodule TestWeb.PowAssent.RegistrationView do" - assert view_content =~ "use TestWeb, :view" - - assert_received {:mix_shell, :info, ["PowAssent Phoenix templates and views has been generated." <> msg]} - assert msg =~ "defmodule TestWeb.Endpoint" - assert msg =~ "otp_app: :test" - assert msg =~ "repo: Test.Repo" - assert msg =~ "user: Test.Users.User" - assert msg =~ "web_module: TestWeb" end) end diff --git a/test/mix/tasks/pow_assent.install_test.exs b/test/mix/tasks/pow_assent.install_test.exs index 7f0b156..e5f4667 100644 --- a/test/mix/tasks/pow_assent.install_test.exs +++ b/test/mix/tasks/pow_assent.install_test.exs @@ -12,9 +12,19 @@ defmodule Mix.Tasks.PowAssent.InstallTest do :ok end - test "runs" do + test "generates files" do File.cd!(@tmp_path, fn -> Install.run([]) + + assert File.ls!("lib/pow_assent/user_identities") == ["user_identity.ex"] + end) + end + + test "with schema name and table" do + File.cd!(@tmp_path, fn -> + Install.run(~w(Accounts.Identity identities)) + + assert File.ls!("lib/pow_assent/accounts") == ["identity.ex"] end) end @@ -31,10 +41,30 @@ defmodule Mix.Tasks.PowAssent.InstallTest do """) Mix.Project.in_project(:umbrella, ".", fn _ -> - assert_raise Mix.Error, "mix pow_assent.install can't be used in umbrella apps. Run mix pow_assent.ecto.install in your ecto app directory.", fn -> + assert_raise Mix.Error, ~r/mix pow_assent.install has to be used inside an application directory/, fn -> Install.run([]) end end) end) end + + test "raises error on invalid schema name or table" do + File.cd!(@tmp_path, fn -> + assert_raise Mix.Error, ~r/Invalid arguments/, fn -> + Install.run(~w(UserIdentities.UserIdentity)) + end + + assert_raise Mix.Error, ~r/Expected the schema argument, "useridentities.useridentity", to be a valid module name/, fn -> + Install.run(~w(useridentities.useridentity useridentities)) + end + + assert_raise Mix.Error, ~r/Expected the plural argument, "UserIdentities", to be all lowercase using snake_case convention/, fn -> + Install.run(~w(UserIdentities.UserIdentity UserIdentities)) + end + + assert_raise Mix.Error, ~r/Expected the plural argument, "useridentities:", to be all lowercase using snake_case convention/, fn -> + Install.run(~w(UserIdentities.UserIdentity useridentities:)) + end + end) + end end