diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2010-01-11 23:28:47 -0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-01-14 01:07:03 +0100 |
commit | 8e0208f650eac23ee4b5c748d2de715344c5c629 (patch) | |
tree | 3902178a33edd0ed0915dd107ff1afd773c8e2c3 /actionpack/test/template | |
parent | f921ad5c97048c692859b395bc78245a343bf833 (diff) | |
download | rails-8e0208f650eac23ee4b5c748d2de715344c5c629.tar.gz rails-8e0208f650eac23ee4b5c748d2de715344c5c629.tar.bz2 rails-8e0208f650eac23ee4b5c748d2de715344c5c629.zip |
Add possibility to use i18n translatios in submit FormHelper.
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'actionpack/test/template')
-rw-r--r-- | actionpack/test/template/form_helper_test.rb | 63 |
1 files changed, 60 insertions, 3 deletions
diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index acadbd0cd0..c62bc6f4a8 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -25,6 +25,17 @@ class FormHelperTest < ActionView::TestCase } } + # Create "submit" locale for testing I18n submit helpers + I18n.backend.store_translations 'submit', { + :helpers => { + :submit => { + :create => 'Create {{model}}', + :update => 'Confirm {{model}} changes', + :submit => 'Save changes' + } + } + } + @post = Post.new @comment = Comment.new def @post.errors() @@ -475,6 +486,52 @@ class FormHelperTest < ActionView::TestCase assert_dom_equal expected, output_buffer end + def test_submit_with_object_as_new_record_and_locale_strings + old_locale, I18n.locale = I18n.locale, :submit + + def @post.new_record?() true; end + form_for(:post, @post) do |f| + concat f.submit + end + + expected = "<form action='http://www.example.com' method='post'>" + + "<input name='commit' id='post_submit' type='submit' value='Create Post' />" + + "</form>" + assert_dom_equal expected, output_buffer + ensure + I18n.locale = old_locale + end + + def test_submit_with_object_as_existing_record_and_locale_strings + old_locale, I18n.locale = I18n.locale, :submit + + form_for(:post, @post) do |f| + concat f.submit + end + + expected = "<form action='http://www.example.com' method='post'>" + + "<input name='commit' id='post_submit' type='submit' value='Confirm Post changes' />" + + "</form>" + assert_dom_equal expected, output_buffer + ensure + I18n.locale = old_locale + end + + def test_submit_without_object_and_locale_strings + old_locale, I18n.locale = I18n.locale, :submit + + form_for(:post) do |f| + concat f.submit + end + + expected = "<form action='http://www.example.com' method='post'>" + + "<input name='commit' id='post_submit' type='submit' value='Save changes' />" + + "</form>" + assert_dom_equal expected, output_buffer + ensure + I18n.locale = old_locale + end + def test_nested_fields_for form_for(:post, @post) do |f| f.fields_for(:comment, @post) do |c| @@ -659,7 +716,7 @@ class FormHelperTest < ActionView::TestCase assert_dom_equal expected, output_buffer end - + def test_nested_fields_for_with_existing_records_on_a_nested_attributes_one_to_one_association_with_explicit_hidden_field_placement @post.author = Author.new(321) @@ -670,7 +727,7 @@ class FormHelperTest < ActionView::TestCase concat af.text_field(:name) end end - + expected = '<form action="http://www.example.com" method="post">' + '<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />' + '<input id="post_author_attributes_id" name="post[author_attributes][id]" type="hidden" value="321" />' + @@ -715,7 +772,7 @@ class FormHelperTest < ActionView::TestCase end end end - + expected = '<form action="http://www.example.com" method="post">' + '<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />' + '<input id="post_comments_attributes_0_id" name="post[comments_attributes][0][id]" type="hidden" value="1" />' + |