Skip to content

Commit a65fb7d

Browse files
committed
Merge pull request #834 from projectblacklight/issue-833
deep-merge context data attributes with link_to_document options; fixes #833
2 parents 49e53f4 + 0954083 commit a65fb7d

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

app/helpers/blacklight/url_helper_behavior.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def link_to_document(doc, opts={:label=>nil, :counter => nil})
2727
end
2828

2929
def document_link_params(doc, opts)
30-
session_tracking_params(doc, opts[:counter]).merge(opts.reject { |k,v| [:label, :counter].include? k })
30+
session_tracking_params(doc, opts[:counter]).deep_merge(opts.except(:label, :counter))
3131
end
3232
protected :document_link_params
3333

spec/helpers/url_helper_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,14 @@
248248
expect(helper.link_to_document(@document, { :label => :title_display, :counter => 5 })).to match /\/catalog\/123456\/track\?counter=5/
249249
end
250250

251+
it "should merge the data- attributes from the options with the counter params" do
252+
data = {'id'=>'123456','title_display'=>['654321']}
253+
@document = SolrDocument.new(data)
254+
link = helper.link_to_document @document, { data: { x: 1 } }
255+
expect(link).to have_selector '[data-x]'
256+
expect(link).to have_selector '[data-context-href]'
257+
end
258+
251259
it "passes on the title attribute to the link_to_with_data method" do
252260
@document = SolrDocument.new('id'=>'123456')
253261
expect(helper.link_to_document(@document,:label=>"Some crazy long label...",:title=>"Some crazy longer label")).to match(/title=\"Some crazy longer label\"/)

0 commit comments

Comments
 (0)