diff --git a/app/controllers/public/search_controller.rb b/app/controllers/public/search_controller.rb index a7a12d7..df2b3b8 100644 --- a/app/controllers/public/search_controller.rb +++ b/app/controllers/public/search_controller.rb @@ -158,8 +158,7 @@ class SearchController < ApplicationController @filtered_query = remove_stop_words(@query) @product_category = ProductCategory.find(params[:product_category]) if params[:product_category] - # FIXME name is not unique - @region = City.find_by_id(params[:city]) if params[:city] + @region = City.find_by_id(params[:city]) if !params[:city].blank? && params[:city] =~ /^\d+$/ # how many assets we are searching for? number_of_result_assets = @searching.values.select{|v| v}.size diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index cef3322..bf68a67 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -622,4 +622,13 @@ module ApplicationHelper form_for(name, object, { :builder => NoosferoFormBuilder }.merge(options), &proc) end + def search_page_title(title, options={}) + title = "

" + title + "

" + title += "

" + _("Searched for '%s'") % options[:query] + "

" if !options[:query].blank? + title += "

" + _("In category %s") % options[:category] + "

" if !options[:category].blank? + title += "

" + _("within %d from %s") % [options[:distance], options[:region]] + "

" if !options[:distance].blank? && !options[:region].blank? + title += "

" + _("%d results found") % options[:total_results] + "

" if !options[:total_results].blank? + title + end + end diff --git a/app/views/search/index.rhtml b/app/views/search/index.rhtml index f1f21fd..3e7a68e 100644 --- a/app/views/search/index.rhtml +++ b/app/views/search/index.rhtml @@ -1,6 +1,6 @@
-

<%=h @category ? (_('Search results for "%{query}" in "%{category}"') % { :query => @query, :category => @category.name}) : (_('Search results for "%s"') % @query) %>

+<%= search_page_title('', :query => @query, :category => @category ? @category.name : nil, :total_results => @total_results) %> <%= render :partial => 'search_form', :locals => { :form_title => _("Refine your search"), :simple_search => true } %> diff --git a/app/views/search/people.rhtml b/app/views/search/people.rhtml index 62c2d84..ef75883 100644 --- a/app/views/search/people.rhtml +++ b/app/views/search/people.rhtml @@ -1,22 +1,8 @@ -<% if @query.blank? %> -

- <% if @category %> - <%= @category.name %>:
- <% end %> - - <%= @asset_name %> - <% if params[:initial] %> - <%= '(%s)' % params[:initial].upcase %> - <% else %> - <%= _('(recently added)') %> - <% end %> -

-<% else %> -

<%= @asset_name %>: <%= h(@category ? (_('Search results for "%{query}" in "%{category}"') % { :query => @query, :category => @category.name}) : (_('Search results for "%s"') % @query)) %>

-
- <%= link_to _('Browse by name'), :action => 'assets', :asset => @results.keys.first %> -
-<% end %> +<%= search_page_title( _('People'), { :query => @query, + :category => @category, + :total_results => @total_results, + :region => @region ? @region.name : nil, + :distance => @radius } ) %> <%= render :partial => 'search_form', :locals => { :form_title => @query.blank? ? _('Search') : _("Refine your search"), :simple_search => true } %> diff --git a/app/views/search/products.rhtml b/app/views/search/products.rhtml index 2272487..7f70008 100644 --- a/app/views/search/products.rhtml +++ b/app/views/search/products.rhtml @@ -1,14 +1,8 @@ -

- <% if !@query.blank? %> - <%=h @category ? (_('Products and Services results for "%{query}" of enterprises in "%{category}"') % { :query => @query, :category => @category.name}) : (_('Products and Services results for "%s"') % @query) %> - <% else %> - <%=h @category ? (_('Products and Services of enterprises in "%s"') % @category.name) : _('Products and Services') %> - <% end %> -

- -<% if @radius && @region %> -

<%=h (_('Within %s km from %s') % [@radius, @region.name]) %>

