diff --git a/lib/gollum/views/template_cascade.rb b/lib/gollum/views/template_cascade.rb index 9bddc1cd..9929f8dd 100644 --- a/lib/gollum/views/template_cascade.rb +++ b/lib/gollum/views/template_cascade.rb @@ -11,9 +11,13 @@ module Precious end def first_path_available(name) - priority = File.join(template_priority_path, "#{name}.#{template_extension}") default = File.join(template_path, "#{name}.#{template_extension}") - File.exists?(priority) ? priority : default + priority = + if template_priority_path + File.join(template_priority_path, "#{name}.#{template_extension}") + end + + priority && File.exists?(priority) ? priority : default end # Method should track lib/mustache/settings.rb from Mustache project. diff --git a/test/test_template_cascade.rb b/test/test_template_cascade.rb index 571d5bff..633461eb 100644 --- a/test/test_template_cascade.rb +++ b/test/test_template_cascade.rb @@ -1,47 +1,59 @@ # ~*~ encoding: utf-8 ~*~ require File.expand_path(File.join(File.dirname(__FILE__), 'helper')) -class TestTemplateCascade < Minitest::Unit::TestCase +context "Precious::Views::TemplateCascade" do include Rack::Test::Methods - def setup + setup do @path = cloned_testpath('examples/lotr.git') Precious::App.set(:gollum_path, @path) - Precious::App.set(:wiki_options, {template_dir: testpath('examples/template_cascade')}) + Precious::App.set( + :wiki_options, + {template_dir: testpath('examples/template_cascade')} + ) @wiki = Gollum::Wiki.new(@path) end - def teardown + teardown do FileUtils.rm_rf(@path) + + Precious::App.set(:wiki_options, {template_dir: nil}) + + # The following line has been added to avoid order-dependent test failures. + # We saw issues where the class variable `@@template_priority_path` was not + # being reset between test cases. + Precious::Views::TemplateCascade.class_variable_set( + :@@template_priority_path, + nil + ) end def app - Precious::App + Precious::App.new end - def test_overridden_page_template_is_used + test "overridden_page_template_is_used" do get '/Home' assert last_response.body.include?('PAGE_OVERRIDE') end - def test_overridden_navbar_partial_is_used + test "test_overridden_navbar_partial_is_used" do get '/Home' assert last_response.body.include?('NAVBAR_OVERRIDE') end - def test_overridden_templates_are_ignore_without_template_dir_set + test "test_overridden_templates_are_ignore_without_template_dir_set" do Precious::App.set(:wiki_options, {template_dir: nil}) get '/Home' + assert_equal '/Home', last_request.fullpath + assert last_response.ok? + refute_match /PAGE_OVERRIDE/, last_response.body refute_match /NAVBAR_OVERRIDE/, last_response.body end - - def teardown - FileUtils.rm_rf(@path) - end end