From 1ef786390d2c8f0cd49b90b4e8c5a335f5cab028 Mon Sep 17 00:00:00 2001 From: Alexander Anich Date: Tue, 17 Oct 2017 17:18:07 -1000 Subject: [PATCH 1/2] fix(mix): change expected filename when attempting to detect the correct phoenix version --- lib/mix/talon.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/mix/talon.ex b/lib/mix/talon.ex index d68bd51..c5b7dae 100644 --- a/lib/mix/talon.ex +++ b/lib/mix/talon.ex @@ -144,10 +144,10 @@ defmodule Mix.Talon do @spec detect_project_structure() :: :phx | :phoenix | :unknown def detect_project_structure do - phx_dir = otp_app_path() + phx_web_root = otp_app_path() <> "_web" cond do File.exists?("web") -> :phoenix - Path.join(["lib", phx_dir, "web"]) |> File.exists? -> :phx + Path.join(["lib", phx_web_root]) |> File.exists? -> :phx true -> :unknown end end From 12858000e48c06fd77901398ecaf822333a875d8 Mon Sep 17 00:00:00 2001 From: Alexander Anich Date: Tue, 17 Oct 2017 17:19:09 -1000 Subject: [PATCH 2/2] test(mix/tasks): create failing case where the namespace of a module should be stripped when generat --- test/mix/tasks/talon.gen.resource_test.exs | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/mix/tasks/talon.gen.resource_test.exs b/test/mix/tasks/talon.gen.resource_test.exs index bb4af34..6683e58 100644 --- a/test/mix/tasks/talon.gen.resource_test.exs +++ b/test/mix/tasks/talon.gen.resource_test.exs @@ -84,6 +84,34 @@ defmodule Mix.Tasks.Talon.Gen.ResourceTest do ] end end + + test "strip app namespace if provided" do + Logger.disable(self()) + + Application.put_env(:phx_blogger, PhxBlogger.Web.Endpoint, + secret_key_base: String.duplicate("abcdefgh", 8), + code_reloader: true, + root: File.cwd!) + + in_tmp "strip_app_namespace", fn -> + Mix.Tasks.Phx.New.run([@app_name, "--no-ecto"]) + end + + in_project :phx_blogger, Path.join(tmp_path(), "strip_app_namespace/phx_blogger"), fn _ -> + Mix.Task.clear + GenNew.run [] #{ }~w(--phx) + + Mix.Task.clear + GenResource.run ["PhxBlogger.Blogs.Post"] + root_path = Path.join(["lib", "phx_blogger", "talon"]) + concern_path = Path.join([root_path, "admin"]) + + assert_file Path.join(concern_path, "post.ex"), [ + "defmodule PhxBlogger.Admin.Blogs.Post do", + "use Talon.Resource, schema: PhxBlogger.Blogs.Post, concern: PhxBlogger.Admin" + ] + end + end end describe "phoenix structure" do