diff options
Diffstat (limited to 'actionpack/test/template')
-rw-r--r-- | actionpack/test/template/lookup_context_test.rb | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/actionpack/test/template/lookup_context_test.rb b/actionpack/test/template/lookup_context_test.rb index 37526957bc..df1aa2edb2 100644 --- a/actionpack/test/template/lookup_context_test.rb +++ b/actionpack/test/template/lookup_context_test.rb @@ -22,34 +22,35 @@ class LookupContextTest < ActiveSupport::TestCase end test "normalizes details on initialization" do - formats = Mime::SET - locale = [I18n.locale] - assert_equal Hash[:formats => formats, :locale => locale], @lookup_context.details - end - - test "allows me to set details" do - @lookup_context.details = { :formats => [:html], :locale => :pt } - assert_equal Hash[:formats => [:html], :locale => [:pt]], @lookup_context.details + assert_equal Mime::SET, @lookup_context.formats + assert_equal :en, @lookup_context.locale end - test "does not allow details to be modified in place" do - assert @lookup_context.details.frozen? + test "allows me to update details" do + @lookup_context.update_details(:formats => [:html], :locale => :pt) + assert_equal [:html], @lookup_context.formats + assert_equal :pt, @lookup_context.locale end test "allows me to update an specific detail" do @lookup_context.update_details(:locale => :pt) assert_equal :pt, I18n.locale - formats = Mime::SET - locale = [I18n.locale] - assert_equal Hash[:formats => formats, :locale => locale], @lookup_context.details + assert_equal :pt, @lookup_context.locale + end + + test "allows me to freeze and retrieve frozen formats" do + @lookup_context.formats.freeze + assert @lookup_context.formats.frozen? end test "allows me to change some details to execute an specific block of code" do formats = Mime::SET @lookup_context.update_details(:locale => :pt) do - assert_equal Hash[:formats => formats, :locale => [:pt]], @lookup_context.details + assert_equal formats, @lookup_context.formats + assert_equal :pt, @lookup_context.locale end - assert_equal Hash[:formats => formats, :locale => [:en]], @lookup_context.details + assert_equal formats, @lookup_context.formats + assert_equal :en, @lookup_context.locale end test "provides getters and setters for formats" do @@ -62,6 +63,11 @@ class LookupContextTest < ActiveSupport::TestCase assert_equal Mime::SET, @lookup_context.formats end + test "adds :html fallback to :js formats" do + @lookup_context.formats = [:js] + assert_equal [:js, :html], @lookup_context.formats + end + test "provides getters and setters for locale" do @lookup_context.locale = :pt assert_equal :pt, @lookup_context.locale @@ -94,6 +100,13 @@ class LookupContextTest < ActiveSupport::TestCase assert_equal "Hey verden", template.source end + test "found templates respects given formats if one cannot be found from template or handler" do + ActionView::Template::Handlers::ERB.expects(:default_format).returns(nil) + @lookup_context.formats = [:text] + template = @lookup_context.find("hello_world", "test") + assert_equal [:text], template.formats + end + test "adds fallbacks to view paths when required" do assert_equal 1, @lookup_context.view_paths.size |