Browse files

Preserve the filter across section changes.

From a conversation with John, this seems to fits better with the way
people would search for an artefact without knowing the section it's in.
  • Loading branch information...
1 parent 2756347 commit 331479a5997bad71470c42a639b379fd4516b1df @fatbusinessman fatbusinessman committed Mar 21, 2013
Showing with 28 additions and 1 deletion.
  1. +4 −1 app/helpers/sections_helper.rb
  2. +24 −0 test/functional/artefacts_controller_test.rb
View
5 app/helpers/sections_helper.rb
@@ -55,7 +55,10 @@ def parent_section_tab_list(options)
css_class = "active"
end
content_tag(:li, :class => css_class) do
- link_to(title, :section => tag_id)
+ link_params = { :section => tag_id, :filter => params[:filter] }
+ link_params.reject! { |key, value| value.blank? }
+
+ link_to(title, link_params)
end
end
safe_join(output)
View
24 test/functional/artefacts_controller_test.rb
@@ -47,6 +47,30 @@ class ArtefactsControllerTest < ActionController::TestCase
end
end
+ should "show links to filter by section" do
+ FactoryGirl.create(:tag, tag_id: "crime", title: "Crime", tag_type: "section")
+
+ get :index
+ assert_select "a[href=/artefacts?section=all]"
+ assert_select "a[href=/artefacts?section=crime]"
+ end
+
+ should "include the filter parameter in section links" do
+ FactoryGirl.create(:tag, tag_id: "crime", title: "Crime", tag_type: "section")
+
+ get :index, filter: "tax"
+ assert_select "a[href=/artefacts?filter=tax&amp;section=all]"
+ assert_select "a[href=/artefacts?filter=tax&amp;section=crime]"
+ end
+
+ should "not include empty filters in section links" do
+ FactoryGirl.create(:tag, tag_id: "crime", title: "Crime", tag_type: "section")
+
+ get :index, filter: ""
+ assert_select "a[href=/artefacts?section=all]"
+ assert_select "a[href=/artefacts?section=crime]"
+ end
+
context "GET new" do
should "render only the non-whitehall link as active" do

0 comments on commit 331479a

Please sign in to comment.