Repository: phoenixframework/phoenix (elixir)

Issue:
`mix phx.new.web app_name` and mix `mix phx.gen.html` conflicts if app_name is not suffixed with `_web`
### Environment

* Elixir version (elixir -v): 1.5.2
* Phoenix version (mix deps): 1.3.0
* NodeJS version (node -v): 8.4.0
* NPM version (npm -v): 5.5.1
* Operating system: macOS Sierra 10.12.6

### Expected behavior
 `mix phx.new.web app_name` and mix `mix phx.gen.html` work fine together, no matter what the app_name is.

If for example the app name is `foo_web` and you run `mix phx.new.web foo_web` and `mix phx.gen.html Account User users name: string` everything works as expected.

### Actual behaviour
 `mix phx.new.web app_name` and mix `mix phx.gen.html` conflicts if app_name is not suffixed with `_web`

If for example the app name is `foo` and you run `mix phx.new.web foo` and `mix phx.gen.html Account User users name: string` the controller contains the namespace `FooWeb.UserController` and uses `use FooWeb, :controller` however `FooWeb` does not exist since the app name is `Foo`. The PageController (generated with the creation of the app) does this right however.

Same problem occurs in `FooWeb.UserView`

### Possible solutions
- Force the developer to suffix his app_name with `_web` when using `mix phx.new.web`, raise if not.
- Automatically suffix app_name with `_web` when creating new web app. (Or prompt developer for it)
- Remove suffixing with `_web` when building context struct: https://github.com/phoenixframework/phoenix/blob/d36148ae7b6570d45227abaabd2af9740beff542/lib/mix/phoenix/context.ex#L77-L84




Pull request description:
Fix issue when umbrella apps don’t use `web` in the name
When Phoenix is added to an umbrella app with a name that doesn't contain `web`, it maintains that name with the generators when using a separate context app.

Fixes #2656.

Patch:
diff --git a/lib/mix/phoenix/context.ex b/lib/mix/phoenix/context.ex
index e7c92dece..d0bae4c37 100644
--- a/lib/mix/phoenix/context.ex
+++ b/lib/mix/phoenix/context.ex
@@ -76,10 +76,15 @@ defmodule Mix.Phoenix.Context do
 
   defp web_module do
     base = Mix.Phoenix.base()
-    if String.ends_with?(base, "Web") do
-      Module.concat([base])
-    else
-      Module.concat(["#{base}Web"])
+    cond do
+      Mix.Phoenix.context_app() != Mix.Phoenix.otp_app() ->
+        Module.concat([base])
+
+      String.ends_with?(base, "Web") ->
+        Module.concat([base])
+
+      true ->
+        Module.concat(["#{base}Web"])
     end
   end
 end


Test patch:
diff --git a/test/mix/tasks/phx.gen.html_test.exs b/test/mix/tasks/phx.gen.html_test.exs
index 5c4d3292d..c098f6d47 100644
--- a/test/mix/tasks/phx.gen.html_test.exs
+++ b/test/mix/tasks/phx.gen.html_test.exs
@@ -313,17 +313,17 @@ defmodule Mix.Tasks.Phx.Gen.HtmlTest do
         assert_file "another_app/lib/another_app/accounts/user.ex"
 
         assert_file "lib/phoenix/controllers/user_controller.ex", fn file ->
-          assert file =~ "defmodule PhoenixWeb.UserController"
-          assert file =~ "use PhoenixWeb, :controller"
+          assert file =~ "defmodule Phoenix.UserController"
+          assert file =~ "use Phoenix, :controller"
         end
 
         assert_file "lib/phoenix/templates/user/form.html.eex"
         assert_file "lib/phoenix/views/user_view.ex", fn file ->
-          assert file =~ "defmodule PhoenixWeb.UserView"
+          assert file =~ "defmodule Phoenix.UserView"
         end
 
         assert_file "test/phoenix/controllers/user_controller_test.exs", fn file ->
-          assert file =~ "defmodule PhoenixWeb.UserControllerTest"
+          assert file =~ "defmodule Phoenix.UserControllerTest"
         end
       end
     end
diff --git a/test/mix/tasks/phx.gen.json_test.exs b/test/mix/tasks/phx.gen.json_test.exs
index cf310cd25..eb370ec68 100644
--- a/test/mix/tasks/phx.gen.json_test.exs
+++ b/test/mix/tasks/phx.gen.json_test.exs
@@ -217,16 +217,16 @@ defmodule Mix.Tasks.Phx.Gen.JsonTest do
         assert_file "another_app/lib/another_app/accounts/user.ex"
 
         assert_file "lib/phoenix/controllers/user_controller.ex", fn file ->
-          assert file =~ "defmodule PhoenixWeb.UserController"
-          assert file =~ "use PhoenixWeb, :controller"
+          assert file =~ "defmodule Phoenix.UserController"
+          assert file =~ "use Phoenix, :controller"
         end
 
         assert_file "lib/phoenix/views/user_view.ex", fn file ->
-          assert file =~ "defmodule PhoenixWeb.UserView"
+          assert file =~ "defmodule Phoenix.UserView"
         end
 
         assert_file "test/phoenix/controllers/user_controller_test.exs", fn file ->
-          assert file =~ "defmodule PhoenixWeb.UserControllerTest"
+          assert file =~ "defmodule Phoenix.UserControllerTest"
         end
       end
     end