Commit 755f943179656f64bd53df19e6890a16cc2966f7

Authored by Rodrigo Souto
1 parent 0fb41209

Fixing search controller tests

app/controllers/public/search_controller.rb
... ... @@ -51,7 +51,7 @@ class SearchController < PublicController
51 51 [ :articles, _('Contents'), :recent_articles ]
52 52 ].each do |asset, name, filter|
53 53 @order << asset
54   - @searches[asset] = @category.send(filter, limit)
  54 + @searches[asset]= {:results => @category.send(filter, limit)}
55 55 raise "No total_entries for: #{asset}" unless @searches[asset][:results].respond_to?(:total_entries)
56 56 @names[asset] = name
57 57 end
... ... @@ -128,7 +128,7 @@ class SearchController &lt; PublicController
128 128 @tag = params[:tag]
129 129 @tag_cache_key = "tag_#{CGI.escape(@tag.to_s)}_env_#{environment.id.to_s}_page_#{params[:npage]}"
130 130 if is_cache_expired?(@tag_cache_key)
131   - @searches[@asset] = environment.articles.find_tagged_with(@tag).paginate(paginate_options)
  131 + @searches[@asset] = {:results => environment.articles.find_tagged_with(@tag).paginate(paginate_options)}
132 132 end
133 133 end
134 134  
... ... @@ -144,7 +144,6 @@ class SearchController &lt; PublicController
144 144 def load_query
145 145 @asset = (params[:asset] || params[:action]).to_sym
146 146 @order ||= [@asset]
147   - params[:display] ||= DEFAULT_DISPLAY[@asset]
148 147 @searches ||= {}
149 148  
150 149 @query = params[:query] || ''
... ... @@ -190,7 +189,7 @@ class SearchController &lt; PublicController
190 189 end
191 190  
192 191 def limit
193   - if map_search?
  192 + if map_search?(@searches)
194 193 MAP_SEARCH_LIMIT
195 194 elsif !multiple_search?
196 195 if [:people, :communities, :enterprises].include? @asset
... ... @@ -204,7 +203,7 @@ class SearchController &lt; PublicController
204 203 end
205 204  
206 205 def paginate_options(page = params[:page])
207   - page = 1 if multiple_search? || params[:display] == 'map'
  206 + page = 1 if multiple_search?(@searches) || params[:display] == 'map'
208 207 { :per_page => limit, :page => page }
209 208 end
210 209  
... ...
app/helpers/search_helper.rb
... ... @@ -14,10 +14,12 @@ module SearchHelper
14 14 :events, _('Events'),
15 15 ]
16 16  
  17 + VALID_DISPLAYS = %w[full compatct map]
  18 +
