summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2013-05-09 07:12:42 -0600
committermo khan <mo@mokhan.ca>2013-05-09 07:12:42 -0600
commit3c282dd665dfdb6cd5880da5d3394b347f4739e8 (patch)
tree3d8d1b21c2f9ecf0141464d9da479586bceed007
parentfdb71218fcf4f514cfbceb5ceb0df54166839923 (diff)
redirect to root url instead of route that does not exist.
https://cakeside.airbrake.io/groups/57695470
-rw-r--r--app/controllers/search_controller.rb4
-rw-r--r--spec/controllers/search_controller_spec.rb47
2 files changed, 30 insertions, 21 deletions
diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb
index 74502e0a..26e66d65 100644
--- a/app/controllers/search_controller.rb
+++ b/app/controllers/search_controller.rb
@@ -1,8 +1,8 @@
class SearchController < ApplicationController
def index
@search = params[:q]
- if @search.blank?
- redirect_to(home_index_url)
+ if @search.blank?
+ redirect_to(root_url)
else
@creations = Creation.includes(:user).search(@search).page(params[:page]).per(100)
@members = User.includes(:avatar).where("upper(name) like upper(?)", "%#{@search}%")
diff --git a/spec/controllers/search_controller_spec.rb b/spec/controllers/search_controller_spec.rb
index 741963f2..10f804e8 100644
--- a/spec/controllers/search_controller_spec.rb
+++ b/spec/controllers/search_controller_spec.rb
@@ -2,31 +2,40 @@ require 'spec_helper'
describe SearchController do
describe "GET 'index'" do
- let!(:user) { FactoryGirl.create(:user, :name => 'cake') }
- let!(:bob) { FactoryGirl.create(:user, :name => 'bob') }
- let!(:cake) { FactoryGirl.create(:creation, :name => 'cake') }
- let!(:donut) { FactoryGirl.create(:creation, :name => 'donut') }
+ context "when no search query is given" do
+ before { get :index }
- before { get :index, { :q => 'cake' } }
-
- it "should be successful" do
- response.should be_success
+ it "should redirect you to the home page" do
+ response.should redirect_to(root_url)
+ end
end
+ context "when a valid search query is given" do
+ let!(:user) { FactoryGirl.create(:user, :name => 'cake') }
+ let!(:bob) { FactoryGirl.create(:user, :name => 'bob') }
+ let!(:cake) { FactoryGirl.create(:creation, :name => 'cake') }
+ let!(:donut) { FactoryGirl.create(:creation, :name => 'donut') }
- it "should return all creations that have a matching name" do
- assigns(:creations).should include(cake)
- end
+ before { get :index, { :q => 'cake' } }
- it "should not include cakes that do not match" do
- assigns(:creations).should_not include(donut)
- end
+ it "should be successful" do
+ response.should be_success
+ end
- it "should return all makers that match" do
- assigns(:members).should include(user)
- end
+ it "should return all creations that have a matching name" do
+ assigns(:creations).should include(cake)
+ end
+
+ it "should not include cakes that do not match" do
+ assigns(:creations).should_not include(donut)
+ end
+
+ it "should return all makers that match" do
+ assigns(:members).should include(user)
+ end
- it "should not include makers with names that do not match" do
- assigns(:members).should_not include(bob)
+ it "should not include makers with names that do not match" do
+ assigns(:members).should_not include(bob)
+ end
end
end
end