Skip to content
This repository has been archived by the owner on Apr 26, 2022. It is now read-only.

Commit

Permalink
fix for crashing events search
Browse files Browse the repository at this point in the history
  • Loading branch information
jlapier committed Feb 17, 2012
1 parent ef8bf0b commit 413213f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
5 changes: 3 additions & 2 deletions app/controllers/event_calendar/events_controller.rb
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions 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 %>
Expand Down
12 changes: 12 additions & 0 deletions spec/controllers/event_calendar/events_controller_spec.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions vendor/plugins/searchable_by/lib/searchable_by.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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.