Skip to content

Commit

Permalink
The user's view preference must be active to be used
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Feb 21, 2015
1 parent 58dd4e2 commit 056499f
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 23 deletions.
6 changes: 4 additions & 2 deletions app/helpers/blacklight/blacklight_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,10 @@ def field_value_separator
# @param [Hash] the query parameters to check
# @return [Symbol]
def document_index_view_type query_params=params
if query_params[:view] and blacklight_config.view.keys.include? query_params[:view].to_sym
query_params[:view].to_sym
view_param = query_params[:view]
view_param ||= session[:preferred_view]
if view_param and document_index_views.keys.include? view_param.to_sym
view_param.to_sym
else
default_document_index_view_type
end
Expand Down
1 change: 0 additions & 1 deletion lib/blacklight/catalog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ def has_search_parameters?
# them default to the last used view.
def preferred_view
session[:preferred_view] = params[:view] if params[:view]
params[:view] ||= session[:preferred_view]
end

##
Expand Down
20 changes: 0 additions & 20 deletions spec/controllers/catalog_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,6 @@ def assigns_response
get :index, q: 'foo', view: 'gallery'
expect(session[:preferred_view]).to eq 'gallery'
end

context "when they have a preferred view" do
before do
session[:preferred_view] = 'gallery'
end

context "and no view is specified" do
it "should use the saved preference" do
get :index, q: 'foo'
expect(controller.params[:view]).to eq 'gallery'
end
end

context "and a view is specified" do
it "should use the saved preference" do
get :index, q: 'foo', view: 'list'
expect(controller.params[:view]).to eq 'list'
end
end
end
end

# check each user manipulated parameter
Expand Down
44 changes: 44 additions & 0 deletions spec/helpers/blacklight_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,50 @@ def mock_document_app_helper_url *args
end
end

describe "#document_index_view_type" do
it "should default to the default view" do
allow(helper).to receive(:document_index_views).and_return(a: 1, b: 2)
allow(helper).to receive(:default_document_index_view_type).and_return(:xyz)
expect(helper.document_index_view_type).to eq :xyz
end

it "should use the query parameter" do
allow(helper).to receive(:document_index_views).and_return(a: 1, b: 2)
expect(helper.document_index_view_type(view: :a)).to eq :a
end

it "should use the default view if the requested view is not available" do
allow(helper).to receive(:default_document_index_view_type).and_return(:xyz)
allow(helper).to receive(:document_index_views).and_return(a: 1, b: 2)
expect(helper.document_index_view_type(view: :c)).to eq :xyz
end

context "when they have a preferred view" do
before do
session[:preferred_view] = :b
end

context "and no view is specified" do
it "should use the saved preference" do
allow(helper).to receive(:document_index_views).and_return(a: 1, b: 2, c: 3)
expect(helper.document_index_view_type).to eq :b
end

it "should use the default view if the preference is not available" do
allow(helper).to receive(:document_index_views).and_return(a: 1)
expect(helper.document_index_view_type).to eq :a
end
end

context "and a view is specified" do
it "should use the query parameter" do
allow(helper).to receive(:document_index_views).and_return(a: 1, b: 2, c: 3)
expect(helper.document_index_view_type(view: :c)).to eq :c
end
end
end
end

describe "#presenter_class" do
before do
allow(helper).to receive(:blacklight_config).and_return(blacklight_config)
Expand Down

0 comments on commit 056499f

Please sign in to comment.