Skip to content

Commit

Permalink
When rendering a field through a configured helper method, supply the…
Browse files Browse the repository at this point in the history
… field configuration as an additional option
  • Loading branch information
cbeer committed Nov 16, 2015
1 parent f143adc commit 1fe1d1c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/presenters/blacklight/document_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def get_field_values field, field_config, options = {}
# rendering values
case
when (field_config and field_config.helper_method)
@controller.send(field_config.helper_method, options.merge(:document => @document, :field => field, :value => value))
@controller.send(field_config.helper_method, options.merge(document: @document, field: field, config: field_config, value: value))
when (field_config and field_config.link_to_search)
link_field = if field_config.link_to_search === true
field_config.key
Expand Down
28 changes: 28 additions & 0 deletions spec/presenters/document_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -334,4 +334,32 @@ def mock_document_app_helper_url *args
expect(subject.document_show_html_title).to eq "value"
end
end

describe '#get_field_values' do
context 'for a field with the helper_method option' do
let(:field_name) { 'field_with_helper' }
let(:field_config) { config.add_facet_field 'field_with_helper', helper_method: 'render_field_with_helper' }

before do
document['field_with_helper'] = 'value'
end

it "should check call the helper method with arguments" do
allow(request_context).to receive(:render_field_with_helper) do |*args|
args.first
end

render_options = { a: 1 }

options = subject.get_field_values field_name, field_config, a: 1

expect(options).to include :document, :field, :value, :config, :a
expect(options[:document]).to eq document
expect(options[:field]).to eq 'field_with_helper'
expect(options[:value]).to eq 'value'
expect(options[:config]).to eq field_config
expect(options[:a]).to eq 1
end
end
end
end

0 comments on commit 1fe1d1c

Please sign in to comment.