Skip to content

Commit

Permalink
Merge pull request #41 from dwyl/schema-underscore
Browse files Browse the repository at this point in the history
Schema underscore
  • Loading branch information
nelsonic authored Dec 22, 2018
2 parents 9871884 + 8d11bb6 commit 582d42c
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/autoform.ex
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ defmodule Autoform do
end

defp schema_name(schema) do
schema |> to_string() |> Macro.underscore() |> String.split(".") |> List.last()
schema |> to_string() |> String.split(".") |> List.last() |> Macro.underscore()
end

defp submit_btn_txt(assigns, options) do
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Autoform.MixProject do
def project do
[
app: :autoform,
version: "0.6.1",
version: "0.6.4",
elixir: "~> 1.7",
elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :prod,
Expand Down
9 changes: 9 additions & 0 deletions test/autoform_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,14 @@ defmodule AutoformControllerTest do

refute response =~ "age"
end

test "multipe words schema", %{conn: conn} do
assert response =
conn
|> get(do_what_you_love_path(conn, :new))
|> html_response(200)

assert response =~ "do_what_you_love_name"
end
end
end
17 changes: 17 additions & 0 deletions test/support/test_autoform/lib/test_autoform/DoWhatYouLove.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
defmodule TestAutoform.DoWhatYouLove do
use Ecto.Schema
import Ecto.Changeset

schema "do_what_you_love" do
field(:name, :string)

timestamps()
end

@doc false
def changeset(user, attrs) do
user
|> cast(attrs, [:name])
|> validate_required([:name])
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
defmodule TestAutoformWeb.DoWhatYouLoveController do
use TestAutoformWeb, :controller
use Autoform

alias TestAutoform.DoWhatYouLove

def new(conn, _params) do
changeset = DoWhatYouLove.changeset(%DoWhatYouLove{}, %{})

render_autoform(conn, :create, DoWhatYouLove, assigns: [changeset: changeset])
end

end
1 change: 1 addition & 0 deletions test/support/test_autoform/lib/test_autoform_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ defmodule TestAutoformWeb.Router do
resources("/sample_products", SampleProductController)
get("/custom_no_path", CustomController, :new_no_path)
get("/custom_new_product", CustomController, :new_product)
resources("/do_what_you_love", DoWhatYouLoveController)
end

# Other scopes may use custom stacks.
Expand Down

0 comments on commit 582d42c

Please sign in to comment.