Commit a51a5baaeb80296df2b8bad3ccfd381cd497c109

Authored by MoisesMachado
1 parent 1c0d419c

ActionItem501: fixed some bugs in teser


git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2190 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/public/search_controller.rb
... ... @@ -158,8 +158,7 @@ class SearchController < ApplicationController
158 158 @filtered_query = remove_stop_words(@query)
159 159 @product_category = ProductCategory.find(params[:product_category]) if params[:product_category]
160 160  
161   - # FIXME name is not unique
162   - @region = City.find_by_id(params[:city]) if params[:city]
  161 + @region = City.find_by_id(params[:city]) if !params[:city].blank? && params[:city] =~ /^\d+$/
163 162  
164 163 # how many assets we are searching for?
165 164 number_of_result_assets = @searching.values.select{|v| v}.size
... ...
app/helpers/application_helper.rb
... ... @@ -622,4 +622,13 @@ module ApplicationHelper
622 622 form_for(name, object, { :builder => NoosferoFormBuilder }.merge(options), &proc)
623 623 end
624 624  
  625 + def search_page_title(title, options={})
  626 + title = "<h1>" + title + "</h1>"
  627 + title += "<h2 align='center'>" + _("Searched for '%s'") % options[:query] + "</h2>" if !options[:query].blank?
  628 + title += "<h2 align='center'>" + _("In category %s") % options[:category] + "</h2>" if !options[:category].blank?
  629 + title += "<h2 align='center'>" + _("within %d from %s") % [options[:distance], options[:region]] + "</h2>" if !options[:distance].blank? && !options[:region].blank?
  630 + title += "<h2 align='center'>" + _("%d results found") % options[:total_results] + "</h2>" if !options[:total_results].blank?
  631 + title
  632 + end
  633 +
625 634 end
... ...
app/views/search/index.rhtml
1 1 <div id="search-page">
2 2  
3   -<h1> <%=h @category ? (_('Search results for "%{query}" in "%{category}"') % { :query => @query, :category => @category.name}) : (_('Search results for "%s"') % @query) %> </h1>
  3 +<%= search_page_title('', :query => @query, :category => @category ? @category.name : nil, :total_results => @total_results) %>
4 4  
5 5 <%= render :partial => 'search_form', :locals => { :form_title => _("Refine your search"), :simple_search => true } %>
6 6  
... ...
app/views/search/people.rhtml
1   -<% if @query.blank? %>
2   - <h1>
3   - <% if @category %>
4   - <%= @category.name %>:<br/>
5   - <% end %>
6   -
7   - <%= @asset_name %>
8   - <% if params[:initial] %>
9   - <%= '(%s)' % params[:initial].upcase %>
10   - <% else %>
11   - <%= _('(recently added)') %>
12   - <% end %>
13   - </h1>
14   -<% else %>
15   - <h1> <%= @asset_name %>: <%= h(@category ? (_('Search results for "%{query}" in "%{category}"') % { :query => @query, :category => @category.name}) : (_('Search results for "%s"') % @query)) %> </h1>
16   - <div style='text-align: center'>
17   - <%= link_to _('Browse by name'), :action => 'assets', :asset => @results.keys.first %>
18   - </div>
19   -<% end %>
  1 +<%= search_page_title( _('People'), { :query => @query,
  2 + :category => @category,
  3 + :total_results => @total_results,
  4 + :region => @region ? @region.name : nil,
  5 + :distance => @radius } ) %>
