From 6702cf8a595583527492bda2c28b9820fe90cfd8 Mon Sep 17 00:00:00 2001 From: Michael Kaiser-Nyman Date: Fri, 1 May 2015 22:13:45 -0700 Subject: [PATCH 01/13] DRY up spec for TOC skip_sidebar code --- spec/toc_spec.rb | 36 +++++++++--------------------------- 1 file changed, 9 insertions(+), 27 deletions(-) diff --git a/spec/toc_spec.rb b/spec/toc_spec.rb index 6567ebd59..281e3a7b5 100644 --- a/spec/toc_spec.rb +++ b/spec/toc_spec.rb @@ -6,6 +6,7 @@ let(:basic_chapter_title) { "What even is middleman?" } let(:basic_guide_title) { "Middleman Basics" } let(:basics_page) { double(path: "middleman-basics/index.html") } + let(:toc) { helper.toc_for(helper.data.guides) } before(:each) do class HelperTester @@ -19,6 +20,12 @@ class HelperTester chapters: - title: "What even is middleman?" url: "index" + - title: "Secret stuff" + url: "secret" + chapters: + - title: "Don't tell anybody" + url: "" + skip_sidebar: true } data = Hashie::Mash.new(YAML.load(data_yml)) @@ -51,33 +58,8 @@ class HelperTester end it "includes guide titles except guides that are marked to skip sidbar" do - data_yml = %Q{ -guides: - - title: "Middleman Basics" - url: "middleman-basics" - chapters: - - title: "What even is middleman?" - url: "" - skip_sidebar: true - - - title: "Advanced Middleman" - url: "advanced-middleman" - chapters: - - title: "Advanced Concepts" - url: "index" - - title: "Extending Middleman" - url: "extending-middleman" - chapters: - - title: "What are extensions?" - url: "index" - } - - data = Hashie::Mash.new(YAML.load(data_yml)) - toc = helper.toc_for(data.guides) - expect(toc).to include("Advanced Middleman") - expect(toc).to include("Extending Middleman") - - expect(toc).not_to include("Middleman Basics") + expect(toc).to include("What even is middleman?") + expect(toc).not_to include("Secret stuff") end it "includes chapter titles except for chapter that are marked to skip sidbar" do From becbc6b21174f014c47313a330f98cfec0184ece Mon Sep 17 00:00:00 2001 From: Michael Kaiser-Nyman Date: Fri, 1 May 2015 22:14:59 -0700 Subject: [PATCH 02/13] DRY up spec for toc generation for missing file exception --- spec/toc_spec.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/spec/toc_spec.rb b/spec/toc_spec.rb index 281e3a7b5..b7912e66c 100644 --- a/spec/toc_spec.rb +++ b/spec/toc_spec.rb @@ -52,9 +52,8 @@ class HelperTester it "raises an exception if a file doesn't exist" do allow(File).to receive(:exist?).and_return(false) - expect { - helper.toc_for(helper.data.guides) - }.to raise_error(RuntimeError, "source/middleman-basics/index.md does not exist. Please fix guides.yml.") + expect { toc }.to raise_error(RuntimeError, + "source/middleman-basics/index.md does not exist. Please fix guides.yml.") end it "includes guide titles except guides that are marked to skip sidbar" do From 54817e4a7bbcdc355f49d912b166c8e985d4c282 Mon Sep 17 00:00:00 2001 From: Michael Kaiser-Nyman Date: Fri, 1 May 2015 22:18:36 -0700 Subject: [PATCH 03/13] DRY up spec for toc skip_sidebar_item code --- spec/toc_spec.rb | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/spec/toc_spec.rb b/spec/toc_spec.rb index b7912e66c..9fb6d6f5c 100644 --- a/spec/toc_spec.rb +++ b/spec/toc_spec.rb @@ -20,6 +20,9 @@ class HelperTester chapters: - title: "What even is middleman?" url: "index" + - title: "Nobody really cares about this" + url: "meh" + skip_sidebar_item: true - title: "Secret stuff" url: "secret" chapters: @@ -62,27 +65,8 @@ class HelperTester end it "includes chapter titles except for chapter that are marked to skip sidbar" do - data_yml = %Q{ -guides: - - title: "Extending Middleman" - url: "extending-middleman" - chapters: - - title: "What are extensions?" - url: "index" - skip_sidebar_item: true - - title: "Building Middleman Extensions" - url: "building-middleman-extensions" - - title: "Testing Middleman Extensions" - url: "testing-middleman-extensions" - } - - data = Hashie::Mash.new(YAML.load(data_yml)) - toc = helper.toc_for(data.guides) - - expect(toc).to include("Building Middleman Extensions") - expect(toc).to include("Testing Middleman Extensions") - - expect(toc).not_to include("What are extensions?") + expect(toc).to include("What even is middleman?") + expect(toc).not_to include("Nobody really cares about this") end it "includes guide urls except guides that are marked to skip sidbar" do From 894dd7b231f9d04c65b50db8ae85f9295083aa54 Mon Sep 17 00:00:00 2001 From: Michael Kaiser-Nyman Date: Fri, 1 May 2015 22:21:08 -0700 Subject: [PATCH 04/13] only make one assertion per test --- spec/toc_spec.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/spec/toc_spec.rb b/spec/toc_spec.rb index 9fb6d6f5c..04a0ebac4 100644 --- a/spec/toc_spec.rb +++ b/spec/toc_spec.rb @@ -59,13 +59,15 @@ class HelperTester "source/middleman-basics/index.md does not exist. Please fix guides.yml.") end - it "includes guide titles except guides that are marked to skip sidbar" do + it "includes guide titles" do expect(toc).to include("What even is middleman?") + end + + it "does not includes guide titles that are marked to skip sidebar" do expect(toc).not_to include("Secret stuff") end - it "includes chapter titles except for chapter that are marked to skip sidbar" do - expect(toc).to include("What even is middleman?") + it "does not includes chapter titles that are marked to skip sidebar" do expect(toc).not_to include("Nobody really cares about this") end From d1f15a1fc0e6b1cbd620c55e5bb7f0c8a9770fd6 Mon Sep 17 00:00:00 2001 From: Michael Kaiser-Nyman Date: Fri, 1 May 2015 22:22:09 -0700 Subject: [PATCH 05/13] add spec for guide urls --- spec/toc_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/toc_spec.rb b/spec/toc_spec.rb index 04a0ebac4..b69c3410c 100644 --- a/spec/toc_spec.rb +++ b/spec/toc_spec.rb @@ -71,6 +71,10 @@ class HelperTester expect(toc).not_to include("Nobody really cares about this") end + it "includes guide urls" do + expect(toc).to include("middleman-basics") + end + it "includes guide urls except guides that are marked to skip sidbar" do data_yml = %Q{ guides: From c377d7570f4604cc98578727e4138b840b66d180 Mon Sep 17 00:00:00 2001 From: Michael Kaiser-Nyman Date: Fri, 1 May 2015 22:23:29 -0700 Subject: [PATCH 06/13] DRY up spec for skipping url on sidebar --- spec/toc_spec.rb | 31 ++----------------------------- 1 file changed, 2 insertions(+), 29 deletions(-) diff --git a/spec/toc_spec.rb b/spec/toc_spec.rb index b69c3410c..0761ad4d2 100644 --- a/spec/toc_spec.rb +++ b/spec/toc_spec.rb @@ -75,35 +75,8 @@ class HelperTester expect(toc).to include("middleman-basics") end - it "includes guide urls except guides that are marked to skip sidbar" do - data_yml = %Q{ -guides: - - title: "Middleman Basics" - url: "middleman-basics" - chapters: - - title: "What even is middleman?" - url: "" - skip_sidebar: true - - - title: "Advanced Middleman" - url: "advanced-middleman" - chapters: - - title: "Advanced Concepts" - url: "index" - - title: "Extending Middleman" - url: "extending-middleman" - chapters: - - title: "What are extensions?" - url: "index" - } - - data = Hashie::Mash.new(YAML.load(data_yml)) - toc = helper.toc_for(data.guides) - - expect(toc).to include("advanced-middleman") - expect(toc).to include("extending-middleman") - - expect(toc).not_to include("middleman-basics") + it "does not include guide urls for guides that are marked to skip sidebar" do + expect(toc).not_to include("secret") end it "includes chapter urls except for chapter that are marked to skip sidbar" do From 83ef5e0409893466ce4f070d9ab669660e11cbad Mon Sep 17 00:00:00 2001 From: Michael Kaiser-Nyman Date: Fri, 1 May 2015 22:26:24 -0700 Subject: [PATCH 07/13] DRY up spec for skipping chapter urls --- spec/toc_spec.rb | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/spec/toc_spec.rb b/spec/toc_spec.rb index 0761ad4d2..e2efae021 100644 --- a/spec/toc_spec.rb +++ b/spec/toc_spec.rb @@ -79,30 +79,8 @@ class HelperTester expect(toc).not_to include("secret") end - it "includes chapter urls except for chapter that are marked to skip sidbar" do - data_yml = %Q{ -guides: - - title: "Advanced Middleman" - url: "advanced-middleman" - chapters: - - title: "Advanced Concepts" - url: "index" - - title: "Middleman Architecture" - url: "middleman-architecture" - skip_sidebar_item: true - - title: "Contributing to Middleman" - url: "contributing-to-middleman" - } - - data = Hashie::Mash.new(YAML.load(data_yml)) - toc = helper.toc_for(data.guides) - advanced_index_page = double(path: "advanced-middleman/index.html") - allow(helper).to receive(:request).and_return(advanced_index_page) - - expect(toc).to include(advanced_index_page.path) - expect(toc).to include("contributing-to-middleman") - - expect(toc).not_to include("middleman-architecture") + it "does not include chapter urls that are marked to skip sidebar" do + expect(toc).not_to include("meh") end it "contains a link to first chapter as a guide link even if it is marked with :skip_sidebar_item" do From c8fd4ef4da609f3c80cd3c8408d77de95417f3cb Mon Sep 17 00:00:00 2001 From: Michael Kaiser-Nyman Date: Fri, 1 May 2015 22:31:00 -0700 Subject: [PATCH 08/13] DRY up spec for first chapter skip link exception --- spec/toc_spec.rb | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/spec/toc_spec.rb b/spec/toc_spec.rb index e2efae021..6976de784 100644 --- a/spec/toc_spec.rb +++ b/spec/toc_spec.rb @@ -6,7 +6,6 @@ let(:basic_chapter_title) { "What even is middleman?" } let(:basic_guide_title) { "Middleman Basics" } let(:basics_page) { double(path: "middleman-basics/index.html") } - let(:toc) { helper.toc_for(helper.data.guides) } before(:each) do class HelperTester @@ -29,6 +28,12 @@ class HelperTester - title: "Don't tell anybody" url: "" skip_sidebar: true + - title: "Extending Middleman" + url: "extending-middleman" + chapters: + - title: "What are extensions?" + url: "index" + skip_sidebar_item: true } data = Hashie::Mash.new(YAML.load(data_yml)) @@ -47,6 +52,8 @@ class HelperTester end describe "#toc_for" do + let(:toc) { helper.toc_for(helper.data.guides) } + before(:each) do building_page = double(path: "custom-extensions/building-custom-extensions.html") allow(helper).to receive(:request).and_return(building_page) @@ -84,20 +91,7 @@ class HelperTester end it "contains a link to first chapter as a guide link even if it is marked with :skip_sidebar_item" do - data_yml = %Q{ -guides: - - title: "Extending Middleman" - url: "extending-middleman" - chapters: - - title: "What are extensions?" - url: "index" - skip_sidebar_item: true - } - - data = Hashie::Mash.new(YAML.load(data_yml)) - toc = helper.toc_for(data.guides) - expectation = %Q{
  • Extending Middleman} - expect(toc).to include(expectation) + expect(toc).to include("extending-middleman") end end From 9ec947bbabefda2b9f6380f0609814d95f6fd832 Mon Sep 17 00:00:00 2001 From: Michael Kaiser-Nyman Date: Sat, 2 May 2015 08:45:05 -0700 Subject: [PATCH 09/13] standardize current page for github link test --- spec/toc_spec.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/spec/toc_spec.rb b/spec/toc_spec.rb index 6976de784..99bcee96f 100644 --- a/spec/toc_spec.rb +++ b/spec/toc_spec.rb @@ -37,10 +37,9 @@ class HelperTester } data = Hashie::Mash.new(YAML.load(data_yml)) - testing_page = double(path: "custom-extensions/testing-custom-extensions.html") allow(helper).to receive(:data).and_return(data) - allow(helper).to receive(:current_page).and_return(testing_page) + allow(helper).to receive(:current_page).and_return(basics_page) allow(helper).to receive(:link_to).and_wrap_original do |_, title, url| %Q{#{title}} end @@ -168,7 +167,7 @@ class HelperTester describe "#chapter_github_source_url" do it "is the github URL to the source file for current page" do - expect(helper.chapter_github_source_url).to eq("https://github.com/emberjs/guides/edit/master/source/custom-extensions/testing-custom-extensions.md") + expect(helper.chapter_github_source_url).to eq("https://github.com/emberjs/guides/edit/master/source/middleman-basics/index.md") end end From 7e8b5bf9756ff5ea5a3bb65155f4a497217b42b5 Mon Sep 17 00:00:00 2001 From: Michael Kaiser-Nyman Date: Sat, 2 May 2015 08:45:48 -0700 Subject: [PATCH 10/13] remove redundant current_page stubs --- spec/toc_spec.rb | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/spec/toc_spec.rb b/spec/toc_spec.rb index 99bcee96f..1d78bd1e9 100644 --- a/spec/toc_spec.rb +++ b/spec/toc_spec.rb @@ -95,10 +95,6 @@ class HelperTester end describe "#page_title" do - before(:each) do - allow(helper).to receive(:current_page).and_return(basics_page) - end - it "is generic when current guide is not specified" do allow(helper).to receive(:current_guide).and_return(nil) @@ -117,10 +113,6 @@ class HelperTester end describe "#guide_name" do - before(:each) do - allow(helper).to receive(:current_page).and_return(basics_page) - end - it "is nil if current guide is not specified" do allow(helper).to receive(:current_guide).and_return(nil) @@ -133,10 +125,6 @@ class HelperTester end describe "#chapter_name" do - before(:each) do - allow(helper).to receive(:current_page).and_return(basics_page) - end - it "is an empty string when current chapter is not specified" do allow(helper).to receive(:current_chapter).and_return(nil) @@ -149,10 +137,6 @@ class HelperTester end describe "#chapter_heading" do - before(:each) do - allow(helper).to receive(:current_page).and_return(basics_page) - end - it "is nil if chapter name is blank" do allow(helper).to receive(:chapter_name).and_return("") @@ -172,10 +156,6 @@ class HelperTester end describe "#current_guide" do - before(:each) do - allow(helper).to receive(:current_page).and_return(basics_page) - end - it "is the current value if present" do helper.instance_variable_set(:@current_guide, "some random value") expect(helper.current_guide).to eq("some random value") From 9a4ab90b73aa56d3a794249aa001b1994b9cc204 Mon Sep 17 00:00:00 2001 From: Michael Kaiser-Nyman Date: Sat, 2 May 2015 09:20:17 -0700 Subject: [PATCH 11/13] privatize and don't test implementation details --- lib/toc.rb | 66 +++++++++++++------------- spec/toc_spec.rb | 120 ----------------------------------------------- 2 files changed, 34 insertions(+), 152 deletions(-) diff --git a/lib/toc.rb b/lib/toc.rb index 296c9f986..c0cee8dbc 100644 --- a/lib/toc.rb +++ b/lib/toc.rb @@ -98,38 +98,6 @@ def chapter_github_source_url "https://github.com/emberjs/guides/edit/master/source/#{current_page.path.gsub('.html', '.md')}" end - def current_guide - return @current_guide if @current_guide - - path = current_page.path.gsub('.html', '') - guide_path = path.split("/")[0] - - @current_guide = data.guides.find do |guide| - guide.url == guide_path - end - end - - def current_guide_index - data.guides.find_index(current_guide) - end - - def current_chapter - return unless current_guide - - return @current_chapter if @current_chapter - path = current_page.path.gsub('.html', '') - chapter_path = path.split('/')[1..-1].join('/') - - @current_chapter = current_guide.chapters.find do |chapter| - chapter.url == chapter_path - end - end - - def current_chapter_index - return unless current_guide - current_guide.chapters.find_index(current_chapter) - end - def chapter_links %Q{