Skip to content

Commit

Permalink
Improve check for paths as hashes in GalleryGenerator
Browse files Browse the repository at this point in the history
To match the changes to CaptureOptions.

For bbc#536
  • Loading branch information
Steve Day authored and Steve Day committed Sep 7, 2018
1 parent 7734de1 commit c90ee53
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/wraith/gallery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions spec/configs/test_config--hash-paths.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
imports: 'test_config--phantom.yaml'

paths:
home:
path: '/'
uk_index:
some_other_key: 'blahblahblah'
23 changes: 23 additions & 0 deletions spec/gallery_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c90ee53

Please sign in to comment.