Skip to content

Commit

Permalink
Disable thumbnail linking by passing false or suppress_link: false to…
Browse files Browse the repository at this point in the history
… #render_thumbnail_tag
  • Loading branch information
cbeer committed Feb 12, 2014
1 parent 12643e1 commit 99dc688
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
6 changes: 5 additions & 1 deletion app/helpers/blacklight/catalog_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,11 @@ def render_thumbnail_tag document, image_options = {}, url_options = {}
end

if value
link_to_document document, url_options.merge(:label => value)
if url_options === false || url_options[:suppress_link]
value
else
link_to_document document, url_options.merge(:label => value)
end
end
end

Expand Down
27 changes: 20 additions & 7 deletions spec/helpers/catalog_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ def render_grouped_response?
end

describe "render_thumbnail_tag" do
let(:document) { double }
it "should call the provided thumbnail method" do
helper.stub(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new(:thumbnail_method => :xyz) ))
document = double()
helper.stub(:xyz => "some-thumbnail")

helper.should_receive(:link_to_document).with(document, :label => "some-thumbnail")
Expand All @@ -188,27 +188,40 @@ def render_grouped_response?

it "should create an image tag from the given field" do
helper.stub(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new(:thumbnail_field => :xyz) ))
document = double()


document.stub(:has?).with(:xyz).and_return(true)
document.stub(:first).with(:xyz).and_return("http://example.com/some.jpg")

helper.should_receive(:link_to_document).with(document, :label => image_tag("http://example.com/some.jpg"))
helper.render_thumbnail_tag document
end

it "should not link to the document if the url options are false" do
helper.stub(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new(:thumbnail_method => :xyz) ))
helper.stub(:xyz => "some-thumbnail")

result = helper.render_thumbnail_tag document, {}, false
expect(result).to eq "some-thumbnail"
end

it "should not link to the document if the url options have :suppress_link" do
helper.stub(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new(:thumbnail_method => :xyz) ))
helper.stub(:xyz => "some-thumbnail")

result = helper.render_thumbnail_tag document, {}, suppress_link: true
expect(result).to eq "some-thumbnail"
end


it "should return nil if no thumbnail is available" do
helper.stub(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new() ))

document = double()
expect(helper.render_thumbnail_tag document).to be_nil
end

it "should return nil if no thumbnail is returned from the thumbnail method" do
helper.stub(:blacklight_config => Blacklight::Configuration.new(:index => Blacklight::OpenStructWithHashAccess.new(:thumbnail_method => :xyz) ))
helper.stub(:xyz => nil)
document = double()


expect(helper.render_thumbnail_tag document).to be_nil
end
end
Expand Down

0 comments on commit 99dc688

Please sign in to comment.