diff options
-rw-r--r-- | app/controllers/application_controller.rb | 7 | ||||
-rw-r--r-- | app/views/public_body/_search_ahead.rhtml | 6 | ||||
-rw-r--r-- | spec/controllers/public_body_controller_spec.rb | 3 | ||||
-rw-r--r-- | spec/spec_helper.rb | 5 |
4 files changed, 16 insertions, 5 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0c8544932..2cdd5ee35 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -365,7 +365,10 @@ class ApplicationController < ActionController::Base def get_search_page_from_params return (params[:page] || "1").to_i end + def perform_search_typeahead(query, model) + @page = get_search_page_from_params + @per_page = 10 query_words = query.split(/ +(?![-+]+)/) if query_words.last.nil? || query_words.last.strip.length < 3 xapian_requests = nil @@ -376,8 +379,8 @@ class ApplicationController < ActionController::Base collapse = 'request_collapse' end options = { - :offset => 0, - :limit => 5, + :offset => (@page - 1) * @per_page, + :limit => @per_page, :sort_by_prefix => nil, :sort_by_ascending => true, :collapse_by_prefix => collapse, diff --git a/app/views/public_body/_search_ahead.rhtml b/app/views/public_body/_search_ahead.rhtml index 484d28256..7ade89b8e 100644 --- a/app/views/public_body/_search_ahead.rhtml +++ b/app/views/public_body/_search_ahead.rhtml @@ -1,4 +1,4 @@ -<p> +<div> <% if !@xapian_requests.nil? %> <% if @xapian_requests.results.size > 0 %> <h3><%= _('Top search results:') %></h3> @@ -13,9 +13,9 @@ <%= render :partial => 'body_listing_single', :locals => { :public_body => result[:model] } %> <% end %> </div> - <%= will_paginate WillPaginate::Collection.new(@page, 10, @xapian_requests.matches_estimated) %> + <%= will_paginate WillPaginate::Collection.new(@page, @per_page, @xapian_requests.matches_estimated) %> <% end %> -</p> +</div> diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb index a563b92ad..72fbe965c 100644 --- a/spec/controllers/public_body_controller_spec.rb +++ b/spec/controllers/public_body_controller_spec.rb @@ -181,6 +181,8 @@ end describe PublicBodyController, "when doing type ahead searches" do fixtures :public_bodies, :public_body_translations, :public_body_versions, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events, :track_things + integrate_views + it "should return nothing for the empty query string" do get :search_typeahead, :query => "" response.should render_template('public_body/_search_ahead') @@ -190,6 +192,7 @@ describe PublicBodyController, "when doing type ahead searches" do it "should return a body matching the given keyword, but not users with a matching description" do get :search_typeahead, :query => "Geraldine" response.should render_template('public_body/_search_ahead') + response.body.should include('search_ahead') assigns[:xapian_requests].results.size.should == 1 assigns[:xapian_requests].results[0][:model].name.should == public_bodies(:geraldine_public_body).name end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6c3a947ba..8dabfce7f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -144,7 +144,12 @@ if $tempfilecount.nil? return unless @response.template.controller.instance_eval { integrate_views? } # And then if HTML, not a redirect (302, 301) if @response.content_type == "text/html" && ! [301,302,401].include?(@response.response_code) + if @response.template.instance_eval("@_memoized__pick_partial_template").nil? validate_html(@response.body) + else + # it's a partial + validate_as_body(@response.body) + end end end end |