|
From 0256c11df521fc07768f0b1b307e9231e4c46ed8 Mon Sep 17 00:00:00 2001 |
|
From: Ben Mills <[email protected]> |
|
Date: Fri, 17 Dec 2010 19:01:14 -0700 |
|
Subject: [PATCH] Titleize model_name for default submit button value |
|
|
|
--- |
|
actionpack/lib/action_view/helpers/form_helper.rb | 4 ++- |
|
actionpack/test/lib/controller/fake_models.rb | 22 +++++++++++++++++++++ |
|
actionpack/test/template/form_helper_test.rb | 20 ++++++++++++++++++- |
|
3 files changed, 44 insertions(+), 2 deletions(-) |
|
|
|
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb |
|
index 6f0e2c9..0158988 100644 |
|
--- a/actionpack/lib/action_view/helpers/form_helper.rb |
|
+++ b/actionpack/lib/action_view/helpers/form_helper.rb |
|
@@ -1269,7 +1269,9 @@ module ActionView |
|
else |
|
@object_name.to_s.humanize |
|
end |
|
- |
|
+ |
|
+ model = model.titleize |
|
+ |
|
defaults = [] |
|
defaults << :"helpers.submit.#{object_name}.#{key}" |
|
defaults << :"helpers.submit.#{key}" |
|
diff --git a/actionpack/test/lib/controller/fake_models.rb b/actionpack/test/lib/controller/fake_models.rb |
|
index 67baf36..a282d81 100644 |
|
--- a/actionpack/test/lib/controller/fake_models.rb |
|
+++ b/actionpack/test/lib/controller/fake_models.rb |
|
@@ -48,6 +48,28 @@ module Quiz |
|
end |
|
end |
|
|
|
+class TicketType < Struct.new(:name) |
|
+ extend ActiveModel::Naming |
|
+ include ActiveModel::Conversion |
|
+ extend ActiveModel::Translation |
|
+ |
|
+ def initialize(*args) |
|
+ super |
|
+ @persisted = false |
|
+ end |
|
+ |
|
+ def persisted=(boolean) |
|
+ @persisted = boolean |
|
+ end |
|
+ |
|
+ def persisted? |
|
+ @persisted |
|
+ end |
|
+ |
|
+ attr_accessor :name |
|
+ def name_attributes=(attributes); end |
|
+end |
|
+ |
|
class Post < Struct.new(:title, :author_name, :body, :secret, :written_on, :cost) |
|
extend ActiveModel::Naming |
|
include ActiveModel::Conversion |
|
diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb |
|
index 2c60096..515ea0a 100644 |
|
--- a/actionpack/test/template/form_helper_test.rb |
|
+++ b/actionpack/test/template/form_helper_test.rb |
|
@@ -65,6 +65,7 @@ class FormHelperTest < ActionView::TestCase |
|
@post.written_on = Date.new(2004, 6, 15) |
|
|
|
@blog_post = Blog::Post.new("And his name will be forty and four.", 44) |
|
+ @ticket_type = TicketType.new |
|
end |
|
|
|
Routes = ActionDispatch::Routing::RouteSet.new |
|
@@ -72,7 +73,9 @@ class FormHelperTest < ActionView::TestCase |
|
resources :posts do |
|
resources :comments |
|
end |
|
- |
|
+ |
|
+ resources :ticket_types |
|
+ |
|
namespace :admin do |
|
resources :posts do |
|
resources :comments |
|
@@ -694,6 +697,21 @@ class FormHelperTest < ActionView::TestCase |
|
"</form>" |
|
end |
|
|
|
+ #pragma mark |
|
+ def test_titleize_model_name_default_submit_button_value |
|
+ form_for(@ticket_type) do |f| |
|
+ concat f.submit |
|
+ end |
|
+ |
|
+ expected = |
|
+ '<form accept-charset="UTF-8" action="/ticket_types" class="new_ticket_type" id="new_ticket_type" method="post">' + |
|
+ snowman + |
|
+ '<input id="ticket_type_submit" name="commit" type="submit" value="Create Ticket Type" />' + |
|
+ "</form>" |
|
+ |
|
+ assert_dom_equal expected, output_buffer |
|
+ end |
|
+ |
|
def test_form_for_with_symbol_object_name |
|
form_for(@post, :as => "other_name", :html => { :id => 'create-post' }) do |f| |
|
concat f.label(:title, :class => 'post_title') |
|
-- |
|
1.7.0.6 |