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

Return a default presenter instead of nil. #2117

Merged
merged 1 commit into from
Oct 29, 2019
Merged
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
2 changes: 1 addition & 1 deletion app/helpers/blacklight/blacklight_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def presenter(document)
case action_name
when 'show', 'citation'
show_presenter(document)
when 'index'
else
index_presenter(document)
end
end
Expand Down
42 changes: 42 additions & 0 deletions spec/helpers/blacklight_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -388,4 +388,46 @@
expect(helper.render_document_heading(document, tag: "h3")).to have_selector "h3", text: "Document Heading"
end
end

describe "#presenter" do
let(:document) { double }

before do
allow(helper).to receive(:index_presenter).and_return(:index_presenter)
allow(helper).to receive(:show_presenter).and_return(:show_presenter)
allow(helper).to receive(:action_name).and_return(action_name)
end

context "action is show" do
let(:action_name) { "show" }

it "uses the show presenter" do
expect(helper.presenter(document)).to eq(:show_presenter)
end
end

context "action is citation" do
let(:action_name) { "citation" }

it "uses the show presenter" do
expect(helper.presenter(document)).to eq(:show_presenter)
end
end

context "action is index" do
let(:action_name) { "index" }

it "uses the index presenter" do
expect(helper.presenter(document)).to eq(:index_presenter)
end
end

context "action is foo" do
let(:action_name) { "foo" }

it "uses the index presenter (by default)" do
expect(helper.presenter(document)).to eq(:index_presenter)
end
end
end
end