aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/template
diff options
context:
space:
mode:
authorEmilio Tagua <miloops@gmail.com>2010-12-20 11:23:07 -0300
committerEmilio Tagua <miloops@gmail.com>2010-12-20 11:23:07 -0300
commit02fc6fbccdd3345e95592cc14e7855e2f1ea14b3 (patch)
treeb26b91e2b2fad62ec382c9cee4ca2ac318f09257 /actionpack/test/template
parent2ba06b48defaca940e7c878724e2fb1c090eaa92 (diff)
parent0cbfd6c28d327304432f7d0c067662b5c1e41a78 (diff)
downloadrails-02fc6fbccdd3345e95592cc14e7855e2f1ea14b3.tar.gz
rails-02fc6fbccdd3345e95592cc14e7855e2f1ea14b3.tar.bz2
rails-02fc6fbccdd3345e95592cc14e7855e2f1ea14b3.zip
Merge remote branch 'rails/master' into identity_map
Conflicts: activerecord/lib/active_record/associations/association_proxy.rb activerecord/lib/active_record/autosave_association.rb activerecord/lib/active_record/base.rb activerecord/lib/active_record/persistence.rb
Diffstat (limited to 'actionpack/test/template')
-rw-r--r--actionpack/test/template/lookup_context_test.rb29
-rw-r--r--actionpack/test/template/number_helper_test.rb5
-rw-r--r--actionpack/test/template/render_test.rb5
-rw-r--r--actionpack/test/template/translation_helper_test.rb72
4 files changed, 82 insertions, 29 deletions
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
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
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)
diff --git a/actionpack/test/template/translation_helper_test.rb b/actionpack/test/template/translation_helper_test.rb
index 763080550b..9b5c6d127c 100644
--- a/actionpack/test/template/translation_helper_test.rb
+++ b/actionpack/test/template/translation_helper_test.rb
@@ -4,60 +4,78 @@ 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 => '<a>Hello World</a>',
+ :html => '<a>Hello World</a>',
+ :hello_html => '<a>Hello World</a>',
+ :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 = '<span class="translation_missing">en, foo</span>'
- assert_equal expected, translate(:foo)
+ expected = '<span class="translation_missing" title="translation missing: en.translations.missing">Missing</span>'
+ 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
- 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 = '<span class="translation_missing" title="translation missing: en.translations.templates.missing.missing">Missing</span>'
+ 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("<a>Hello World</a>")
- 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("<a>Hello World</a>")
- 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