-<% end %> +<%= search_page_title( _('Products and Services'), { :query => @query, + :category => @category, + :total_results => @total_results, + :region => @region ? @region.name : nil, + :distance => @radius } ) %> <%= render :partial => 'search_form', :locals => { :form_title => _("Refine your search"), :simple_search => true } %> diff --git a/lib/sqlite_extension.rb b/lib/sqlite_extension.rb index e4dd9df..4e2bf8a 100644 --- a/lib/sqlite_extension.rb +++ b/lib/sqlite_extension.rb @@ -1,4 +1,4 @@ -if ActiveRecord::Base.connection.adapter_name =~ /^sqlite$/i +if ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters::SQLite3Adapter) database = ActiveRecord::Base.connection.raw_connection diff --git a/script/fbes_populate_helper.rb b/script/fbes_populate_helper.rb index 4992db7..30e1fb5 100644 --- a/script/fbes_populate_helper.rb +++ b/script/fbes_populate_helper.rb @@ -2,33 +2,33 @@ require File.dirname(__FILE__) + '/../config/environment' require 'console_with_helpers' STATES = { - 12 => Region.find_by_name('Acre'), - 27 => Region.find_by_name('Alagoas'), - 13 => Region.find_by_name('Amazonas'), - 16 => Region.find_by_name('Amapá'), - 29 => Region.find_by_name('Bahia'), - 23 => Region.find_by_name('Ceará'), - 53 => Region.find_by_name('Distrito Federal'), - 32 => Region.find_by_name('Espírito Santo'), - 52 => Region.find_by_name('Goiás'), - 21 => Region.find_by_name('Maranhão'), - 31 => Region.find_by_name('Minas Gerais'), - 50 => Region.find_by_name('Mato Grosso do Sul'), - 51 => Region.find_by_name('Mato Grosso'), - 15 => Region.find_by_name('Pará'), - 25 => Region.find_by_name('Paraíba'), - 26 => Region.find_by_name('Pernambuco'), - 22 => Region.find_by_name('Piauí'), - 41 => Region.find_by_name('Paraná'), - 33 => Region.find_by_name('Rio de Janeiro'), - 24 => Region.find_by_name('Rio Grande do Norte'), - 11 => Region.find_by_name('Rondônia'), - 14 => Region.find_by_name('Roraima'), - 43 => Region.find_by_name('Rio Grande do Sul'), - 42 => Region.find_by_name('Santa Catarina'), - 28 => Region.find_by_name('Sergipe'), - 35 => Region.find_by_name('São Paulo'), - 17 => Region.find_by_name('Tocantins'), + 12 => State.find_by_name('Acre'), + 27 => State.find_by_name('Alagoas'), + 13 => State.find_by_name('Amazonas'), + 16 => State.find_by_name('Amapá'), + 29 => State.find_by_name('Bahia'), + 23 => State.find_by_name('Ceará'), + 53 => State.find_by_name('Distrito Federal'), + 32 => State.find_by_name('Espírito Santo'), + 52 => State.find_by_name('Goiás'), + 21 => State.find_by_name('Maranhão'), + 31 => State.find_by_name('Minas Gerais'), + 50 => State.find_by_name('Mato Grosso do Sul'), + 51 => State.find_by_name('Mato Grosso'), + 15 => State.find_by_name('Pará'), + 25 => State.find_by_name('Paraíba'), + 26 => State.find_by_name('Pernambuco'), + 22 => State.find_by_name('Piauí'), + 41 => State.find_by_name('Paraná'), + 33 => State.find_by_name('Rio de Janeiro'), + 24 => State.find_by_name('Rio Grande do Norte'), + 11 => State.find_by_name('Rondônia'), + 14 => State.find_by_name('Roraima'), + 43 => State.find_by_name('Rio Grande do Sul'), + 42 => State.find_by_name('Santa Catarina'), + 28 => State.find_by_name('Sergipe'), + 35 => State.find_by_name('São Paulo'), + 17 => State.find_by_name('Tocantins'), } COUNT = { @@ -53,8 +53,8 @@ end def new_region(name, parent, lat, lng) path = (parent ? parent.path + '/' : '') + name.to_slug - region = Region.find_by_path(path) - region = Region.create!(:name => name, :parent => parent, :lat => lat, :lng => lng, :environment => $default_env) unless region + region = City.find_by_path(path) + region = City.create!(:name => name, :parent => parent, :lat => lat, :lng => lng, :environment => $default_env) unless region step(:regions) region end @@ -62,8 +62,8 @@ end def new_ent(data, products, consumptions) count = 2 ident = data[:identifier] - idents = Enterprise.find(:all, :conditons => ['identifier like ?', ident + '%']).map(&:identifier) - while idents.includes?(ident) + idents = Enterprise.find(:all, :conditions => ['identifier like ?', ident + '%']).map(&:identifier) + while idents.include?(ident) ident = data[:identifier] + "-#{count}" count += 1 end diff --git a/test/functional/search_controller_test.rb b/test/functional/search_controller_test.rb index 3244fe2..7091e8b 100644 --- a/test/functional/search_controller_test.rb +++ b/test/functional/search_controller_test.rb @@ -354,8 +354,9 @@ class SearchControllerTest < Test::Unit::TestCase should 'display option to search within a given point and distance' do get :popup - assert_tag :tag => 'input', :attributes => {:type => 'text', :name => 'radius'} - assert_tag :tag => 'input', :attributes => {:type => 'text', :name => 'region[name]'} + assert_tag :tag => 'select', :attributes => {:name => 'radius'} + assert_tag :tag => 'select', :attributes => {:name => 'state'} + assert_tag :tag => 'select', :attributes => {:name => 'city'} end should 'search in whole site when told so' do @@ -489,7 +490,8 @@ class SearchControllerTest < Test::Unit::TestCase child = Category.create!(:name => "Child Category", :environment => Environment.default, :parent => parent) get :index, :category_path => [ 'parent-category', 'child-category' ], :query => 'a sample search' - assert_tag :tag => 'h1', :content => /Search results for "a sample search" in "Child Category"/ + assert_tag :tag => 'h2', :content => /Searched for 'a sample search'/ + assert_tag :tag => 'h2', :content => /In category Child Category/ end should 'search in category hierachy' do @@ -885,6 +887,18 @@ class SearchControllerTest < Test::Unit::TestCase assert_tag :tag => "form", :attributes => { :class => 'search_form', :action => '/search' } end + should 'treat blank input for the city id' do + get :index, :city => '' + + assert_equal nil, assigns(:region) + end + + should 'treat non-numeric input for the city id' do + get :index, :city => 'bla' + + assert_equal nil, assigns(:region) + end + ################################################################## ################################################################## -- libgit2 0.21.2