Skip to content

Commit

Permalink
Build admin paths using model_name helper
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinClowers committed Mar 13, 2017
1 parent 398889f commit 6a321d5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/ex_admin/utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ defmodule ExAdmin.Utils do
admin_resource_path(conn.assigns.resource.__struct__, method, args)
end
def admin_resource_path(resource_model, method, args) when is_atom(resource_model) do
resource_name = resource_model |> ExAdmin.Utils.base_name |> Inflex.underscore |> Inflex.pluralize
resource_name = resource_model |> ExAdmin.Helpers.model_name |> Inflex.pluralize
apply(router(), :admin_resource_path, [endpoint(), method || :index, resource_name | args])
end
def admin_resource_path(resource, method, args) when is_map(resource) do
Expand Down
6 changes: 3 additions & 3 deletions test/controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,16 @@ defmodule ExAdminTest.ControllerTest do
test "restricted actions" do
restricted = insert_restricted()

conn = get build_conn(), admin_resource_path(Restricted, :index)
conn = get build_conn(), admin_resource_path(TestExAdmin.Restricted, :index)
assert html_response(conn, 200) =~ ~r/Simple/

conn = get build_conn(), admin_resource_path(Restricted, :new)
conn = get build_conn(), admin_resource_path(TestExAdmin.Restricted, :new)
assert html_response(conn, 403) =~ ~r/Forbidden Request/

conn = get build_conn(), admin_resource_path(restricted, :edit), %{}
assert html_response(conn, 403) =~ ~r/Forbidden Request/

conn = post build_conn(), ExAdmin.Utils.admin_resource_path(Restricted, :create)
conn = post build_conn(), ExAdmin.Utils.admin_resource_path(TestExAdmin.Restricted, :create)
assert html_response(conn, 403) =~ ~r/Forbidden Request/

conn = delete build_conn(), admin_resource_path(restricted, :destroy)
Expand Down

0 comments on commit 6a321d5

Please sign in to comment.