Skip to content

Commit

Permalink
Merge pull request #1176 from projectblacklight/release-5.11-backports
Browse files Browse the repository at this point in the history
5.11 backports
  • Loading branch information
cjcolvar committed Mar 26, 2015
2 parents 8588764 + 6220777 commit 06ab74b
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 16 deletions.
2 changes: 1 addition & 1 deletion app/helpers/blacklight/configuration_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def view_label view
# @param [Symbol] any number of additional keys
# @param [Symbol] ...
def field_label *i18n_keys
first, *rest = i18n_keys
first, *rest = i18n_keys.compact

t(first, default: rest)
end
Expand Down
7 changes: 6 additions & 1 deletion app/helpers/blacklight/url_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,15 @@ def session_tracking_params document, counter
return {}
end

{ :data => {:'context-href' => track_solr_document_path(document, per_page: params.fetch(:per_page, search_session['per_page']), counter: counter, search_id: current_search_session.try(:id))}}
{ :data => {:'context-href' => session_tracking_path(document, per_page: params.fetch(:per_page, search_session['per_page']), counter: counter, search_id: current_search_session.try(:id))}}
end
protected :session_tracking_params

##
# Get the URL for tracking search sessions across pages using polymorphic routing
def session_tracking_path document, params = {}
polymorphic_path([:track, document], params)
end

#
# link based helpers ->
Expand Down
2 changes: 1 addition & 1 deletion app/views/catalog/_sms_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

</div>
<% @documents.each do |doc| %>
<%=hidden_field_tag "id[]", doc.get(:id)%>
<%=hidden_field_tag "id[]", doc.id %>
<% end %>
</div>
<div class="modal-footer">
Expand Down
2 changes: 1 addition & 1 deletion lib/blacklight/configuration/facet_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def normalize! blacklight_config = nil

self.collapse = true if self.collapse.nil?
self.show = true if self.show.nil?
self.if ||= self.show
self.if = self.show if self.if.nil?

super

Expand Down
2 changes: 1 addition & 1 deletion lib/blacklight/configuration/search_field.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Blacklight
class Configuration::SearchField < Blacklight::Configuration::Field
def normalize! blacklight_config = nil
self.if ||= self.include_in_simple_select
self.if = self.include_in_simple_select if self.if.nil?

super
self.qt ||= blacklight_config.default_solr_params[:qt] if blacklight_config && blacklight_config.default_solr_params
Expand Down
24 changes: 19 additions & 5 deletions lib/blacklight/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module Blacklight::Document
include Blacklight::Document::Extensions
end

attr_reader :response
attr_reader :response, :_source
alias_method :solr_response, :response

def initialize(source_doc={}, response=nil)
Expand All @@ -52,11 +52,19 @@ def persisted?
# If a method is missing, it gets sent to @_source
# with all of the original params and block
def method_missing(m, *args, &b)
@_source.send(m, *args, &b)
if _source and _source.respond_to? m
_source.send(m, *args, &b)
else
super
end
end

def respond_to_missing? *args
(_source && _source.respond_to?(*args)) || super
end

def [] *args
@_source.send :[], *args
_source.send :[], *args
end

def _read_attribute(attr)
Expand Down Expand Up @@ -85,7 +93,7 @@ def has?(k, *values)
end

def key? k
@_source.key? k
_source.key? k
end

# helper
Expand Down Expand Up @@ -116,7 +124,7 @@ def to_param
end

def as_json(options = nil)
@_source.as_json(options)
_source.as_json(options)
end

def to_partial_path
Expand All @@ -139,6 +147,12 @@ def highlight_field k
nil
end

##
# Implementations that support More-Like-This should override this method
# to return an array of documents that are like this one.
def more_like_this
[]
end

# Certain class-level methods needed for the document-specific
# extendability architecture
Expand Down
7 changes: 7 additions & 0 deletions spec/helpers/configuration_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@

label = helper.field_label :key_a, :key_b, "default text"
end

it "should compact nil keys (fixes rails/rails#19419)" do
allow(helper).to receive(:t).with(:key_a, default: [:key_b])

label = helper.field_label :key_a, nil, :key_b

end
end

describe "#default_per_page" do
Expand Down
11 changes: 11 additions & 0 deletions spec/helpers/url_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -499,4 +499,15 @@
expect(url).to eq helper.bookmarks_url(format: :html, encrypted_user_id: 'xyz')
end
end

describe "#session_tracking_path" do
let(:document) { SolrDocument.new(id: 1) }
it "should determine the correct route for the document class" do
expect(helper.session_tracking_path(document)).to eq helper.track_solr_document_path(document)
end

it "should pass through tracking parameters" do
expect(helper.session_tracking_path(document, x: 1)).to eq helper.track_solr_document_path(document, x: 1)
end
end
end
39 changes: 33 additions & 6 deletions spec/lib/blacklight/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,25 @@
"another_field_facet" => {},
"a_facet_field" => {},
})
expect { |b| @config.add_index_field "*_facet", &b }.to yield_control.twice

expect(@config.index_fields.keys).to eq ["some_field_facet", "another_field_facet"]
expect { |b| @config.add_facet_field "*_facet", &b }.to yield_control.twice
expect(@config.facet_fields.keys).to eq ["some_field_facet", "another_field_facet"]
end

describe "if/unless conditions with legacy show parameter" do
it "should be hidden if the if condition is false" do
expect(@config.add_facet_field("hidden", if: false).if).to eq false
expect(@config.add_facet_field("hidden_with_legacy", if: false, show: true).if).to eq false
end

it "should be true if the if condition is true" do
expect(@config.add_facet_field("hidden", if: true).if).to eq true
expect(@config.add_facet_field("hidden_with_legacy", if: true, show: false).if).to eq true
end

it "should be true if the if condition is missing" do
expect(@config.add_facet_field("hidden", show: true).if).to eq true
end
end
end

describe "add_index_field" do
Expand Down Expand Up @@ -261,7 +275,6 @@

expect(@config.index_fields.keys).to eq ["some_field_display", "another_field_display"]
end

end

describe "add_show_field" do
Expand Down Expand Up @@ -370,8 +383,22 @@

expect(@config.search_fields["author_name"].label).to eq "Author Name"
end



describe "if/unless conditions with legacy include_in_simple_search" do
it "should be hidden if the if condition is false" do
expect(@config.add_search_field("hidden", if: false).if).to eq false
expect(@config.add_search_field("hidden_with_legacy", if: false, include_in_simple_search: true).if).to eq false
end

it "should be true if the if condition is true" do
expect(@config.add_search_field("hidden", if: true).if).to eq true
expect(@config.add_search_field("hidden_with_legacy", if: true, include_in_simple_search: false).if).to eq true
end

it "should be true if the if condition is missing" do
expect(@config.add_search_field("hidden", include_in_simple_search: true).if).to eq true
end
end
end

describe "add_sort_field" do
Expand Down

0 comments on commit 06ab74b

Please sign in to comment.