Permalink
Browse files

fix for crashing events search

  • Loading branch information...
1 parent ef8bf0b commit 413213f9387f3900d2b6dcbb83188f51b0ecff25 @jlapier committed Feb 17, 2012
View
5 app/controllers/event_calendar/events_controller.rb
@@ -88,8 +88,9 @@ def index
def search
@events = EventCalendar::Event.search(params[:q], {
- # :narrow_fields => params[:fields] ? params[:fields].keys : nil
- }).paginate :page => params[:page]
+ # :narrow_fields; => params[:fields] ? params[:fields].keys : nil
+ :page => (params[:page] || 1)
+ }) #.paginate :page => params[:page]
@link = EventCalendar::Link.new
end
View
4 app/views/event_calendar/events/search.html.erb
@@ -1,11 +1,11 @@
<h1>Events Search</h1>
-<%= render :partial => 'events/search_form' %>
+<%= render :partial => 'event_calendar/events/search_form' %>
<div class="span-16">
<h4><%= pluralize(@events.count, 'Result') %> Found</h4>
<% if @events.present? and @events.any? %>
- <%= render 'events/list_group', :events => @events, :closed_or_open => 'open' %>
+ <%= render 'event_calendar/events/list_group', :events => @events, :closed_or_open => 'open' %>
<% else %>
<p>Sorry no events could be located, try broadening your search terms or using partial words.</p>
<% end %>
View
12 spec/controllers/event_calendar/events_controller_spec.rb
@@ -28,6 +28,7 @@
subject.stub(:find).with("37"){ event }
subject.stub_chain(:past, :order){ ['past'] }
subject.stub_chain(:current, :order){ ['current'] }
+ subject.stub(:search).with("test", {}) { [event] }
end
describe "GET index" do
@@ -40,6 +41,17 @@
assigns(:current_events).should eq ['current']
end
end
+
+ describe "GET search" do
+ it "assigns events as @events" do
+ get :search, :q => "test"
+ assigns(:events).should eq [event]
+ end
+ it "renders the search page" do
+ get :search, :q => "test"
+ response.should render_template('search')
+ end
+ end
describe "GET index as JSON" do
context "no @events are found" do
View
6 vendor/plugins/searchable_by/lib/searchable_by.rb
@@ -69,9 +69,9 @@ def search(query, options = {})
search_options = options.reject { |k,v| [:require_all, :narrow_fields].include? k.to_sym }
if options.include?(:page)
# I think this will help us fail if will_paginate is not installed
- gem 'mislav-will_paginate'
+# gem 'mislav-will_paginate'
# take out require_all option when calling paginate
- paginate :all, search_options
+ paginate search_options
else
# take out require_all option when calling find
find :all, search_options
@@ -134,4 +134,4 @@ def search_conditions(query, require_all, cols_with_tables=nil )
end
end
end
-end
+end

0 comments on commit 413213f

Please sign in to comment.