From 4ecdf6ce108a91c593fa9d30115f2e3d63c70830 Mon Sep 17 00:00:00 2001 From: Zshawn Syed Date: Thu, 21 Jan 2016 23:44:30 -0600 Subject: [PATCH] Remove extra OR condition since a missing hash key will return a nil anyway. Added a test to catch this nil condition since it was missing to begin with. Reduced line length in test_page.rb --- lib/jekyll/page.rb | 3 +-- test/test_page.rb | 9 ++++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/jekyll/page.rb b/lib/jekyll/page.rb index fde45651..eda87f12 100644 --- a/lib/jekyll/page.rb +++ b/lib/jekyll/page.rb @@ -63,8 +63,7 @@ module Jekyll # # Returns the String permalink or nil if none has been set. def permalink - return nil if data.nil? || data['permalink'].nil? - data['permalink'] + data.nil? ? nil : data['permalink'] end # The template of the permalink. diff --git a/test/test_page.rb b/test/test_page.rb index 2728b4e3..69794107 100644 --- a/test/test_page.rb +++ b/test/test_page.rb @@ -8,7 +8,9 @@ class TestPage < JekyllUnitTest end def do_render(page) - layouts = { "default" => Layout.new(@site, source_dir('_layouts'), "simple.html")} + layouts = { + "default" => Layout.new(@site, source_dir('_layouts'), "simple.html") + } page.render(layouts, @site.site_payload) end @@ -206,6 +208,11 @@ class TestPage < JekyllUnitTest assert_equal "/about/", @page.dir end + should "return nil permalink if no permalink exists" do + @page = setup_page('') + assert_equal nil, @page.permalink + end + should "not be writable outside of destination" do unexpected = File.expand_path("../../../baddie.html", dest_dir) File.delete unexpected if File.exist?(unexpected)