Repository: phoenixframework/phoenix
Pull request #2165 (2017-03-06 23:11:49)

Documentation for options on gen.{context, html, json}
Addressing #2138 


Patch:
diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md
index c49751684..1c87e8848 100644
--- a/ISSUE_TEMPLATE.md
+++ b/ISSUE_TEMPLATE.md
@@ -1,3 +1,4 @@
+<!--
 ### Precheck
 
 * For help and support, use Stack Overflow or the Phoenix Talk mailing list
@@ -5,6 +6,7 @@
 * For bugs, do a quick search and make sure the bug has not yet been reported
 * Ensure that this issue is related to the Phoenix library and not one of the dependencies listed in mix.exs (Ecto, Plug, etc.)
 * All checked? Be nice and have fun!
+-->
 
 ### Environment
 
diff --git a/lib/mix/tasks/phx.gen.context.ex b/lib/mix/tasks/phx.gen.context.ex
index 91b6db203..494d4984f 100644
--- a/lib/mix/tasks/phx.gen.context.ex
+++ b/lib/mix/tasks/phx.gen.context.ex
@@ -26,14 +26,35 @@ defmodule Mix.Tasks.Phx.Gen.Context do
   A migration file for the repository and test files for the context
   will also be generated.
 
-  ## Schema options
+  ## table
 
-  By deault, the schema table name will be the plural name, namespaced by the
-  context name. You can customize this value by providing the `--table`
-  option to the generator.
+  By default, the table name for the migration and schema will be
+  the plural name provided for the resource, namespaced by the context name,
+  To customize this value, a `--table` option may be provided. For example:
+
+      mix phx.gen.context Accounts User users --table cms_users
+
+  ## binary_id
+
+  Generated migration can use `binary_id` for schema's primary key
+  and its references with option `--binary-id`.
+
+  ## Default options
+
+  This generator uses default options provided in the `:generators`
+  configuration of your application. These are the defaults:
+
+      config :your_app, :generators,
+        migration: true,
+        binary_id: false,
+        sample_binary_id: "11111111-1111-1111-1111-111111111111"
+
+  You can override those options per invocation by providing corresponding
+  switches, e.g. `--no-binary-id` to use normal ids despite the default
+  configuration or `--migration` to force generation of the migration.
 
   Read the documentation for `phx.gen.schema` for more information on
-  attributes and supported options.
+  attributes.
   """
 
   use Mix.Task
diff --git a/lib/mix/tasks/phx.gen.html.ex b/lib/mix/tasks/phx.gen.html.ex
index a7554ea03..c6acfe17e 100644
--- a/lib/mix/tasks/phx.gen.html.ex
+++ b/lib/mix/tasks/phx.gen.html.ex
@@ -29,14 +29,35 @@ defmodule Mix.Tasks.Phx.Gen.Html do
   A migration file for the repository and test files for the context and
   controller features will also be generated.
 
-  ## Schema options
+  ## table
 
-  By deault, the schema table name will be the plural name, namespaced by the
-  context name. You can customize this value by providing the `--table`
-  option to the generator.
+  By default, the table name for the migration and schema will be
+  the plural name provided for the resource. To customize this value,
+  a `--table` option may be provided. For example:
+
+      mix phx.gen.html Accounts User users --table cms_users
+
+  ## binary_id
+
+  Generated migration can use `binary_id` for schema's primary key
+  and its references with option `--binary-id`.
+
+  ## Default options
+
+  This generator uses default options provided in the `:generators`
+  configuration of your application. These are the defaults:
+
+      config :your_app, :generators,
+        migration: true,
+        binary_id: false,
+        sample_binary_id: "11111111-1111-1111-1111-111111111111"
+
+  You can override those options per invocation by providing corresponding
+  switches, e.g. `--no-binary-id` to use normal ids despite the default
+  configuration or `--migration` to force generation of the migration.
 
   Read the documentation for `phx.gen.schema` for more information on
-  attributes and supported options.
+  attributes.
   """
   use Mix.Task
 
diff --git a/lib/mix/tasks/phx.gen.json.ex b/lib/mix/tasks/phx.gen.json.ex
index 48ab0e878..3c1a1e812 100644
--- a/lib/mix/tasks/phx.gen.json.ex
+++ b/lib/mix/tasks/phx.gen.json.ex
@@ -28,14 +28,35 @@ defmodule Mix.Tasks.Phx.Gen.Json do
   A migration file for the repository and test files for the context and
   controller features will also be generated.
 
