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