20 6  
21 7 <%= render :partial => 'search_form', :locals => { :form_title => @query.blank? ? _('Search') : _("Refine your search"), :simple_search => true } %>
22 8  
... ...
app/views/search/products.rhtml
1   -<h1>
2   - <% if !@query.blank? %>
3   - <%=h @category ? (_('Products and Services results for "%{query}" of enterprises in "%{category}"') % { :query => @query, :category => @category.name}) : (_('Products and Services results for "%s"') % @query) %>
4   - <% else %>
5   - <%=h @category ? (_('Products and Services of enterprises in "%s"') % @category.name) : _('Products and Services') %>
6   - <% end %>
7   -</h1>
8   -
9   -<% if @radius && @region %>
10   - <h2><%=h (_('Within %s km from %s') % [@radius, @region.name]) %><h2>
11   -<% end %>
  1 +<%= search_page_title( _('Products and Services'), { :query => @query,
  2 + :category => @category,
  3 + :total_results => @total_results,
  4 + :region => @region ? @region.name : nil,
  5 + :distance => @radius } ) %>
12 6  
13 7 <%= render :partial => 'search_form', :locals => { :form_title => _("Refine your search"), :simple_search => true } %>
14 8  
... ...
lib/sqlite_extension.rb
1   -if ActiveRecord::Base.connection.adapter_name =~ /^sqlite$/i
  1 +if ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters::SQLite3Adapter)