-  ## Schema options
+  ## table
 
-  By deault, the schema table name will be the plural name, namespaced by the
-  context name. You can customize this value by providing the `--table`
-  option to the generator.
+  By default, the table name for the migration and schema will be
+  the plural name provided for the resource. To customize this value,
+  a `--table` option may be provided. For example:
+
+      mix phx.gen.json Accounts User users --table cms_users
+
+  ## binary_id
+
+  Generated migration can use `binary_id` for schema's primary key
+  and its references with option `--binary-id`.
+
+  ## Default options
+
+  This generator uses default options provided in the `:generators`
+  configuration of your application. These are the defaults:
+
+      config :your_app, :generators,
+        migration: true,
+        binary_id: false,
+        sample_binary_id: "11111111-1111-1111-1111-111111111111"
+
+  You can override those options per invocation by providing corresponding
+  switches, e.g. `--no-binary-id` to use normal ids despite the default
+  configuration or `--migration` to force generation of the migration.
 
   Read the documentation for `phx.gen.schema` for more information on
-  attributes and supported options.
+  attributes.
   """
 
   use Mix.Task
diff --git a/lib/mix/tasks/phx.gen.schema.ex b/lib/mix/tasks/phx.gen.schema.ex
index 781fc4907..98de0654e 100644
--- a/lib/mix/tasks/phx.gen.schema.ex
+++ b/lib/mix/tasks/phx.gen.schema.ex
@@ -54,7 +54,7 @@ defmodule Mix.Tasks.Phx.Gen.Schema do
 
   By default, the table name for the migration and schema will be
   the plural name provided for the resource. To customize this value,
-  a `--table` option may be provided. For exampe:
+  a `--table` option may be provided. For example:
 
       mix phx.gen.schema Blog.Post posts --table cms_posts
 
diff --git a/priv/templates/phx.gen.context/schema_access.ex b/priv/templates/phx.gen.context/schema_access.ex
index c7354ff6e..9bf545e83 100644
--- a/priv/templates/phx.gen.context/schema_access.ex
+++ b/priv/templates/phx.gen.context/schema_access.ex
@@ -35,10 +35,10 @@
 
   ## Examples
 
-      iex> create_<%= schema.singular %>(<%= schema.singular %>, %{field: value})
+      iex> create_<%= schema.singular %>(%{field: value})
       {:ok, %<%= inspect schema.alias %>{}}
 
-      iex> create_<%= schema.singular %>(<%= schema.singular %>, %{field: bad_value})
+      iex> create_<%= schema.singular %>(%{field: bad_value})
       {:error, %Ecto.Changeset{}}
 
   """


Test patch:
diff --git a/priv/templates/phx.gen.context/context_test.exs b/priv/templates/phx.gen.context/context_test.exs
index 6e8d6775b..db71abf49 100644
--- a/priv/templates/phx.gen.context/context_test.exs
+++ b/priv/templates/phx.gen.context/context_test.exs
@@ -24,8 +24,7 @@ defmodule <%= inspect context.module %>Test do
   end
 
   test "create_<%= schema.singular %>/1 with valid data creates a <%= schema.singular %>" do
-    assert {:ok, %<%= inspect schema.alias %>{} = <%= schema.singular %>} = <%= inspect context.alias %>.create_<%= schema.singular %>(@create_attrs)
-    <%= for {field, value} <- schema.params.create do %>
+    assert {:ok, %<%= inspect schema.alias %>{} = <%= schema.singular %>} = <%= inspect context.alias %>.create_<%= schema.singular %>(@create_attrs)<%= for {field, value} <- schema.params.create do %>
     assert <%= schema.singular %>.<%= field %> == <%= inspect value %><% end %>
   end
 
@@ -36,8 +35,7 @@ defmodule <%= inspect context.module %>Test do
   test "update_<%= schema.singular %>/2 with valid data updates the <%= schema.singular %>" do
     <%= schema.singular %> = fixture(:<%= schema.singular %>)
     assert {:ok, <%= schema.singular %>} = <%= inspect context.alias %>.update_<%= schema.singular %>(<%= schema.singular %>, @update_attrs)
-    assert %<%= inspect schema.alias %>{} = <%= schema.singular %>
-    <%= for {field, value} <- schema.params.update do %>
+    assert %<%= inspect schema.alias %>{} = <%= schema.singular %><%= for {field, value} <- schema.params.update do %>
     assert <%= schema.singular %>.<%= field %> == <%= inspect value %><% end %>
   end