From 8624065bffd203e1f590ca431d468f9b38e9fb7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 24 Nov 2010 12:38:52 +0100 Subject: Allow template handlers to store temp data. --- actionpack/test/template/lookup_context_test.rb | 29 +++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/lookup_context_test.rb b/actionpack/test/template/lookup_context_test.rb index 6d3b26e131..c9dd27cf2a 100644 --- a/actionpack/test/template/lookup_context_test.rb +++ b/actionpack/test/template/lookup_context_test.rb @@ -180,6 +180,16 @@ class LookupContextTest < ActiveSupport::TestCase assert_not_equal template, old_template end + + test "data can be stored in cached templates" do + template = @lookup_context.find("hello_world", "test") + template.data["cached"] = "data" + assert_equal "Hello world!", template.source + + template = @lookup_context.find("hello_world", "test") + assert_equal "data", template.data["cached"] + assert_equal "Hello world!", template.source + end end class LookupContextWithFalseCaching < ActiveSupport::TestCase @@ -205,7 +215,7 @@ class LookupContextWithFalseCaching < ActiveSupport::TestCase assert_equal "Bar", template.source end - test "if no template was found in the second lookup, give it higher preference" do + test "if no template was found in the second lookup, with no cache, raise error" do template = @lookup_context.find("foo", "test", true) assert_equal "Foo", template.source @@ -215,7 +225,7 @@ class LookupContextWithFalseCaching < ActiveSupport::TestCase end end - test "if no template was cached in the first lookup, do not use the cache in the second" do + test "if no template was cached in the first lookup, retrieval should work in the second call" do @resolver.hash.clear assert_raise ActionView::MissingTemplate do @lookup_context.find("foo", "test", true) @@ -225,4 +235,19 @@ class LookupContextWithFalseCaching < ActiveSupport::TestCase template = @lookup_context.find("foo", "test", true) assert_equal "Foo", template.source end + + test "data can be stored as long as template was not updated" do + template = @lookup_context.find("foo", "test", true) + template.data["cached"] = "data" + assert_equal "Foo", template.source + + template = @lookup_context.find("foo", "test", true) + assert_equal "data", template.data["cached"] + assert_equal "Foo", template.source + + @resolver.hash["test/_foo.erb"][1] = Time.now.utc + template = @lookup_context.find("foo", "test", true) + assert_nil template.data["cached"] + assert_equal "Foo", template.source + end end \ No newline at end of file -- cgit v1.2.3 From 896e25e994e272a1cb485d9a850501b488992cb2 Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Sun, 14 Nov 2010 18:46:40 +0100 Subject: Make TranslationHelper#translate use the :rescue_format option in I18n 0.5.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Don't catch exceptions here. Instead only declare that we want exceptions to be rescued as :html, but also let users configure reactions to exceptions in I18n. Signed-off-by: José Valim --- .../test/template/translation_helper_test.rb | 67 +++++++++++++--------- 1 file changed, 40 insertions(+), 27 deletions(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/translation_helper_test.rb b/actionpack/test/template/translation_helper_test.rb index 763080550b..67d459136b 100644 --- a/actionpack/test/template/translation_helper_test.rb +++ b/actionpack/test/template/translation_helper_test.rb @@ -4,60 +4,73 @@ class TranslationHelperTest < ActiveSupport::TestCase include ActionView::Helpers::TagHelper include ActionView::Helpers::TranslationHelper - attr_reader :request + attr_reader :request, :view + def setup + I18n.backend.store_translations(:en, + :translations => { + :templates => { + :found => { :foo => 'Foo' }, + :array => { :foo => { :bar => 'Foo Bar' } } + }, + :foo => 'Foo', + :hello => 'Hello World', + :html => 'Hello World', + :hello_html => 'Hello World', + :array_html => %w(foo bar), + :array => %w(foo bar) + } + ) + @view = ::ActionView::Base.new(ActionController::Base.view_paths, {}) end - def test_delegates_to_i18n_setting_the_raise_option - I18n.expects(:translate).with(:foo, :locale => 'en', :raise => true).returns("") + def test_delegates_to_i18n_setting_the_rescue_format_option_to_html + I18n.expects(:translate).with(:foo, :locale => 'en', :rescue_format => :html).returns("") translate :foo, :locale => 'en' end + def test_delegates_localize_to_i18n + @time = Time.utc(2008, 7, 8, 12, 18, 38) + I18n.expects(:localize).with(@time) + localize @time + end + def test_returns_missing_translation_message_wrapped_into_span - expected = 'en, foo' - assert_equal expected, translate(:foo) + expected = 'Missing' + assert_equal expected, translate(:"translations.missing") end def test_translation_returning_an_array - I18n.expects(:translate).with(:foo, :raise => true).returns(["foo", "bar"]) - assert_equal ["foo", "bar"], translate(:foo) + expected = %w(foo bar) + assert_equal expected, translate(:"translations.array") end - def test_delegates_localize_to_i18n - @time = Time.utc(2008, 7, 8, 12, 18, 38) - I18n.expects(:localize).with(@time) - localize @time + def test_finds_translation_scoped_by_partial + assert_equal 'Foo', view.render(:file => 'translations/templates/found').strip end - def test_scoping_by_partial - I18n.expects(:translate).with("test.translation.helper", :raise => true).returns("helper") - @view = ::ActionView::Base.new(ActionController::Base.view_paths, {}) - assert_equal "helper", @view.render(:file => "test/translation") + def test_finds_array_of_translations_scoped_by_partial + assert_equal 'Foo Bar', @view.render(:file => 'translations/templates/array').strip end - def test_scoping_by_partial_of_an_array - I18n.expects(:translate).with("test.scoped_translation.foo.bar", :raise => true).returns(["foo", "bar"]) - @view = ::ActionView::Base.new(ActionController::Base.view_paths, {}) - assert_equal "foobar", @view.render(:file => "test/scoped_translation") + def test_missing_translation_scoped_by_partial + expected = 'Missing' + assert_equal expected, view.render(:file => 'translations/templates/missing').strip end def test_translate_does_not_mark_plain_text_as_safe_html - I18n.expects(:translate).with("hello", :raise => true).returns("Hello World") - assert_equal false, translate("hello").html_safe? + assert_equal false, translate(:'translations.hello').html_safe? end def test_translate_marks_translations_named_html_as_safe_html - I18n.expects(:translate).with("html", :raise => true).returns("Hello World") - assert translate("html").html_safe? + assert translate(:'translations.html').html_safe? end def test_translate_marks_translations_with_a_html_suffix_as_safe_html - I18n.expects(:translate).with("hello_html", :raise => true).returns("Hello World") - assert translate("hello_html").html_safe? + assert translate(:'translations.hello_html').html_safe? end def test_translation_returning_an_array_ignores_html_suffix - I18n.expects(:translate).with(:foo_html, :raise => true).returns(["foo", "bar"]) - assert_equal ["foo", "bar"], translate(:foo_html) + assert_equal ["foo", "bar"], translate(:'translations.array_html') end end -- cgit v1.2.3 From b696dd70db651c6cb4a096dd0d5762416acd9917 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sat, 4 Dec 2010 20:07:54 -0200 Subject: Allow back passing :rescue_format => nil and test added --- actionpack/test/template/translation_helper_test.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/translation_helper_test.rb b/actionpack/test/template/translation_helper_test.rb index 67d459136b..9b5c6d127c 100644 --- a/actionpack/test/template/translation_helper_test.rb +++ b/actionpack/test/template/translation_helper_test.rb @@ -40,6 +40,11 @@ class TranslationHelperTest < ActiveSupport::TestCase assert_equal expected, translate(:"translations.missing") end + def test_returns_missing_translation_message_using_nil_as_rescue_format + expected = 'translation missing: en.translations.missing' + assert_equal expected, translate(:"translations.missing", :rescue_format => nil) + end + def test_translation_returning_an_array expected = %w(foo bar) assert_equal expected, translate(:"translations.array") -- cgit v1.2.3 From cc70ac9508dff6a4406f446d7a53d05f6c7d9f61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 9 Dec 2010 13:15:40 +0100 Subject: Properly check the arity for template handlers. --- actionpack/test/template/render_test.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index 8087429d62..38bedd2e4e 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -225,6 +225,11 @@ module RenderTestCases %'"#{template.class} #{view.class}"' end + def test_render_inline_with_render_from_to_proc + ActionView::Template.register_template_handler :ruby_handler, :source.to_proc + assert_equal '3', @view.render(:inline => "(1 + 2).to_s", :type => :ruby_handler) + end + def test_render_inline_with_template_handler_with_view ActionView::Template.register_template_handler :with_view, WithViewHandler assert_equal 'ActionView::Template ActionView::Base', @view.render(:inline => "Hello, World!", :type => :with_view) -- cgit v1.2.3 From 006ec77e60163d57d655479602230672d98e0f10 Mon Sep 17 00:00:00 2001 From: Don Wilson Date: Thu, 16 Dec 2010 11:37:11 -0200 Subject: Fixed number_with_precision rounding error [#6182 state:resolved] --- actionpack/test/template/number_helper_test.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/number_helper_test.rb b/actionpack/test/template/number_helper_test.rb index ab127521ad..6b234cfbb9 100644 --- a/actionpack/test/template/number_helper_test.rb +++ b/actionpack/test/template/number_helper_test.rb @@ -100,6 +100,11 @@ class NumberHelperTest < ActionView::TestCase assert_equal("0", number_with_precision(0, :precision => 0)) assert_equal("0.00100", number_with_precision(0.001, :precision => 5)) assert_equal("0.001", number_with_precision(0.00111, :precision => 3)) + assert_equal("10.00", number_with_precision(9.995, :precision => 2)) + assert_equal("11.00", number_with_precision(10.995, :precision => 2)) + assert_equal("10.0", number_with_precision(9.995, :precision => 3, :significant => true)) + assert_equal("9.99", number_with_precision(9.994, :precision => 3, :significant => true)) + assert_equal("11.0", number_with_precision(10.995, :precision => 3, :significant => true)) end def test_number_with_precision_with_custom_delimiter_and_separator -- cgit v1.2.3 From 07567aea5f0c6f14a53f511ab4cc46201b669795 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 17 Dec 2010 16:11:47 +0100 Subject: Revert "Fixed number_with_precision rounding error [#6182 state:resolved]" This reverts commit 006ec77e60163d57d655479602230672d98e0f10. --- actionpack/test/template/number_helper_test.rb | 5 ----- 1 file changed, 5 deletions(-) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/number_helper_test.rb b/actionpack/test/template/number_helper_test.rb index 6b234cfbb9..ab127521ad 100644 --- a/actionpack/test/template/number_helper_test.rb +++ b/actionpack/test/template/number_helper_test.rb @@ -100,11 +100,6 @@ class NumberHelperTest < ActionView::TestCase assert_equal("0", number_with_precision(0, :precision => 0)) assert_equal("0.00100", number_with_precision(0.001, :precision => 5)) assert_equal("0.001", number_with_precision(0.00111, :precision => 3)) - assert_equal("10.00", number_with_precision(9.995, :precision => 2)) - assert_equal("11.00", number_with_precision(10.995, :precision => 2)) - assert_equal("10.0", number_with_precision(9.995, :precision => 3, :significant => true)) - assert_equal("9.99", number_with_precision(9.994, :precision => 3, :significant => true)) - assert_equal("11.0", number_with_precision(10.995, :precision => 3, :significant => true)) end def test_number_with_precision_with_custom_delimiter_and_separator -- cgit v1.2.3 From f71809f25761440cbec9463bbc082987c90a471b Mon Sep 17 00:00:00 2001 From: Don Wilson Date: Fri, 17 Dec 2010 09:56:03 -0700 Subject: Fixed number_with_precision rounding error [#6182 state:resolved] --- actionpack/test/template/number_helper_test.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/number_helper_test.rb b/actionpack/test/template/number_helper_test.rb index ab127521ad..156b7cb5ff 100644 --- a/actionpack/test/template/number_helper_test.rb +++ b/actionpack/test/template/number_helper_test.rb @@ -100,6 +100,8 @@ class NumberHelperTest < ActionView::TestCase assert_equal("0", number_with_precision(0, :precision => 0)) assert_equal("0.00100", number_with_precision(0.001, :precision => 5)) assert_equal("0.001", number_with_precision(0.00111, :precision => 3)) + assert_equal("10.00", number_with_precision(9.995, :precision => 2)) + assert_equal("11.00", number_with_precision(10.995, :precision => 2)) end def test_number_with_precision_with_custom_delimiter_and_separator @@ -125,6 +127,9 @@ class NumberHelperTest < ActionView::TestCase assert_equal "0.0001", number_with_precision(0.0001, :precision => 1, :significant => true ) assert_equal "0.000100", number_with_precision(0.0001, :precision => 3, :significant => true ) assert_equal "0.0001", number_with_precision(0.0001111, :precision => 1, :significant => true ) + assert_equal "10.0", number_with_precision(9.995, :precision => 3, :significant => true) + assert_equal "9.99", number_with_precision(9.994, :precision => 3, :significant => true) + assert_equal "11.0", number_with_precision(10.995, :precision => 3, :significant => true) end def test_number_with_precision_with_strip_insignificant_zeros -- cgit v1.2.3