2 2  
3 3 database = ActiveRecord::Base.connection.raw_connection
4 4  
... ...
script/fbes_populate_helper.rb
... ... @@ -2,33 +2,33 @@ require File.dirname(__FILE__) + &#39;/../config/environment&#39;
2 2 require 'console_with_helpers'
3 3  
4 4 STATES = {
5   - 12 => Region.find_by_name('Acre'),
6   - 27 => Region.find_by_name('Alagoas'),
7   - 13 => Region.find_by_name('Amazonas'),
8   - 16 => Region.find_by_name('Amapá'),
9   - 29 => Region.find_by_name('Bahia'),
10   - 23 => Region.find_by_name('Ceará'),
11   - 53 => Region.find_by_name('Distrito Federal'),
12   - 32 => Region.find_by_name('Espírito Santo'),
13   - 52 => Region.find_by_name('Goiás'),
14   - 21 => Region.find_by_name('Maranhão'),
15   - 31 => Region.find_by_name('Minas Gerais'),
16   - 50 => Region.find_by_name('Mato Grosso do Sul'),
17   - 51 => Region.find_by_name('Mato Grosso'),
18   - 15 => Region.find_by_name('Pará'),
19   - 25 => Region.find_by_name('Paraíba'),
20   - 26 => Region.find_by_name('Pernambuco'),
21   - 22 => Region.find_by_name('Piauí'),
22   - 41 => Region.find_by_name('Paraná'),
23   - 33 => Region.find_by_name('Rio de Janeiro'),
24   - 24 => Region.find_by_name('Rio Grande do Norte'),
25   - 11 => Region.find_by_name('Rondônia'),
26   - 14 => Region.find_by_name('Roraima'),
27   - 43 => Region.find_by_name('Rio Grande do Sul'),
28   - 42 => Region.find_by_name('Santa Catarina'),
29   - 28 => Region.find_by_name('Sergipe'),
30   - 35 => Region.find_by_name('São Paulo'),
31   - 17 => Region.find_by_name('Tocantins'),
  5 + 12 => State.find_by_name('Acre'),
  6 + 27 => State.find_by_name('Alagoas'),
  7 + 13 => State.find_by_name('Amazonas'),
  8 + 16 => State.find_by_name('Amapá'),
  9 + 29 => State.find_by_name('Bahia'),
  10 + 23 => State.find_by_name('Ceará'),
  11 + 53 => State.find_by_name('Distrito Federal'),
  12 + 32 => State.find_by_name('Espírito Santo'),
  13 + 52 => State.find_by_name('Goiás'),
  14 + 21 => State.find_by_name('Maranhão'),
  15 + 31 => State.find_by_name('Minas Gerais'),
  16 + 50 => State.find_by_name('Mato Grosso do Sul'),
  17 + 51 => State.find_by_name('Mato Grosso'),
  18 + 15 => State.find_by_name('Pará'),
  19 + 25 => State.find_by_name('Paraíba'),
  20 + 26 => State.find_by_name('Pernambuco'),
  21 + 22 => State.find_by_name('Piauí'),
  22 + 41 => State.find_by_name('Paraná'),
  23 + 33 => State.find_by_name('Rio de Janeiro'),
  24 + 24 => State.find_by_name('Rio Grande do Norte'),
  25 + 11 => State.find_by_name('Rondônia'),
  26 + 14 => State.find_by_name('Roraima'),
  27 + 43 => State.find_by_name('Rio Grande do Sul'),
  28 + 42 => State.find_by_name('Santa Catarina'),
  29 + 28 => State.find_by_name('Sergipe'),
  30 + 35 => State.find_by_name('São Paulo'),
  31 + 17 => State.find_by_name('Tocantins'),
32 32 }
33 33  
34 34 COUNT = {
... ... @@ -53,8 +53,8 @@ end
53 53  
54 54 def new_region(name, parent, lat, lng)
55 55 path = (parent ? parent.path + '/' : '') + name.to_slug
56   - region = Region.find_by_path(path)
57   - region = Region.create!(:name => name, :parent => parent, :lat => lat, :lng => lng, :environment => $default_env) unless region
  56 + region = City.find_by_path(path)
  57 + region = City.create!(:name => name, :parent => parent, :lat => lat, :lng => lng, :environment => $default_env) unless region
58 58 step(:regions)
59 59 region
60 60 end
... ... @@ -62,8 +62,8 @@ end
62 62 def new_ent(data, products, consumptions)
63 63 count = 2
64 64 ident = data[:identifier]
65   - idents = Enterprise.find(:all, :conditons => ['identifier like ?', ident + '%']).map(&:identifier)
66   - while idents.includes?(ident)
  65 + idents = Enterprise.find(:all, :conditions => ['identifier like ?', ident + '%']).map(&:identifier)
  66 + while idents.include?(ident)
67 67 ident = data[:identifier] + "-#{count}"
68 68 count += 1
69 69 end
... ...
test/functional/search_controller_test.rb
... ... @@ -354,8 +354,9 @@ class SearchControllerTest &lt; Test::Unit::TestCase
354 354 should 'display option to search within a given point and distance' do
355 355 get :popup
356 356  
357   - assert_tag :tag => 'input', :attributes => {:type => 'text', :name => 'radius'}
358   - assert_tag :tag => 'input', :attributes => {:type => 'text', :name => 'region[name]'}
  357 + assert_tag :tag => 'select', :attributes => {:name => 'radius'}
  358 + assert_tag :tag => 'select', :attributes => {:name => 'state'}
  359 + assert_tag :tag => 'select', :attributes => {:name => 'city'}
359 360 end
360 361  
361 362 should 'search in whole site when told so' do
... ... @@ -489,7 +490,8 @@ class SearchControllerTest &lt; Test::Unit::TestCase
489 490 child = Category.create!(:name => "Child Category", :environment => Environment.default, :parent => parent)
490 491  
491 492 get :index, :category_path => [ 'parent-category', 'child-category' ], :query => 'a sample search'
492   - assert_tag :tag => 'h1', :content => /Search results for &quot;a sample search&quot; in &quot;Child Category&quot;/
  493 + assert_tag :tag => 'h2', :content => /Searched for 'a sample search'/
  494 + assert_tag :tag => 'h2', :content => /In category Child Category/
493 495 end
494 496  
495 497 should 'search in category hierachy' do
... ... @@ -885,6 +887,18 @@ class SearchControllerTest &lt; Test::Unit::TestCase
885 887 assert_tag :tag => "form", :attributes => { :class => 'search_form', :action => '/search' }
886 888 end
887 889  
  890 + should 'treat blank input for the city id' do
  891 + get :index, :city => ''
  892 +
  893 + assert_equal nil, assigns(:region)
  894 + end
  895 +
  896 + should 'treat non-numeric input for the city id' do
  897 + get :index, :city => 'bla'
  898 +
  899 + assert_equal nil, assigns(:region)
  900 + end
  901 +
888 902 ##################################################################
889 903 ##################################################################
890 904  
... ...