17 19 DEFAULT_DISPLAY = {
18 20 :articles => 'full',
19 21 :communities => 'compact',
20   - :enterprises => 'full',
  22 + :enterprises => 'compact',
21 23 :events => 'full',
22 24 :people => 'compact',
23 25 :products => 'full',
... ... @@ -33,12 +35,12 @@ module SearchHelper
33 35 # FIXME remove it after search_controler refactored
34 36 include EventsHelper
35 37  
36   - def multiple_search?
37   - ['index', 'category_index'].include?(params[:action]) || @searches.size > 1
  38 + def multiple_search?(searches=nil)
  39 + ['index', 'category_index'].include?(params[:action]) || (searches && searches.size > 1)
38 40 end
39 41  
40   - def map_search?
41   - !multiple_search? && params[:display] == 'map'
  42 + def map_search?(searches=nil)
  43 + !multiple_search?(searches) && params[:display] == 'map'
42 44 end
43 45  
44 46 def asset_class(asset)
... ... @@ -70,8 +72,8 @@ module SearchHelper
70 72 [:articles, :enterprises, :events, :products].include?(asset)
71 73 end
72 74  
73   - def display_results(asset = nil)
74   - if display_map?(asset) and map_search?
  75 + def display_results(searches=nil, asset=nil)
  76 + if display_map?(asset) && map_search?(searches)
75 77 partial = 'google_maps'
76 78 klass = 'map'
77 79 else
... ... @@ -82,6 +84,14 @@ module SearchHelper
82 84 content_tag('div', render(:partial => partial), :class => "map-or-list-search-results #{klass}")
83 85 end
84 86  
  87 + def display_filter(asset, display)
  88 + if VALID_DISPLAYS.include?(display) && send("display_#{display}?", asset)
  89 + display
  90 + else
  91 + DEFAULT_DISPLAY[asset]
  92 + end
  93 + end
  94 +
85 95 def city_with_state(city)
86 96 if city and city.kind_of?(City)
87 97 s = city.parent
... ...
app/views/search/_compact_profile.html.erb
1   -<% profile = item %>
2 1 <% filter_label = profile.send(@filter + '_label') %>
3 2 <% filter_label += show_date(profile.created_at) if @filter == 'more_recent' %>
4 3 <li class="search-profile-item">
... ...
app/views/search/_display_results.rhtml
... ... @@ -5,18 +5,20 @@
5 5 <div class="search-results-<%= name %> search-results-box <%= "search-results-empty" if search[:results].blank? %>">
6 6 <% if !search[:results].blank? %>
7 7  
8   - <% if multiple_search? %>
  8 + <% if multiple_search?(@searches) %>
9 9 <h3><%= @names[name] %></h3>
10 10 <% if search[:results].total_entries > SearchController::MULTIPLE_SEARCH_LIMIT %>
11 11 <%= link_to(_('see all (%d)') % search[:results].total_entries, params.merge(:action => name), :class => 'see-more' ) %>
12 12 <% end %>
13 13 <% end %>
14 14  
  15 + <% display = display_filter(name, params[:display]) %>
  16 +
15 17 <div class="search-results-innerbox search-results-type-<%= name.to_s.singularize %> <%= 'common-profile-list-block' if [:enterprises, :people, :communities].include?(name) %>">
16 18 <ul>
17 19 <% search[:results].each do |hit| %>
18   - <% partial = partial_for_class(hit.class, params[:display]) %>
19   - <% variable_name = partial.gsub("#{params[:display]}_", '').to_sym %>
  20 + <% partial = partial_for_class(hit.class, display) %>
  21 + <% variable_name = partial.gsub("#{display}_", '').to_sym %>
20 22 <%= render :partial => partial, :locals => {variable_name => hit} %>
21 23 <% end %>
22 24 </ul>
... ...
app/views/search/_full_enterprise.html.erb
1 1 <li class="search-profile-item">
2 2 <div class="search-enterprise-item">
3 3 <div class="search-enterprise-item-column-left">
4   - <%= profile_image_link profile, :portrait, 'div',
5   - @filter == 'more_recent' ? profile.send(@filter + '_label') + show_date(profile.created_at) : profile.send(@filter + '_label') %>
  4 + <%= profile_image_link enterprise, :portrait, 'div',
  5 + @filter == 'more_recent' ? enterprise.send(@filter + '_label') + show_date(enterprise.created_at) : enterprise.send(@filter + '_label') %>
6 6 </div>
7 7 <div class="search-enterprise-item-column-right">
8   - <%= link_to_homepage(profile.name, profile.identifier, :class => "search-result-title") %>
  8 + <%= link_to_homepage(enterprise.name, enterprise.identifier, :class => "search-result-title") %>
9 9 <div class="search-enterprise-description">
10   - <% if profile.description %>
11   - <% body_stripped = strip_tags(profile.description) %>
12   - <% elsif profile.home_page and profile.home_page.body %>
13   - <% body_stripped = strip_tags(profile.home_page.body) %>
  10 + <% if enterprise.description %>
  11 + <% body_stripped = strip_tags(enterprise.description) %>
  12 + <% elsif enterprise.home_page and enterprise.home_page.body %>
  13 + <% body_stripped = strip_tags(enterprise.home_page.body) %>
14 14 <% end %>
15 15 <%= excerpt(body_stripped, body_stripped.first(3), 200) if body_stripped %>
16 16 </div>
17 17 <div class="search-enterprise-region">
18 18 <span class="search-enterprise-region-label"><%= _("City") %></span>
19   - <% if profile.region %>
20   - <span class="search-enterprise-region-name"><%= city_with_state(profile.region) %></span>
  19 + <% if enterprise.region %>
  20 + <span class="search-enterprise-region-name"><%= city_with_state(enterprise.region) %></span>
21 21 <% end %>
22 22 </div>
23 23  
24 24 <div class="search-enterprise-categorization">
25   - <% profile.top_level_categorization.each do |parent, children| %>
  25 + <% enterprise.top_level_categorization.each do |parent, children| %>
26 26 <div class="search-enterprise-category-<%=parent.id%> search-enterprise-category">
27 27 <span class="search-enterprise-categorization-parent"><%= parent.name %></span>
28 28 <span class="search-enterprise-categorization-children">
... ...
app/views/search/category_index.rhtml
... ... @@ -7,7 +7,7 @@
7 7 <%= search_page_title(_('Search Results'), @category) %>
8 8 <%= render :partial => 'search_form', :locals => { :hint => '' } %>
9 9 <%= category_context(@category, params) %>
10   - <%= display_results %>
  10 + <%= display_results @searches %>
11 11  
12 12 <div id="category-childs">
13 13 <% if @category %>
... ...
app/views/search/index.rhtml
... ... @@ -7,7 +7,7 @@
7 7 <%= search_page_title(_('Search Results'), @category) %>
8 8 <%= render :partial => 'search_form', :locals => { :hint => '' } %>
9 9 <%= category_context(@category, params) %>
10   - <%= display_results(@asset) %>
  10 + <%= display_results(@searches, @asset) %>
11 11  
12 12 <div id="category-childs">
13 13 <% if @category %>
... ...
app/views/search/search_page.html.erb
... ... @@ -3,7 +3,7 @@
3 3 <%= render :partial => 'search_form', :locals => { :hint => _("Type words about the %s you're looking for") % @asset.to_s.singularize } %>
4 4 <%= render :partial => 'results_header' %>
5 5  
6   -<%= display_results(@asset) %>
  6 +<%= display_results(@searches, @asset) %>
7 7 <% if params[:display] != 'map' %>
8 8 <%= pagination_links @searches[@asset][:results] %>
9 9 <% end %>
... ...
app/views/search/tag.rhtml
... ... @@ -7,7 +7,7 @@
7 7 <% end %>
8 8  
9 9 <% cache_timeout(@tag_cache_key, 4.hour) do %>
10   - <%= display_results %>
  10 + <%= display_results @searches %>
11 11  
12 12 <div style="clear: both"></div>
13 13 <% end %>
... ...
lib/set_profile_region_from_city_state.rb
... ... @@ -27,14 +27,14 @@ module SetProfileRegionFromCityState
27 27 if @change_region
28 28 self.region = nil
29 29 state = search_region(State, self.state)
30   - region = search_region(City.where(:parent_id => state.id), self.city) if state
  30 + self.region = search_region(City.where(:parent_id => state.id), self.city) if state
31 31 end
32 32 end
33 33  
34 34 private
35 35  
36 36 def search_region(scope, query)
37   - return [] if !query
  37 + return nil if !query
38 38 query = query.downcase.strip
39 39 scope.where(['lower(name)=? OR lower(abbreviation)=? OR lower(acronym)=?', query, query, query]).first
40 40 end
... ...
plugins/solr/test/unit/search_helper_test.rb 0 → 100644
... ... @@ -0,0 +1,137 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class SearchHelperTest < ActiveSupport::TestCase
  4 +
  5 + include SearchHelper
  6 +
  7 + should 'display facets menu' do
  8 + expects(:asset_class).with('asset')
  9 + expects(:render).with(:partial => 'facets_menu')
  10 + facets_menu 'asset', nil
  11 + end
  12 +
  13 + should 'display facets_unselect menu' do
  14 + expects(:asset_class).with('asset')
  15 + expects(:render).with(:partial => 'facets_unselect_menu')
  16 + facets_unselect_menu 'asset'
  17 + end
  18 +
  19 + should 'display facets javascript' do
  20 + expects(:text_field_tag).returns('<text_field_tag_return>')
  21 + expects(:javascript_tag).with(regexp_matches(/id.*[\'array_item\'].*json_message/m)).returns(
  22 + '<javascript_tag_return>')
  23 + stubs(:jquery_token_input_messages_json).returns('json_message')
  24 + assert_equal '<text_field_tag_return><javascript_tag_return>',
  25 + facet_javascript('id', '', ['array_item'])
  26 + end
  27 +
  28 + should 'display empty array in facets javascript if array is nil' do
  29 + expects(:text_field_tag).returns('<text_field_tag_return>')
  30 + expects(:javascript_tag).with(regexp_matches(/id.*\[\].*json_message/m)).returns(
  31 + '<javascript_tag_return>')
  32 + stubs(:jquery_token_input_messages_json).returns('json_message')
  33 + assert_equal '<text_field_tag_return><javascript_tag_return>',
  34 + facet_javascript('id', '', [])
  35 + end
  36 +
  37 + should 'return html code for facet link' do
  38 + facet = {
  39 + :solr_field => 'facet_solr_field',
  40 + :label_id => 'facet_label_id'
  41 + }
  42 + params = {}
  43 + value = 'facet_value'
  44 + label = 'facet_label'
  45 + count = 1
  46 +
  47 + expected_url = {:facet => {'facet_solr_field' => { 'facet_label_id' => ['facet_value']}}}
  48 +
  49 + expects(:link_to).with('facet_label', expected_url, anything).returns('<link_to_result>')
  50 + stubs(:content_tag).with(anything, '', anything).returns('<content_tag_extra>')
  51 + stubs(:content_tag).with(anything, ' (1)', anything).returns('<content_tag_count>')
  52 + stubs(:content_tag).with(anything, '<link_to_result><content_tag_extra><content_tag_count>', anything).returns('<content_tag_final_result>')
  53 +
  54 + assert_equal '<content_tag_final_result>',
  55 + facet_link_html(facet, params, value, label, count)
  56 + end
  57 +
  58 + should 'return html code for facet link with extra label' do
  59 + facet = {
  60 + :solr_field => 'facet_solr_field',
  61 + :label_id => 'facet_label_id'
  62 + }
  63 + params = {}
  64 + value = 'facet_value'
  65 + label = ['facet_label', 'facet_extra']
  66 + count = 1
  67 +
  68 + expected_url = {:facet => {'facet_solr_field' => { 'facet_label_id' => ['facet_value']}}}
  69 +
  70 + expects(:link_to).with('facet_label', expected_url, anything).returns('<link_to_result>')
  71 + stubs(:content_tag).with(anything, 'facet_extra', anything).returns('<content_tag_extra>')
  72 + stubs(:content_tag).with(anything, ' (1)', anything).returns('<content_tag_count>')
  73 + stubs(:content_tag).with(anything, '<link_to_result><content_tag_extra><content_tag_count>', anything).returns('<content_tag_final_result>')
  74 +
  75 + assert_equal '<content_tag_final_result>',
  76 + facet_link_html(facet, params, value, label, count)
  77 + end
  78 +
  79 + should 'return html code for selected facet link' do
  80 + facet = {
  81 + :solr_field => 'facet_solr_field'
  82 + }
  83 + params = {:facet => {'facet_solr_field' => 'facet_value'}}
  84 + value = 'facet_value'
  85 + label = 'facet_label'
  86 + count = 1
  87 +
  88 + expected_url = {:facet => {'facet_solr_field' => 'facet_value'}}
  89 +
  90 + expects(:link_to).with('facet_label', expected_url, anything).returns('<link_to_result>')
  91 + stubs(:content_tag).with(anything, '', anything).returns('<content_tag_extra>')
  92 + stubs(:content_tag).with(anything, ' (1)', anything).returns('<content_tag_count>')
  93 + stubs(:content_tag).with(anything, '<link_to_result><content_tag_extra><content_tag_count>', {:class => 'facet-menu-item facet-result-link-selected'}).returns('<content_tag_final_result>')
  94 +
  95 + assert_equal '<content_tag_final_result>',
  96 + facet_link_html(facet, params, value, label, count)
  97 + end
  98 +
  99 + should 'show html for non-hash selected facets' do
  100 + klass = mock
  101 + klass.stubs(:facet_by_id).with(:facet_id).returns('klass_facet_by_id')
  102 + klass.stubs(:facet_label).with('klass_facet_by_id').returns('klass_facet_label')
  103 + klass.stubs(:facet_result_name).with('klass_facet_by_id', 'facet_value').returns('klass_facet_result_name')
  104 + params = {:facet => {:facet_id => 'facet_value'}}
  105 +
  106 + expects(:content_tag).with(anything, 'klass_facet_label', anything).returns('<content_tag_label>')
  107 + expects(:content_tag).with(anything, 'klass_facet_result_name', anything).returns('<content_tag_name>')
  108 + expects(:link_to).with(anything, {:facet => {}}, anything).returns('<link_to_url>')
  109 + expects(:content_tag).with(anything, '<content_tag_label><content_tag_name><link_to_url>', anything).returns('<final_content>')
  110 +
  111 + environment = mock
  112 + assert_match '<final_content>', facet_selecteds_html_for(environment, klass, params)
  113 + end
  114 +
  115 + should 'show select tag for order_by' do
  116 + [:products, :events, :articles, :enterprises, :people, :communities].each do |asset|
  117 + params = {:order_by => 'Relevance'}
  118 +
  119 + stubs(:params).returns(params)
  120 + stubs(:logged_in?).returns(false)
  121 + stubs(:options_for_select).with(instance_of(Array), params[:order_by]).returns('<options_for_select>')
  122 + stubs(:select_tag).with(regexp_matches(/#{asset}/), '<options_for_select>', anything).returns('<select_tag>')
  123 + expects(:content_tag).with(anything, regexp_matches(/<select_tag>/), anything).returns('<final_content>')
  124 +
  125 + assert_equal '<final_content>', order_by(asset)
  126 + end
  127 + end
  128 +
  129 + should 'show total of assets found' do
  130 + [:products, :events, :articles, :enterprises, :people, :communities].each do |asset|
  131 + expects(:content_tag).with(anything, regexp_matches(/10.*#{asset}.*found/), anything).returns('<final_content>')
  132 + assert_equal '<final_content>', label_total_found(asset, 10)
  133 + end
  134 + end
  135 +
  136 +end
  137 +
... ...
plugins/solr/test/unit/textile_article_test.rb 0 → 100644
... ... @@ -0,0 +1,10 @@
  1 +require 'test_helper'
  2 +
  3 +class TextileArticleTest < ActiveSupport::TestCase
  4 +
  5 + should 'define type facet' do
  6 + a = TextileArticle.new
  7 + assert_equal TextArticle.type_name, TextileArticle.send(:f_type_proc, a.send(:f_type))
  8 + end
  9 +
  10 +end
... ...
plugins/solr/test/unit/tiny_mce_article_test.rb
... ... @@ -15,4 +15,9 @@ class TinyMceArticleTest &lt; ActiveSupport::TestCase
15 15 assert_includes TinyMceArticle.find_by_contents('article')[:results], tma
16 16 assert_includes Article.find_by_contents('article')[:results], tma
17 17 end
  18 +
  19 + should 'define type facet' do
  20 + a = TinyMceArticle.new
  21 + assert_equal TextArticle.type_name, TinyMceArticle.send(:f_type_proc, a.send(:f_type))
  22 + end
18 23 end
... ...
test/factories.rb
... ... @@ -21,9 +21,6 @@ module Noosfero::Factory
21 21 obj.add_category(category)
22 22 end
23 23 end
24   - if options[:search]
25   - obj.solr_save
26   - end
27 24 obj
28 25 end
29 26  
... ...
test/functional/enterprise_registration_controller_test.rb
... ... @@ -41,7 +41,7 @@ class EnterpriseRegistrationControllerTest &lt; ActionController::TestCase
41 41 env = Environment.default
42 42 env.organization_approval_method = :admin
43 43 env.save
44   - region = fast_create(Region, {}, :search => true)
  44 + region = fast_create(Region, {})
45 45  
46 46 data = { :name => 'My new enterprise', :identifier => 'mynew', :region => region }
47 47 create_enterprise = CreateEnterprise.new(data)
... ... @@ -54,7 +54,7 @@ class EnterpriseRegistrationControllerTest &lt; ActionController::TestCase
54 54 env = Environment.default
55 55 env.organization_approval_method = :none
56 56 env.save
57   - region = fast_create(Region, {}, :search => true)
  57 + region = fast_create(Region, {})
58 58  
59 59 data = { :name => 'My new enterprise', :identifier => 'mynew', :region => region }
60 60 create_enterprise = CreateEnterprise.new(data)
... ...
test/functional/profile_search_controller_test.rb
... ... @@ -6,8 +6,6 @@ class ProfileSearchController; def rescue_action(e) raise e end; end
6 6  
7 7 class ProfileSearchControllerTest < ActionController::TestCase
8 8 def setup
9   - super
10   - TestSolr.enable
11 9 @controller = ProfileSearchController.new
12 10 @request = ActionController::TestRequest.new
13 11 @response = ActionController::TestResponse.new
... ... @@ -30,7 +28,7 @@ class ProfileSearchControllerTest &lt; ActionController::TestCase
30 28 should 'search for articles' do
31 29 article = TextileArticle.create(:name => 'My article', :body => 'Article to test profile search', :profile => person)
32 30  
33   - get 'index', :profile => person.identifier, :q => 'article profile'
  31 + get 'index', :profile => person.identifier, :q => 'article to test'
34 32 assert_includes assigns(:results), article
35 33 end
36 34  
... ... @@ -61,7 +59,7 @@ class ProfileSearchControllerTest &lt; ActionController::TestCase
61 59  
62 60 get 'index', :profile => person.identifier, :q => 'Article'
63 61  
64   - assert_equal 10, assigns('results').docs.size
  62 + assert_equal 10, assigns('results').size
65 63 assert_tag :tag => 'a', :attributes => { :href => "/profile/#{person.identifier}/search?page=2&amp;q=Article", :rel => 'next' }
66 64 end
67 65  
... ... @@ -69,7 +67,7 @@ class ProfileSearchControllerTest &lt; ActionController::TestCase
69 67 article1 = TextileArticle.create(:name => 'Article 1', :abstract => 'Abstract to test', :body => 'Article to test profile search', :profile => person)
70 68 article2 = TextileArticle.create(:name => 'Article 2', :body => 'Another article to test profile search', :profile => person)
71 69  
72   - get 'index', :profile => person.identifier, :q => 'article profile'
  70 + get 'index', :profile => person.identifier, :q => 'article to test'
73 71  
74 72 assert_tag :tag => 'li', :descendant => { :tag => 'a', :content => article1.abstract, :attributes => { :class => /article-details/ }}
75 73 assert_no_tag :tag => 'li', :descendant => { :tag => 'a', :content => article1.body, :attributes => { :class => /article-details/ }}
... ... @@ -90,7 +88,7 @@ class ProfileSearchControllerTest &lt; ActionController::TestCase
90 88 article1 = TextileArticle.create(:name => 'Article 1', :body => 'Article to test profile search', :profile => person, :published => false)
91 89 article2 = TextileArticle.create(:name => 'Article 2', :body => 'Another article to test profile search', :profile => person)
92 90  
93   - get 'index', :profile => person.identifier, :q => 'article profile'
  91 + get 'index', :profile => person.identifier, :q => 'article to test'
94 92  
95 93 assert_no_tag :tag => 'li', :descendant => { :tag => 'a', :content => article1.body, :attributes => { :class => /article-details/ }}
96 94  
... ... @@ -101,7 +99,7 @@ class ProfileSearchControllerTest &lt; ActionController::TestCase
101 99 article1 = TextileArticle.create(:name => 'Article 1', :body => 'Article to test profile search', :body => 'Article to test profile search', :profile => person)
102 100 article2 = TextileArticle.create(:name => 'Article 2', :body => 'Another article to test profile search', :profile => person)
103 101  
104   - get 'index', :profile => person.identifier, :q => 'article profile'
  102 + get 'index', :profile => person.identifier, :q => 'article to test'
105 103  
106 104 assert_tag :tag => 'div', :attributes => { :class => 'results-found-message' }, :content => /2 results found/
107 105 end
... ...
test/functional/search_controller_test.rb
... ... @@ -7,8 +7,6 @@ class SearchController; def rescue_action(e) raise e end; end
7 7 class SearchControllerTest < ActionController::TestCase
8 8  
9 9 def setup
10   - super
11   - TestSolr.enable
12 10 @controller = SearchController.new
13 11 @request = ActionController::TestRequest.new
14 12 @request.stubs(:ssl?).returns(false)
... ... @@ -60,7 +58,7 @@ class SearchControllerTest &lt; ActionController::TestCase
60 58  
61 59 should 'search only in specified types of content' do
62 60 get :articles, :query => 'something not important'
63   - assert_equal [:articles], assigns(:results).keys
  61 + assert_equal [:articles], assigns(:searches).keys
64 62 end
65 63  
66 64 should 'render success in search' do
... ... @@ -72,8 +70,8 @@ class SearchControllerTest &lt; ActionController::TestCase
72 70 person = fast_create(Person)
73 71 art = create_article_with_optional_category('an article to be found', person)
74 72  
75   - get 'articles', :query => 'article found'
76   - assert_includes assigns(:results)[:articles], art
  73 + get 'articles', :query => 'article to be found'
  74 + assert_includes assigns(:searches)[:articles][:results], art
77 75 end
78 76  
79 77 # should 'get facets with articles search results' do
... ... @@ -86,11 +84,11 @@ class SearchControllerTest &lt; ActionController::TestCase
86 84 # art.save!
87 85 #
88 86 # get 'articles', :query => 'article found'
89   -# assert !assigns(:results)[:articles].facets.blank?
90   -# assert assigns(:results)[:articles].facets['facet_fields']['f_type_facet'][0][0] == 'Article'
91   -# assert assigns(:results)[:articles].facets['facet_fields']['f_profile_type_facet'][0][0] == 'Person'
92   -# assert assigns(:results)[:articles].facets['facet_fields']['f_category_facet'][0][0] == 'cat1'
93   -# assert assigns(:results)[:articles].facets['facet_fields']['f_category_facet'][1][0] == 'cat2'
  87 +# assert !assigns(:searches)[:articles].facets.blank?
  88 +# assert assigns(:searches)[:articles].facets['facet_fields']['f_type_facet'][0][0] == 'Article'
  89 +# assert assigns(:searches)[:articles].facets['facet_fields']['f_profile_type_facet'][0][0] == 'Person'
  90 +# assert assigns(:searches)[:articles].facets['facet_fields']['f_category_facet'][0][0] == 'cat1'
  91 +# assert assigns(:searches)[:articles].facets['facet_fields']['f_category_facet'][1][0] == 'cat2'
94 92 # end
95 93  
96 94 should 'redirect contents to articles' do
... ... @@ -99,7 +97,7 @@ class SearchControllerTest &lt; ActionController::TestCase
99 97  
100 98 get 'contents', :query => 'article found'
101 99 # full description to avoid deprecation warning
102   - assert_redirected_to :controller => :search, :action => :articles, :query => 'article found', :display => 'list'
  100 + assert_redirected_to :controller => :search, :action => :articles, :query => 'article found'
103 101 end
104 102  
105 103 # 'assets' outside any category
... ... @@ -111,30 +109,30 @@ class SearchControllerTest &lt; ActionController::TestCase
111 109  
112 110 get :articles
113 111  
114   - assert_includes assigns(:results)[:articles], art1
115   - assert_includes assigns(:results)[:articles], art2
  112 + assert_includes assigns(:searches)[:articles][:results], art1
  113 + assert_includes assigns(:searches)[:articles][:results], art2
116 114 end
117 115  
118   -# should 'find enterprises' do
119   -# ent = create_profile_with_optional_category(Enterprise, 'teste')
120   -# get :enterprises, :query => 'teste'
121   -# assert_includes assigns(:results)[:enterprises], ent
122   -# assert !assigns(:results)[:enterprises].facets.nil?
123   -# end
  116 + should 'find enterprises' do
  117 + ent = create_profile_with_optional_category(Enterprise, 'teste')
  118 + get :enterprises, :query => 'teste'
  119 + assert_includes assigns(:searches)[:enterprises][:results], ent
  120 +# assert !assigns(:searches)[:enterprises].facets.nil?
  121 + end
124 122  
125 123 should 'list enterprises in general' do
126 124 ent1 = create_profile_with_optional_category(Enterprise, 'teste 1')
127 125 ent2 = create_profile_with_optional_category(Enterprise, 'teste 2')
128 126  
129 127 get :enterprises
130   - assert_includes assigns(:results)[:enterprises], ent1
131   - assert_includes assigns(:results)[:enterprises], ent2
  128 + assert_includes assigns(:searches)[:enterprises][:results], ent1
  129 + assert_includes assigns(:searches)[:enterprises][:results], ent2
132 130 end
133 131  
134 132 should 'search for people' do
135 133 p1 = create_user('people_1').person; p1.name = 'a beautiful person'; p1.save!
136 134 get :people, :query => 'beautiful'
137   - assert_includes assigns(:results)[:people], p1
  135 + assert_includes assigns(:searches)[:people][:results], p1
138 136 end
139 137  
140 138 # should 'get facets with people search results' do
... ... @@ -148,10 +146,10 @@ class SearchControllerTest &lt; ActionController::TestCase
148 146 #
149 147 # get 'people', :query => 'Hildebrando'
150 148 #
151   -# assert !assigns(:results)[:people].facets.blank?
152   -# assert assigns(:results)[:people].facets['facet_fields']['f_region_facet'][0][0] == city.id.to_s
  149 +# assert !assigns(:searches)[:people].facets.blank?
  150 +# assert assigns(:searches)[:people].facets['facet_fields']['f_region_facet'][0][0] == city.id.to_s
153 151 #
154   -# categories_facet = assigns(:results)[:people].facets['facet_fields']['f_categories_facet']
  152 +# categories_facet = assigns(:searches)[:people].facets['facet_fields']['f_categories_facet']
155 153 # assert_equal 2, categories_facet.count
156 154 # assert_equivalent [cat1.id.to_s, cat2.id.to_s], [categories_facet[0][0], categories_facet[1][0]]
157 155 # end
... ... @@ -165,15 +163,15 @@ class SearchControllerTest &lt; ActionController::TestCase
165 163  
166 164 get :people
167 165  
168   - assert_equivalent [p2,p1], assigns(:results)[:people]
  166 + assert_equivalent [p2,p1], assigns(:searches)[:people][:results]
169 167 end
170 168  
171   -# should 'find communities' do
172   -# c1 = create_profile_with_optional_category(Community, 'a beautiful community')
173   -# get :communities, :query => 'beautiful'
174   -# assert_includes assigns(:results)[:communities], c1
175   -# assert !assigns(:results)[:communities].facets.nil?
176   -# end
  169 + should 'find communities' do
  170 + c1 = create_profile_with_optional_category(Community, 'a beautiful community')
  171 + get :communities, :query => 'beautiful'
  172 + assert_includes assigns(:searches)[:communities][:results], c1
  173 +# assert !assigns(:searches)[:communities].facets.nil?
  174 + end
177 175  
178 176 # 'assets' menu outside any category
179 177 should 'list communities in general' do
... ... @@ -181,14 +179,14 @@ class SearchControllerTest &lt; ActionController::TestCase
181 179 c2 = create_profile_with_optional_category(Community, 'another beautiful community')
182 180  
183 181 get :communities
184   - assert_equivalent [c2, c1], assigns(:results)[:communities]
  182 + assert_equivalent [c2, c1], assigns(:searches)[:communities][:results]
185 183 end
186 184  
187 185 should 'search for products' do
188 186 ent = create_profile_with_optional_category(Enterprise, 'teste')
189 187 prod = ent.products.create!(:name => 'a beautiful product', :product_category => @product_category)
190 188 get :products, :query => 'beautiful'
191   - assert_includes assigns(:results)[:products], prod
  189 + assert_includes assigns(:searches)[:products][:results], prod
192 190 end
193 191  
194 192 # should 'get facets with products search results' do
... ... @@ -203,11 +201,11 @@ class SearchControllerTest &lt; ActionController::TestCase
203 201 # prod.save!
204 202 #
205 203 # get 'products', :query => 'Sound'
206   -# assert !assigns(:results)[:products].facets.blank?
207   -# assert assigns(:results)[:products].facets['facet_fields']['f_category_facet'][0][0] == @product_category.name
208   -# assert assigns(:results)[:products].facets['facet_fields']['f_region_facet'][0][0] == city.id.to_s
209   -# assert assigns(:results)[:products].facets['facet_fields']['f_qualifier_facet'][0][0] == "#{qualifier1.id} 0"
210   -# assert assigns(:results)[:products].facets['facet_fields']['f_qualifier_facet'][1][0] == "#{qualifier2.id} 0"
  204 +# assert !assigns(:searches)[:products].facets.blank?
  205 +# assert assigns(:searches)[:products].facets['facet_fields']['f_category_facet'][0][0] == @product_category.name
  206 +# assert assigns(:searches)[:products].facets['facet_fields']['f_region_facet'][0][0] == city.id.to_s
  207 +# assert assigns(:searches)[:products].facets['facet_fields']['f_qualifier_facet'][0][0] == "#{qualifier1.id} 0"
  208 +# assert assigns(:searches)[:products].facets['facet_fields']['f_qualifier_facet'][1][0] == "#{qualifier2.id} 0"
211 209 # end
212 210  
213 211 # 'assets' menu outside any category
... ... @@ -221,7 +219,7 @@ class SearchControllerTest &lt; ActionController::TestCase
221 219 # prod2 = ent2.products.create!(:name => 'another beautiful product', :product_category => @product_category)
222 220 #
223 221 # get :products
224   -# assert_equivalent [prod2, prod1], assigns(:results)[:products].docs
  222 +# assert_equivalent [prod2, prod1], assigns(:searches)[:products].docs
225 223 # assert_match 'Highlights', @response.body
226 224 # end
227 225  
... ... @@ -284,7 +282,7 @@ class SearchControllerTest &lt; ActionController::TestCase
284 282  
285 283 get :enterprises, :page => '2'
286 284  
287   - assert_equal 1, assigns(:results)[:enterprises].size
  285 + assert_equal 1, assigns(:searches)[:enterprises][:results].size
288 286 end
289 287  
290 288 should 'display a given category' do
... ... @@ -326,7 +324,7 @@ class SearchControllerTest &lt; ActionController::TestCase
326 324  
327 325 get :category_index, :category_path => ['parent-category'], :query => 'test_profile'
328 326  
329   - assert_includes assigns(:results)[:people], p
  327 + assert_includes assigns(:searches)[:people][:results], p
330 328 end
331 329  
332 330 # should 'find enterprise by product category' do
... ... @@ -338,10 +336,10 @@ class SearchControllerTest &lt; ActionController::TestCase
338 336 #
339 337 # get :index, :query => prod_cat.name
340 338 #
341   -# assert_includes assigns('results')[:enterprises], ent1
342   -# assert_not_includes assigns('results')[:enterprises], ent2
  339 +# assert_includes assigns(:searches)[:enterprises][:results], ent1
  340 +# assert_not_includes assigns(:searches)[:enterprises][:results], ent2
343 341 # end
344   -#
  342 +
345 343 # should 'show only results in general search' do
346 344 # ent1 = create_profile_with_optional_category(Enterprise, 'test1')
347 345 # prod_cat = ProductCategory.create!(:name => 'pctest', :environment => Environment.default)
... ... @@ -352,8 +350,8 @@ class SearchControllerTest &lt; ActionController::TestCase
352 350 # get :index, :query => prod_cat.name
353 351 #
354 352 # assert assigns(:facets).blank?
355   -# assert_nil assigns(:results)[:enterprises].facets
356   -# assert_nil assigns(:results)[:products].facets
  353 +# assert_nil assigns(:searches)[:enterprises].facets
  354 +# assert_nil assigns(:searches)[:products].facets
357 355 # end
358 356  
359 357 should 'render specific action when only one asset is enabled' do
... ... @@ -370,23 +368,23 @@ class SearchControllerTest &lt; ActionController::TestCase
370 368 get :index, :query => 'something'
371 369 end
372 370  
373   -# should 'search all enabled assets in general search' do
374   -# ent1 = create_profile_with_optional_category(Enterprise, 'test enterprise')
375   -# prod_cat = ProductCategory.create!(:name => 'pctest', :environment => Environment.default)
376   -# prod = ent1.products.create!(:name => 'test product', :product_category => prod_cat)
377   -# art = Article.create!(:name => 'test article', :profile_id => fast_create(Person).id)
378   -# per = Person.create!(:name => 'test person', :identifier => 'test-person', :user_id => fast_create(User).id)
379   -# com = Community.create!(:name => 'test community')
380   -# eve = Event.create!(:name => 'test event', :profile_id => fast_create(Person).id)
381   -#
382   -# get :index, :query => 'test'
383   -#
384   -# [:articles, :enterprises, :people, :communities, :products, :events].select do |key, name|
385   -# !@controller.environment.enabled?('disable_asset_' + key.to_s)
386   -# end.each do |asset|
387   -# assert !assigns(:results)[asset].docs.empty?
388   -# end
389   -# end
  371 + should 'search all enabled assets in general search' do
  372 + ent1 = create_profile_with_optional_category(Enterprise, 'test enterprise')
  373 + prod_cat = ProductCategory.create!(:name => 'pctest', :environment => Environment.default)
  374 + prod = ent1.products.create!(:name => 'test product', :product_category => prod_cat)
  375 + art = Article.create!(:name => 'test article', :profile_id => fast_create(Person).id)
  376 + per = Person.create!(:name => 'test person', :identifier => 'test-person', :user_id => fast_create(User).id)
  377 + com = Community.create!(:name => 'test community')
  378 + eve = Event.create!(:name => 'test event', :profile_id => fast_create(Person).id)
  379 +
  380 + get :index, :query => 'test'
  381 +
  382 + [:articles, :enterprises, :people, :communities, :products, :events].select do |key, name|
  383 + !@controller.environment.enabled?('disable_asset_' + key.to_s)
  384 + end.each do |asset|
  385 + assert !assigns(:searches)[asset][:results].empty?
  386 + end
  387 + end
390 388  
391 389 should 'display category image while in directory' do
392 390 parent = Category.create!(:name => 'category1', :environment => Environment.default)
... ... @@ -399,15 +397,15 @@ class SearchControllerTest &lt; ActionController::TestCase
399 397 assert_tag :tag => 'img', :attributes => { :src => /rails_thumb\.png/ }
400 398 end
401 399  
402   -# should 'search for events' do
403   -# person = create_user('teste').person
404   -# ev = create_event(person, :name => 'an event to be found')
405   -#
406   -# get :events, :query => 'event found'
407   -#
408   -# assert_includes assigns(:results)[:events], ev
409   -# assert !assigns(:results)[:events].facets.nil?
410   -# end
  400 + should 'search for events' do
  401 + person = create_user('teste').person
  402 + event = create_event(person, :name => 'an event to be found')
  403 +
  404 + get :events, :query => 'event to be found'
  405 +
  406 + assert_includes assigns(:searches)[:events][:results], event
  407 +# assert !assigns(:searches)[:events].facets.nil?
  408 + end
411 409  
412 410 should 'return events of the day' do
413 411 person = create_user('someone').person
... ... @@ -452,8 +450,8 @@ class SearchControllerTest &lt; ActionController::TestCase
452 450  
453 451 get :events
454 452  
455   - assert_not_includes assigns(:results)[:events], ev1
456   - assert_includes assigns(:results)[:events], ev2
  453 + assert_not_includes assigns(:searches)[:events][:results], ev1
  454 + assert_includes assigns(:searches)[:events][:results], ev2
457 455 end
458 456  
459 457 should 'list events for a given month' do
... ... @@ -464,7 +462,7 @@ class SearchControllerTest &lt; ActionController::TestCase
464 462  
465 463 get :events, :year => '2008', :month => '1'
466 464  
467   - assert_equal [ 'upcoming event 1' ], assigns(:results)[:events].map(&:name)
  465 + assert_equal [ 'upcoming event 1' ], assigns(:searches)[:events][:results].map(&:name)
468 466 end
469 467  
470 468 %w[ people enterprises articles events communities products ].each do |asset|
... ... @@ -482,7 +480,7 @@ class SearchControllerTest &lt; ActionController::TestCase
482 480  
483 481 get :products, :product_category => prod_cat.id
484 482  
485   - assert_includes assigns(:results)[:products], p
  483 + assert_includes assigns(:searches)[:products][:results], p
486 484 end
487 485  
488 486 # Testing random sequences always have a small chance of failing
... ... @@ -494,16 +492,16 @@ class SearchControllerTest &lt; ActionController::TestCase
494 492 # end
495 493 #
496 494 # get :products
497   -# result1 = assigns(:results)[:products].docs.map(&:id)
  495 +# result1 = assigns(:searches)[:products][:results].map(&:id)
498 496 #
499 497 # (1..10).each do |n|
500 498 # get :products
501 499 # end
502   -# result2 = assigns(:results)[:products].docs.map(&:id)
  500 +# result2 = assigns(:searches)[:products][:results].map(&:id)
503 501 #
504 502 # assert_not_equal result1, result2
505 503 # end
506   -#
  504 +
507 505 # should 'remove far products by geolocalization empty logged search' do
508 506 # user = create_user('a_logged_user')
509 507 # # trigger geosearch
... ... @@ -523,7 +521,7 @@ class SearchControllerTest &lt; ActionController::TestCase
523 521 # prod4 = Product.create!(:name => 'produto 4', :enterprise_id => ent4.id, :product_category_id => cat.id)
524 522 #
525 523 # get :products
526   -# assert_equivalent [prod1, prod3, prod2], assigns(:results)[:products].docs
  524 +# assert_equivalent [prod1, prod3, prod2], assigns(:searches)[:products].docs
527 525 # end
528 526  
529 527 should 'display properly in conjuntion with a category' do
... ... @@ -536,7 +534,7 @@ class SearchControllerTest &lt; ActionController::TestCase
536 534  
537 535 get :products, :category_path => cat.path.split('/'), :product_category => prod_cat1.id
538 536  
539   - assert_includes assigns(:results)[:products], product
  537 + assert_includes assigns(:searches)[:products][:results], product
540 538 end
541 539  
542 540 should 'provide calendar for events' do
... ... @@ -555,9 +553,9 @@ class SearchControllerTest &lt; ActionController::TestCase
555 553 person = create_user('teste').person
556 554 art = TextileArticle.create!(:name => 'an text_article article to be found', :profile => person)
557 555  
558   - get 'articles', :query => 'article found'
  556 + get 'articles', :query => 'article to be found'
559 557  
560   - assert_includes assigns(:results)[:articles], art
  558 + assert_includes assigns(:searches)[:articles][:results], art
561 559 end
562 560  
563 561 should 'show link to article asset in the see all foot link of the articles block in the category page' do
... ... @@ -583,7 +581,7 @@ class SearchControllerTest &lt; ActionController::TestCase
583 581  
584 582 get :index, :query => 'test'
585 583  
586   - assert_equal 20, assigns(:results)[:enterprises].total_entries
  584 + assert_equal 20, assigns(:searches)[:enterprises][:results].total_entries
587 585 end
588 586  
589 587 should 'find products when enterprises has own hostname' do
... ... @@ -591,7 +589,7 @@ class SearchControllerTest &lt; ActionController::TestCase
591 589 ent.domains << Domain.new(:name => 'testent.com'); ent.save!
592 590 prod = ent.products.create!(:name => 'a beautiful product', :product_category => @product_category)
593 591 get 'products', :query => 'beautiful'
594   - assert_includes assigns(:results)[:products], prod
  592 + assert_includes assigns(:searches)[:products][:results], prod
595 593 end
596 594  
597 595 should 'add script tag for google maps if searching products' do
... ... @@ -657,7 +655,7 @@ class SearchControllerTest &lt; ActionController::TestCase
657 655  
658 656 get :people
659 657 assert_equal SearchController::BLOCKS_SEARCH_LIMIT+3, Person.count
660   - assert_equal SearchController::BLOCKS_SEARCH_LIMIT, assigns(:results)[:people].count
  658 + assert_equal SearchController::BLOCKS_SEARCH_LIMIT, assigns(:searches)[:people][:results].count
661 659 assert_tag :a, '', :attributes => {:class => 'next_page'}
662 660 end
663 661  
... ... @@ -667,7 +665,7 @@ class SearchControllerTest &lt; ActionController::TestCase
667 665 c3 = create(Community, :name => 'Testing community 3')
668 666  
669 667 get :communities
670   - assert_equal [c3,c2,c1] , assigns(:results)[:communities]
  668 + assert_equal [c3,c2,c1] , assigns(:searches)[:communities][:results]
671 669 end
672 670  
673 671 should "paginate search of communities in groups of #{SearchController::BLOCKS_SEARCH_LIMIT}" do
... ... @@ -677,7 +675,7 @@ class SearchControllerTest &lt; ActionController::TestCase
677 675  
678 676 get :communities
679 677 assert_equal SearchController::BLOCKS_SEARCH_LIMIT+3, Community.count
680   - assert_equal SearchController::BLOCKS_SEARCH_LIMIT, assigns(:results)[:communities].count
  678 + assert_equal SearchController::BLOCKS_SEARCH_LIMIT, assigns(:searches)[:communities][:results].count
681 679 assert_tag :a, '', :attributes => {:class => 'next_page'}
682 680 end
683 681  
... ... @@ -691,21 +689,21 @@ class SearchControllerTest &lt; ActionController::TestCase
691 689 fast_create(ActionTracker::Record, :target_id => c2, :user_type => 'Profile', :user_id => person, :created_at => Time.now)
692 690 fast_create(ActionTracker::Record, :target_id => c2, :user_type => 'Profile', :user_id => person, :created_at => Time.now)
693 691 get :communities, :filter => 'more_active'
694   - assert_equal [c2,c1,c3] , assigns(:results)[:communities]
  692 + assert_equal [c2,c1,c3] , assigns(:searches)[:communities][:results]
695 693 end
696 694  
697 695 should "only include visible people in more_recent filter" do
698 696 # assuming that all filters behave the same!
699 697 p1 = fast_create(Person, :visible => false)
700 698 get :people, :filter => 'more_recent'
701   - assert_not_includes assigns(:results), p1
  699 + assert_not_includes assigns(:searches)[:people][:results], p1
702 700 end
703 701  
704 702 should "only include visible communities in more_recent filter" do
705 703 # assuming that all filters behave the same!
706 704 p1 = fast_create(Community, :visible => false)
707 705 get :communities, :filter => 'more_recent'
708   - assert_not_includes assigns(:results), p1
  706 + assert_not_includes assigns(:searches)[:communities][:results], p1
709 707 end
710 708  
711 709 # should 'browse facets when query is not empty' do
... ... @@ -729,17 +727,17 @@ class SearchControllerTest &lt; ActionController::TestCase
729 727  
730 728 should 'keep old urls working' do
731 729 get :assets, :asset => 'articles'
732   - assert_redirected_to :controller => :search, :action => :articles, :display => 'list'
  730 + assert_redirected_to :controller => :search, :action => :articles
733 731 get :assets, :asset => 'people'
734   - assert_redirected_to :controller => :search, :action => :people, :display => 'list'
  732 + assert_redirected_to :controller => :search, :action => :people
735 733 get :assets, :asset => 'communities'
736   - assert_redirected_to :controller => :search, :action => :communities, :display => 'list'
  734 + assert_redirected_to :controller => :search, :action => :communities
737 735 get :assets, :asset => 'products'
738   - assert_redirected_to :controller => :search, :action => :products, :display => 'list'
  736 + assert_redirected_to :controller => :search, :action => :products
739 737 get :assets, :asset => 'enterprises'
740   - assert_redirected_to :controller => :search, :action => :enterprises, :display => 'list'
  738 + assert_redirected_to :controller => :search, :action => :enterprises
741 739 get :assets, :asset => 'events'
742   - assert_redirected_to :controller => :search, :action => :events, :display => 'list'
  740 + assert_redirected_to :controller => :search, :action => :events
743 741 end
744 742  
745 743 should 'show tag cloud' do
... ... @@ -765,25 +763,25 @@ class SearchControllerTest &lt; ActionController::TestCase
765 763  
766 764 get :tag, :tag => 'two'
767 765  
768   - assert_equal [a, a2], assigns(:results)[:tag]
  766 + assert_equal [a, a2], assigns(:searches)[:tag][:results]
769 767  
770 768 get :tag, :tag => 'one'
771 769  
772   - assert_equal [a], assigns(:results)[:tag]
  770 + assert_equal [a], assigns(:searches)[:tag][:results]
  771 + end
  772 +
  773 + should 'not show assets from other environments' do
  774 + other_env = Environment.create!(:name => 'Another environment')
  775 + p1 = Person.create!(:name => 'Hildebrando', :identifier => 'hild', :user_id => fast_create(User).id, :environment_id => other_env.id)
  776 + p2 = Person.create!(:name => 'Adamastor', :identifier => 'adam', :user_id => fast_create(User).id)
  777 + art1 = Article.create!(:name => 'my article', :profile_id => p1.id)
  778 + art2 = Article.create!(:name => 'my article', :profile_id => p2.id)
  779 +
  780 + get :articles, :query => 'my article'
  781 +
  782 + assert_equal [art2], assigns(:searches)[:articles][:results]
773 783 end
774 784  
775   -# should 'not show assets from other environments' do
776   -# other_env = Environment.create!(:name => 'Another environment')
777   -# p1 = Person.create!(:name => 'Hildebrando', :identifier => 'hild', :user_id => fast_create(User).id, :environment_id => other_env.id)
778   -# p2 = Person.create!(:name => 'Adamastor', :identifier => 'adam', :user_id => fast_create(User).id)
779   -# art1 = Article.create!(:name => 'my article', :profile_id => p1.id)
780   -# art2 = Article.create!(:name => 'my article', :profile_id => p2.id)
781   -#
782   -# get :articles, :query => 'my article'
783   -#
784   -# assert_equal [art2], assigns(:results)[:articles].docs
785   -# end
786   -#
787 785 # should 'order product results by more recent when requested' do
788 786 # ent = fast_create(Enterprise)
789 787 # prod1 = Product.create!(:name => 'product 1', :enterprise_id => ent.id, :product_category_id => @product_category.id)
... ... @@ -799,7 +797,7 @@ class SearchControllerTest &lt; ActionController::TestCase
799 797 #
800 798 # get :products, :query => 'product', :order_by => :more_recent
801 799 #
802   -# assert_equal [prod2, prod1, prod3], assigns(:results)[:products].docs
  800 +# assert_equal [prod2, prod1, prod3], assigns(:searches)[:products].docs
803 801 # end
804 802 #
805 803 # should 'only list products from enabled enterprises' do
... ... @@ -810,7 +808,8 @@ class SearchControllerTest &lt; ActionController::TestCase
810 808 #
811 809 # get :products, :query => 'product'
812 810 #
813   -# assert_equal [prod1], assigns(:results)[:products].docs
  811 +# assert_includes assigns(:searches)[:products][:results], prod1
  812 +# assert_not_includes assigns(:searches)[:products][:results], prod2
814 813 # end
815 814 #
816 815 # should 'order product results by name when requested' do
... ... @@ -825,7 +824,7 @@ class SearchControllerTest &lt; ActionController::TestCase
825 824 #
826 825 # get :products, :query => 'product', :order_by => :name
827 826 #
828   -# assert_equal [prod3, prod2, prod1], assigns(:results)[:products].docs
  827 +# assert_equal [prod3, prod2, prod1], assigns(:searches)[:products].docs
829 828 # end
830 829 #
831 830 # should 'order product results by closest when requested' do
... ... @@ -845,7 +844,7 @@ class SearchControllerTest &lt; ActionController::TestCase
845 844 # prod3 = Product.create!(:name => 'product 3', :enterprise_id => ent3.id, :product_category_id => cat.id)
846 845 #
847 846 # get :products, :query => 'product', :order_by => :closest
848   -# assert_equal [prod2, prod1, prod3], assigns(:results)[:products].docs
  847 +# assert_equal [prod2, prod1, prod3], assigns(:searches)[:products].docs
849 848 # end
850 849 #
851 850 #
... ... @@ -856,7 +855,7 @@ class SearchControllerTest &lt; ActionController::TestCase
856 855 #
857 856 # get :events, :query => 'party', :order_by => :name
858 857 #
859   -# assert_equal [ev2, ev1], assigns(:results)[:events].docs
  858 +# assert_equal [ev2, ev1], assigns(:searches)[:events].docs
860 859 # end
861 860 #
862 861 # should 'order articles by name when requested' do
... ... @@ -866,7 +865,7 @@ class SearchControllerTest &lt; ActionController::TestCase
866 865 #
867 866 # get :articles, :query => 'review', :order_by => :name
868 867 #
869   -# assert_equal [art2, art3, art1], assigns(:results)[:articles].docs
  868 +# assert_equal [art2, art3, art1], assigns(:searches)[:articles].docs
870 869 # end
871 870  
872 871 should 'order articles by more recent' do
... ... @@ -877,7 +876,7 @@ class SearchControllerTest &lt; ActionController::TestCase
877 876  
878 877 get :articles, :filter => :more_recent
879 878  
880   - assert_equal [art2, art1, art3], assigns(:results)[:articles]
  879 + assert_equal [art2, art1, art3], assigns(:searches)[:articles][:results]
881 880 end
882 881  
883 882 # should 'order enterprise results by name when requested' do
... ... @@ -887,7 +886,7 @@ class SearchControllerTest &lt; ActionController::TestCase
887 886 #
888 887 # get :enterprises, :query => 'Company', :order_by => :name
889 888 #
890   -# assert_equal [ent2, ent1, ent3], assigns(:results)[:enterprises].docs
  889 +# assert_equal [ent2, ent1, ent3], assigns(:searches)[:enterprises].docs
891 890 # end
892 891 #
893 892 # should 'order people results by name when requested' do
... ... @@ -897,7 +896,7 @@ class SearchControllerTest &lt; ActionController::TestCase
897 896 #
898 897 # get :people, :query => 'Silva', :order_by => :name
899 898 #
900   -# assert_equal [person3, person1, person2], assigns(:results)[:people].docs
  899 +# assert_equal [person3, person1, person2], assigns(:searches)[:people].docs
901 900 # end
902 901 #
903 902 # should 'order community results by name when requested' do
... ... @@ -907,7 +906,7 @@ class SearchControllerTest &lt; ActionController::TestCase
907 906 #
908 907 # get :communities, :query => 'Group', :order_by => :name
909 908 #
910   -# assert_equal [com3, com2, com1], assigns(:results)[:communities].docs
  909 +# assert_equal [com3, com2, com1], assigns(:searches)[:communities].docs
911 910 # end
912 911 #
913 912 # should 'raise error when requested to order by unknown filter' do
... ...
test/integration/assigning_validator_organizations_to_regions_test.rb
... ... @@ -3,7 +3,6 @@ require &quot;#{File.dirname(__FILE__)}/../test_helper&quot;
3 3 class AssigningValidatorOrganizationsToRegionsTest < ActionController::IntegrationTest
4 4  
5 5 should 'be able to properly assign organizations as validators to regions' do
6   - TestSolr.enable
7 6 env = Environment.default
8 7  
9 8 Organization.destroy_all
... ...
test/unit/search_helper_test.rb
... ... @@ -35,7 +35,7 @@ class SearchHelperTest &lt; ActiveSupport::TestCase
35 35 title = 'page_title'
36 36 category = mock
37 37 category.stubs(:name).returns('category_name')
38   - assert_equal '<h1>page_title<small>category_name</small></h1>',
  38 + assert_equal '<h1>page_title - <small>category_name</small></h1>',
39 39 search_page_title(title, category)
40 40 end
41 41  
... ... @@ -58,22 +58,10 @@ class SearchHelperTest &lt; ActiveSupport::TestCase
58 58 should 'display results with map' do
59 59 stubs(:params).returns({:display => 'map'})
60 60 @query = 'test'
61   - @results = {:products => [1,2]}
  61 + @searches = {:products => {:results => [1,2]}}
62 62 expects('render').with({:partial => 'google_maps'}).returns('render_return')
63 63 expects('content_tag').with('div', 'render_return', :class => 'map-or-list-search-results map')
64   - display_results true
65   - end
66   -
67   - should 'show display_list button when in map view' do
68   - stubs(:params).returns({:display => 'map'})
69   - expects(:button).with(:search, 'Display in list', {:display => 'list'}, anything)
70   - display_map_list_button
71   - end
72   -
73   - should 'show display_map button when in list view' do
74   - stubs(:params).returns({:display => ''})
75   - expects(:button).with(:search, 'Display in map', {:display => 'map'}, anything)
76   - display_map_list_button
  64 + display_results(@searches, :products)
77 65 end
78 66  
79 67 should 'return full city name with state' do
... ... @@ -125,135 +113,6 @@ class SearchHelperTest &lt; ActiveSupport::TestCase
125 113 city.stubs(:name).returns('Feliz Deserto')
126 114 assert_equal 'Feliz Deserto', city_with_state(city)
127 115 end
128   -
129   - should 'display facets menu' do
130   - expects(:asset_class).with('asset')
131   - expects(:render).with(:partial => 'facets_menu')
132   - facets_menu 'asset', nil
133   - end
134   -
135   - should 'display facets_unselect menu' do
136   - expects(:asset_class).with('asset')
137   - expects(:render).with(:partial => 'facets_unselect_menu')
138   - facets_unselect_menu 'asset'
139   - end
140   -
141   - should 'display facets javascript' do
142   - expects(:text_field_tag).returns('<text_field_tag_return>')
143   - expects(:javascript_tag).with(regexp_matches(/id.*[\'array_item\'].*json_message/m)).returns(
144   - '<javascript_tag_return>')
145   - stubs(:jquery_token_input_messages_json).returns('json_message')
146   - assert_equal '<text_field_tag_return><javascript_tag_return>',
147   - facet_javascript('id', '', ['array_item'])
148   - end
149   -
150   - should 'display empty array in facets javascript if array is nil' do
151   - expects(:text_field_tag).returns('<text_field_tag_return>')
152   - expects(:javascript_tag).with(regexp_matches(/id.*\[\].*json_message/m)).returns(
153   - '<javascript_tag_return>')
154   - stubs(:jquery_token_input_messages_json).returns('json_message')
155   - assert_equal '<text_field_tag_return><javascript_tag_return>',
156   - facet_javascript('id', '', [])
157   - end
158   -
159   - should 'return html code for facet link' do
160   - facet = {
161   - :solr_field => 'facet_solr_field',
162   - :label_id => 'facet_label_id'
163   - }
164   - params = {}
165   - value = 'facet_value'
166   - label = 'facet_label'
167   - count = 1
168   -
169   - expected_url = {:facet => {'facet_solr_field' => { 'facet_label_id' => ['facet_value']}}}
170   -
171   - expects(:link_to).with('facet_label', expected_url, anything).returns('<link_to_result>')
172   - stubs(:content_tag).with(anything, '', anything).returns('<content_tag_extra>')
173   - stubs(:content_tag).with(anything, ' (1)', anything).returns('<content_tag_count>')
174   - stubs(:content_tag).with(anything, '<link_to_result><content_tag_extra><content_tag_count>', anything).returns('<content_tag_final_result>')
175   -
176   - assert_equal '<content_tag_final_result>',
177   - facet_link_html(facet, params, value, label, count)
178   - end
179   -
180   - should 'return html code for facet link with extra label' do
181   - facet = {
182   - :solr_field => 'facet_solr_field',
183   - :label_id => 'facet_label_id'
184   - }
185   - params = {}
186   - value = 'facet_value'
187   - label = ['facet_label', 'facet_extra']
188   - count = 1
189   -
190   - expected_url = {:facet => {'facet_solr_field' => { 'facet_label_id' => ['facet_value']}}}
191   -
192   - expects(:link_to).with('facet_label', expected_url, anything).returns('<link_to_result>')
193   - stubs(:content_tag).with(anything, 'facet_extra', anything).returns('<content_tag_extra>')
194   - stubs(:content_tag).with(anything, ' (1)', anything).returns('<content_tag_count>')
195   - stubs(:content_tag).with(anything, '<link_to_result><content_tag_extra><content_tag_count>', anything).returns('<content_tag_final_result>')
196   -
197   - assert_equal '<content_tag_final_result>',
198   - facet_link_html(facet, params, value, label, count)
199   - end
200   -
201   - should 'return html code for selected facet link' do
202   - facet = {
203   - :solr_field => 'facet_solr_field'
204   - }
205   - params = {:facet => {'facet_solr_field' => 'facet_value'}}
206   - value = 'facet_value'
207   - label = 'facet_label'
208   - count = 1
209   -
210   - expected_url = {:facet => {'facet_solr_field' => 'facet_value'}}
211   -
212   - expects(:link_to).with('facet_label', expected_url, anything).returns('<link_to_result>')
213   - stubs(:content_tag).with(anything, '', anything).returns('<content_tag_extra>')
214   - stubs(:content_tag).with(anything, ' (1)', anything).returns('<content_tag_count>')
215   - stubs(:content_tag).with(anything, '<link_to_result><content_tag_extra><content_tag_count>', {:class => 'facet-menu-item facet-result-link-selected'}).returns('<content_tag_final_result>')
216   -
217   - assert_equal '<content_tag_final_result>',
218   - facet_link_html(facet, params, value, label, count)
219   - end
220   -
221   - should 'show html for non-hash selected facets' do
222   - klass = mock
223   - klass.stubs(:facet_by_id).with(:facet_id).returns('klass_facet_by_id')
224   - klass.stubs(:facet_label).with('klass_facet_by_id').returns('klass_facet_label')
225   - klass.stubs(:facet_result_name).with('klass_facet_by_id', 'facet_value').returns('klass_facet_result_name')
226   - params = {:facet => {:facet_id => 'facet_value'}}
227   -
228   - expects(:content_tag).with(anything, 'klass_facet_label', anything).returns('<content_tag_label>')
229   - expects(:content_tag).with(anything, 'klass_facet_result_name', anything).returns('<content_tag_name>')
230   - expects(:link_to).with(anything, {:facet => {}}, anything).returns('<link_to_url>')
231   - expects(:content_tag).with(anything, '<content_tag_label><content_tag_name><link_to_url>', anything).returns('<final_content>')
232   -
233   - environment = mock
234   - assert_match '<final_content>', facet_selecteds_html_for(environment, klass, params)
235   - end
236   -
237   - should 'show select tag for order_by' do
238   - [:products, :events, :articles, :enterprises, :people, :communities].each do |asset|
239   - params = {:order_by => 'Relevance'}
240   -
241   - stubs(:params).returns(params)
242   - stubs(:logged_in?).returns(false)
243   - stubs(:options_for_select).with(instance_of(Array), params[:order_by]).returns('<options_for_select>')
244   - stubs(:select_tag).with(regexp_matches(/#{asset}/), '<options_for_select>', anything).returns('<select_tag>')
245   - expects(:content_tag).with(anything, regexp_matches(/<select_tag>/), anything).returns('<final_content>')
246   -
247   - assert_equal '<final_content>', order_by(asset)
248   - end
249   - end
250   -
251   - should 'show total of assets found' do
252   - [:products, :events, :articles, :enterprises, :people, :communities].each do |asset|
253   - expects(:content_tag).with(anything, regexp_matches(/10.*#{asset}.*found/), anything).returns('<final_content>')
254   - assert_equal '<final_content>', label_total_found(asset, 10)
255   - end
256   - end
257 116  
258 117 should 'return asset class from string' do
259 118 asset_names = ['products', 'events', 'articles', 'enterprises', 'people', 'communities']
... ... @@ -263,12 +122,4 @@ class SearchHelperTest &lt; ActiveSupport::TestCase
263 122 end
264 123 end
265 124  
266   - should 'return asset table from string' do
267   - asset_classes = [Product, Event, Article, Enterprise, Person, Community]
268   - asset_tables = ['products', 'articles', 'articles', 'profiles', 'profiles', 'profiles']
269   - asset_classes.each_index do |i|
270   - assert_equal asset_tables[i], asset_table(asset_classes[i])
271   - end
272   - end
273   -
274 125 end
... ...
test/unit/set_profile_region_from_city_state_test.rb
... ... @@ -2,11 +2,6 @@ require File.dirname(__FILE__) + &#39;/../test_helper&#39;
2 2  
3 3 class SetProfileRegionFromCityStateTest < ActiveSupport::TestCase
4 4  
5   - def setup
6   - super
7   - TestSolr.enable
8   - end
9   -
10 5 should 'set city and state from names' do
11 6 s = State.create!(:name => 'Sao Paulo', :acronym => 'SP', :environment_id => Environment.default.id)
12 7 c = City.create!(:name => 'Pindamonhangaba', :parent_id => s.id, :environment_id => Environment.default.id)
... ...
test/unit/textile_article_test.rb
... ... @@ -182,9 +182,4 @@ class TextileArticleTest &lt; ActiveSupport::TestCase
182 182 article
183 183 end
184 184  
185   - should 'define type facet' do
186   - a = TextileArticle.new
187   - assert_equal TextArticle.type_name, TextileArticle.send(:f_type_proc, a.send(:f_type))
188   - end
189   -
190 185 end
... ...
test/unit/tiny_mce_article_test.rb
... ... @@ -224,9 +224,4 @@ end
224 224 assert TinyMceArticle.new.tiny_mce?
225 225 end
226 226  
227   - should 'define type facet' do
228   - a = TinyMceArticle.new
229   - assert_equal TextArticle.type_name, TinyMceArticle.send(:f_type_proc, a.send(:f_type))
230   - end
231   -
232 227 end
... ...