From bef968d37942bfb2b7a59fca0e4451e096197c0a Mon Sep 17 00:00:00 2001 From: Carsten Gehling Date: Tue, 29 Dec 2009 13:06:19 +0100 Subject: I18n label helper [#745 status:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- actionpack/test/lib/controller/fake_models.rb | 1 + actionpack/test/template/form_helper_test.rb | 40 +++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/lib/controller/fake_models.rb b/actionpack/test/lib/controller/fake_models.rb index 823de8bdc7..b0e5d7a94c 100644 --- a/actionpack/test/lib/controller/fake_models.rb +++ b/actionpack/test/lib/controller/fake_models.rb @@ -54,6 +54,7 @@ end class Post < Struct.new(:title, :author_name, :body, :secret, :written_on, :cost) extend ActiveModel::Naming include ActiveModel::Conversion + extend ActiveModel::Translation alias_method :secret?, :secret diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index 44734abb18..b1e9fe99a2 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -6,6 +6,25 @@ class FormHelperTest < ActionView::TestCase def setup super + + # Create "label" locale for testing I18n label helpers + I18n.backend.store_translations 'label', { + :activemodel => { + :attributes => { + :post => { + :cost => "Total cost" + } + } + }, + :views => { + :labels => { + :post => { + :body => "Write entire text here" + } + } + } + } + @post = Post.new @comment = Comment.new def @post.errors() @@ -51,6 +70,27 @@ class FormHelperTest < ActionView::TestCase assert_dom_equal('', label(:post, :secret?)) end + def test_label_with_locales_strings + old_locale, I18n.locale = I18n.locale, :label + assert_dom_equal('', label("post", "body")) + ensure + I18n.locale = old_locale + end + + def test_label_with_human_attribute_name + old_locale, I18n.locale = I18n.locale, :label + assert_dom_equal('', label(:post, :cost)) + ensure + I18n.locale = old_locale + end + + def test_label_with_locales_symbols + old_locale, I18n.locale = I18n.locale, :label + assert_dom_equal('', label(:post, :body)) + ensure + I18n.locale = old_locale + end + def test_label_with_for_attribute_as_symbol assert_dom_equal('', label(:post, :title, nil, :for => "my_for")) end -- cgit v1.2.3