Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve check for paths as Hashes in CaptureOptions #582

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion lib/wraith/helpers/capture_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
23 changes: 23 additions & 0 deletions spec/helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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