Created
March 11, 2013 10:25
-
-
Save adamphillips/5133296 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 713527f239f58ab21a40226e2816176c93152d50 Mon Sep 17 00:00:00 2001 | |
From: Adam Phillips <[email protected]> | |
Date: Mon, 11 Mar 2013 09:56:50 +0000 | |
Subject: [PATCH 1/2] Rejigged existing CSE search controller tests | |
Rejigged the existing tests into the new format before updating them to | |
remove bookfairs and writers. | |
--- | |
.../test/functional/cse_search_controller_test.rb | 119 ++++++++++++--------- | |
1 file changed, 68 insertions(+), 51 deletions(-) | |
diff --git a/store/test/functional/cse_search_controller_test.rb b/store/test/functional/cse_search_controller_test.rb | |
index 9367221..a5151d4 100644 | |
--- a/store/test/functional/cse_search_controller_test.rb | |
+++ b/store/test/functional/cse_search_controller_test.rb | |
@@ -2,61 +2,78 @@ require 'test_helper' | |
class CseSearchControllerTest < ActionController::TestCase | |
- | |
- def setup | |
- @request.host = SCHOLASTIC_HOST | |
- end | |
- def test_search | |
- get :search, {:search => {:query => 'some search'}} | |
- assert_response :success | |
- assert assigns(:results) | |
- end | |
- | |
- def test_search_no_query | |
- get :search, :search => {:query => ''} | |
- assert_response :success | |
- assert assigns(:results) | |
- end | |
+ on SCHOLASTIC_HOST do | |
+ action :search do | |
+ context 'when no query is passed' do | |
+ setup do | |
+ @params = {:search => {:query => ''}} | |
+ end | |
- def test_search_has_noindex | |
- get :search, :search => {:query => "stuff"} | |
- assert_response :success | |
- assert_tag :tag => "meta", :attributes => {:name => "robots", :content => "noindex, nofollow"} | |
- end | |
- | |
- def test_search_logs_activity | |
- assert_difference 'LoggedActivity.count' do | |
- get :search, :search => {:query => "stuff"}, :log => "t" | |
- end | |
- end | |
- | |
- def test_no_query_no_logged_activity | |
- assert_no_difference 'LoggedActivity.count' do | |
- get :search, :search => {:query => ''}, :log => "t" | |
- end | |
- end | |
- | |
- def test_no_logged_activity_for_robots | |
- @request.user_agent = "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" | |
- assert_no_difference 'LoggedActivity.count' do | |
- get :search, :search => {:query => "stuff"}, :log => "t" | |
- end | |
- end | |
+ should_work | |
+ end | |
- def test_search_in_writers | |
- get :search, :search => {:query => 'stuff', :site => WRITERS_SHOP_ID} | |
- assert_response :success | |
- end | |
+ context 'with a query' do | |
+ setup do | |
+ @params = {:search => {:query => 'some search'}} | |
+ end | |
- def test_search_in_shop | |
- get :search, :search => {:query => 'stuff', :site => UK_SHOP_ID} | |
- assert_redirected_to search_search_index_url(:host => UK_SHOP_HOST, :search => {:query => 'stuff'}, :log => 't') | |
- end | |
+ should_work | |
+ should 'set nofollow metatag' do | |
+ do_request | |
+ assert_tag :tag => "meta", :attributes => {:name => "robots", :content => "noindex, nofollow"} | |
+ end | |
- def test_search_in_clubs | |
- get :search, :search => {:query => 'stuff', :site => CLUBS_KIDS_SHOP_ID} | |
- assert_redirected_to search_clubs_search_index_url(:host => CLUBS_KIDS_HOST, :search => {:query => 'stuff'}, :log => 't') | |
- end | |
+ context 'when :log is set to t' do | |
+ setup do | |
+ @params[:log] = 't' | |
+ end | |
+ | |
+ should_change 'LoggedActivity.count', 1 | |
+ context 'but the search is empty' do | |
+ setup do | |
+ @params[:search][:query] = '' | |
+ end | |
+ | |
+ should_not_change 'LoggedActivity.count' | |
+ end | |
+ | |
+ context 'but the request is from a robot' do | |
+ setup do | |
+ @request.user_agent = "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" | |
+ end | |
+ | |
+ should_not_change 'LoggedActivity.count' | |
+ end | |
+ end | |
+ | |
+ context 'when site is set' do | |
+ context 'to Writers' do | |
+ setup do | |
+ @params[:search][:site] = WRITERS_SHOP_ID | |
+ end | |
+ | |
+ should_work | |
+ end | |
+ | |
+ context 'to the UK Shop' do | |
+ setup do | |
+ @params[:search][:site] = UK_SHOP_ID | |
+ end | |
+ | |
+ should_redirect :to => [:search_search_index_url, {:host => UK_SHOP_HOST, :search => {:query => 'some search'}, :log => 't'}] | |
+ end | |
+ | |
+ context 'to Clubs Kids' do | |
+ setup do | |
+ @params[:search][:site] = CLUBS_KIDS_SHOP_ID | |
+ end | |
+ | |
+ should_redirect :to => [:search_clubs_search_index_url, {:host => CLUBS_KIDS_HOST, :search => {:query => 'some search'}, :log => 't'}] | |
+ end | |
+ end | |
+ end | |
+ end | |
+ end | |
end | |
-- | |
1.7.12.4 (Apple Git-37) | |
From 89c1aaeab8fc1865af75e84cb9b1a2d1c3351211 Mon Sep 17 00:00:00 2001 | |
From: Adam Phillips <[email protected]> | |
Date: Mon, 11 Mar 2013 10:22:47 +0000 | |
Subject: [PATCH 2/2] Removed Bookfairs and Writers searches from corporate | |
site | |
As part of the Solr upgrade, it was decided that the Bookfairs and | |
Writers searches do not provide any benefit to users and so should be | |
removed from the corporate search. | |
--- | |
store/app/controllers/cse_search_controller.rb | 2 +- | |
.../shared/navigation/_search_scholastic.html.erb | 2 +- | |
store/test/functional/cse_search_controller_test.rb | 20 ++++++++++++++------ | |
3 files changed, 16 insertions(+), 8 deletions(-) | |
diff --git a/store/app/controllers/cse_search_controller.rb b/store/app/controllers/cse_search_controller.rb | |
index db3ddc0..f87aa67 100644 | |
--- a/store/app/controllers/cse_search_controller.rb | |
+++ b/store/app/controllers/cse_search_controller.rb | |
@@ -34,7 +34,7 @@ class CseSearchController < FatController | |
site = params[:search][:site] | |
return if site.blank? | |
site = site.to_i | |
- return if [WRITERS_SHOP_ID, WRITERS_IE_SHOP_ID, BOOKFAIRS_SHOP_ID, BOOKFAIRS_IE_SHOP_ID].include?(site) | |
+ return unless [UK_SHOP_ID, EDUCATION_SHOP_ID, CLUBS_KIDS_SHOP_ID].include?(site) | |
if site == CLUBS_KIDS_SHOP_ID | |
redirect_to search_clubs_search_index_url(:host => Shop.for_id(site).host, | |
diff --git a/store/app/views/shared/navigation/_search_scholastic.html.erb b/store/app/views/shared/navigation/_search_scholastic.html.erb | |
index 4a7cdcf..a67cdd8 100644 | |
--- a/store/app/views/shared/navigation/_search_scholastic.html.erb | |
+++ b/store/app/views/shared/navigation/_search_scholastic.html.erb | |
@@ -9,7 +9,7 @@ | |
<div class="hidden"> | |
<label for="search_site">Where do you want to search?</label> | |
- <%= f.select :site, [["Scholastic Shop", "25"], ["Education", "3"], ["Kids Book Club", "4"], ["Book Fairs", "5"], ["Book Clubs Shop", "25"], ["We Are Writers!", "8"], ["Everything", nil]], :class => "select" %> | |
+ <%= f.select :site, [["Scholastic Shop", "25"], ["Education", "3"], ["Kids Book Club", "4"], ["Book Clubs Shop", "25"], ["Everything", nil]], :class => "select" %> | |
</div><!-- /#department-chooser --> | |
</fieldset> | |
<% end %> | |
diff --git a/store/test/functional/cse_search_controller_test.rb b/store/test/functional/cse_search_controller_test.rb | |
index a5151d4..fca8aea 100644 | |
--- a/store/test/functional/cse_search_controller_test.rb | |
+++ b/store/test/functional/cse_search_controller_test.rb | |
@@ -49,20 +49,20 @@ class CseSearchControllerTest < ActionController::TestCase | |
end | |
context 'when site is set' do | |
- context 'to Writers' do | |
+ context 'to the UK Shop' do | |
setup do | |
- @params[:search][:site] = WRITERS_SHOP_ID | |
+ @params[:search][:site] = UK_SHOP_ID | |
end | |
- should_work | |
+ should_redirect :to => [:search_search_index_url, {:host => UK_SHOP_HOST, :search => {:query => 'some search'}, :log => 't'}] | |
end | |
- context 'to the UK Shop' do | |
+ context 'to Education' do | |
setup do | |
- @params[:search][:site] = UK_SHOP_ID | |
+ @params[:search][:site] = EDUCATION_SHOP_ID | |
end | |
- should_redirect :to => [:search_search_index_url, {:host => UK_SHOP_HOST, :search => {:query => 'some search'}, :log => 't'}] | |
+ should_redirect :to => [:search_search_index_url, {:host => EDUCATION_HOST, :search => {:query => 'some search'}, :log => 't'}] | |
end | |
context 'to Clubs Kids' do | |
@@ -72,6 +72,14 @@ class CseSearchControllerTest < ActionController::TestCase | |
should_redirect :to => [:search_clubs_search_index_url, {:host => CLUBS_KIDS_HOST, :search => {:query => 'some search'}, :log => 't'}] | |
end | |
+ | |
+ context 'to anything else' do | |
+ setup do | |
+ @params[:search][:site] = 123 | |
+ end | |
+ | |
+ should_work | |
+ end | |
end | |
end | |
end | |
-- | |
1.7.12.4 (Apple Git-37) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment