Skip to content

Commit

Permalink
Support for customized model name addressing #65
Browse files Browse the repository at this point in the history
Enables 'display_name "Name"' in an AdminModel
  • Loading branch information
mbrookes committed Nov 20, 2014
1 parent adce922 commit 6d1684e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
8 changes: 7 additions & 1 deletion lib/upmin/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,12 @@ def Model.model_name
end

def Model.humanized_name(type = :plural)
names = model_class_name.split(/(?=[A-Z])/).map{|n| n.gsub(":", "")}
names = @display_name ? [@display_name] : model_class_name.split(/(?=[A-Z])/).map{|n| n.gsub(":", "")}

if type == :plural
names[names.length-1] = names.last.pluralize
end

return names.join(" ")
end

Expand Down Expand Up @@ -286,6 +288,10 @@ def Model.items_per_page(items = Upmin.configuration.items_per_page)
return @items_per_page ||= items
end

def Model.display_name (name)
return @display_name ||= name
end


###########################################################
### Methods that need to be to be overridden. If the
Expand Down
2 changes: 1 addition & 1 deletion spec/features/edit_model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
click_button("Save")

within(".alert.alert-danger") do
expect(page).to(have_content("User was NOT updated."))
expect(page).to(have_content("Customer was NOT updated."))
expect(page).to(have_selector("li", text: /email/i))
end

Expand Down
8 changes: 4 additions & 4 deletions spec/features/navbar_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
visit ("/upmin")

within(".navbar ul.nav") do
expect(page).to(have_selector("li", text: "Users"))
expect(page).to(have_selector("li", text: "Customers"))
expect(page).to(have_selector("li", text: "Products"))
expect(page).to(have_selector("li", text: "Orders"))
expect(page).to(have_selector("li", text: "Product Orders"))
expect(page).to(have_selector("li", text: "Shipments"))

click_link("Users")
click_link("Customers")
end

expect(page).to(have_selector(".upmin-model", minimum: 10))
Expand All @@ -30,13 +30,13 @@
visit ("/upmin")

within(".navbar ul.nav") do
expect(page).to(have_selector("li", text: "Users"))
expect(page).to(have_selector("li", text: "Customers"))
expect(page).to(have_selector("li", text: "Products"))
expect(page).not_to(have_selector("li", text: "Orders"))
expect(page).not_to(have_selector("li", text: "Product Orders"))
expect(page).not_to(have_selector("li", text: "Shipments"))

click_link("Users")
click_link("Customers")
end

expect(page).to(have_selector(".upmin-model", minimum: 10))
Expand Down
2 changes: 1 addition & 1 deletion spec/features/new_model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
expect { click_button("Create") }.not_to(change(User, :count))

within(".alert.alert-danger") do
expect(page).to(have_content("User was NOT created."))
expect(page).to(have_content("Customer was NOT created."))
end

within(".field_with_errors") do
Expand Down
2 changes: 2 additions & 0 deletions test_app_upmin/models/admin_user.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
class AdminUser < Upmin::Model

display_name "Customer"

action :issue_coupon

end

0 comments on commit 6d1684e

Please sign in to comment.