From 7734de193aa9ebb9c271d22b574f51eba95f0636 Mon Sep 17 00:00:00 2001 From: Steve Day Date: Thu, 6 Sep 2018 14:20:27 +0100 Subject: [PATCH 1/2] Improve check for paths as Hashes in CaptureOptions Closes #536 --- lib/wraith/helpers/capture_options.rb | 2 +- spec/helper_spec.rb | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/wraith/helpers/capture_options.rb b/lib/wraith/helpers/capture_options.rb index 9673b0d4..f84bdc32 100644 --- a/lib/wraith/helpers/capture_options.rb +++ b/lib/wraith/helpers/capture_options.rb @@ -47,6 +47,6 @@ def compare_urls(path) end def casper?(options) - options["path"] ? options["path"] : options + options.is_a?(String) ? options : options.fetch("path") end end diff --git a/spec/helper_spec.rb b/spec/helper_spec.rb index 20566862..b6fea29c 100644 --- a/spec/helper_spec.rb +++ b/spec/helper_spec.rb @@ -28,4 +28,27 @@ end end + describe "CaptureOptions" do + let(:capture_options) { CaptureOptions.new('', nil) } + + describe "#casper?" do + it "returns options when options is a string" do + actual = capture_options.casper?('/test/path') + expected = '/test/path' + expect(actual).to eq expected + end + + context "when options is a Hash" do + it "returns options['path']" do + actual = capture_options.casper?({'path' => '/test/path'}) + expected = '/test/path' + expect(actual).to eq expected + end + + it "raises a KeyError if options['path'] is missing" do + expect { capture_options.casper?({}) }.to raise_error(KeyError) + end + end + end + end end From c90ee536683b5849d39399dbb8397c47ed8309a9 Mon Sep 17 00:00:00 2001 From: Steve Day Date: Fri, 7 Sep 2018 15:49:06 +0100 Subject: [PATCH 2/2] Improve check for paths as hashes in GalleryGenerator To match the changes to CaptureOptions. For #536 --- lib/wraith/gallery.rb | 6 +++++- spec/configs/test_config--hash-paths.yaml | 7 +++++++ spec/gallery_spec.rb | 23 +++++++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 spec/configs/test_config--hash-paths.yaml diff --git a/lib/wraith/gallery.rb b/lib/wraith/gallery.rb index b764dc9a..93ac2a37 100755 --- a/lib/wraith/gallery.rb +++ b/lib/wraith/gallery.rb @@ -68,7 +68,11 @@ def figure_out_url(group, category) end def get_path(category) - wraith.paths[category]["path"] || wraith.paths[category] + if wraith.paths[category].is_a?(String) + wraith.paths[category] + else + wraith.paths[category].fetch('path') + end end def get_group_from_match(match) diff --git a/spec/configs/test_config--hash-paths.yaml b/spec/configs/test_config--hash-paths.yaml new file mode 100644 index 00000000..6e60ccd0 --- /dev/null +++ b/spec/configs/test_config--hash-paths.yaml @@ -0,0 +1,7 @@ +imports: 'test_config--phantom.yaml' + +paths: + home: + path: '/' + uk_index: + some_other_key: 'blahblahblah' diff --git a/spec/gallery_spec.rb b/spec/gallery_spec.rb index ed51d810..1ccbd705 100644 --- a/spec/gallery_spec.rb +++ b/spec/gallery_spec.rb @@ -28,4 +28,27 @@ expect(dirs["home"][0][:diff][:thumb]).to eq "thumbnails/home/test_image-diff.png" end end + + describe "#get_path" do + it "returns the path when the category is a string" do + actual = gallery.get_path('home') + expected = '/' + expect(actual).to eq expected + end + + context "when category is a Hash" do + let(:config_name) { get_path_relative_to __FILE__, "./configs/test_config--hash-paths.yaml" } + let(:gallery) { Wraith::GalleryGenerator.new(config_name, false) } + + it "returns category['path']" do + actual = gallery.get_path('home') + expected = '/' + expect(actual).to eq expected + end + + it "raises a KeyError if category['path'] is missing" do + expect { gallery.get_path('uk_index') }.to raise_error(KeyError) + end + end + end end