diff --git a/app/controllers/public/search_controller.rb b/app/controllers/public/search_controller.rb
index 7a9790b..b6431e2 100644
--- a/app/controllers/public/search_controller.rb
+++ b/app/controllers/public/search_controller.rb
@@ -51,7 +51,7 @@ class SearchController < PublicController
[ :articles, _('Contents'), :recent_articles ]
].each do |asset, name, filter|
@order << asset
- @searches[asset] = @category.send(filter, limit)
+ @searches[asset]= {:results => @category.send(filter, limit)}
raise "No total_entries for: #{asset}" unless @searches[asset][:results].respond_to?(:total_entries)
@names[asset] = name
end
@@ -128,7 +128,7 @@ class SearchController < PublicController
@tag = params[:tag]
@tag_cache_key = "tag_#{CGI.escape(@tag.to_s)}_env_#{environment.id.to_s}_page_#{params[:npage]}"
if is_cache_expired?(@tag_cache_key)
- @searches[@asset] = environment.articles.find_tagged_with(@tag).paginate(paginate_options)
+ @searches[@asset] = {:results => environment.articles.find_tagged_with(@tag).paginate(paginate_options)}
end
end
@@ -144,7 +144,6 @@ class SearchController < PublicController
def load_query
@asset = (params[:asset] || params[:action]).to_sym
@order ||= [@asset]
- params[:display] ||= DEFAULT_DISPLAY[@asset]
@searches ||= {}
@query = params[:query] || ''
@@ -190,7 +189,7 @@ class SearchController < PublicController
end
def limit
- if map_search?
+ if map_search?(@searches)
MAP_SEARCH_LIMIT
elsif !multiple_search?
if [:people, :communities, :enterprises].include? @asset
@@ -204,7 +203,7 @@ class SearchController < PublicController
end
def paginate_options(page = params[:page])
- page = 1 if multiple_search? || params[:display] == 'map'
+ page = 1 if multiple_search?(@searches) || params[:display] == 'map'
{ :per_page => limit, :page => page }
end
diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb
index 3512a31..3425ad8 100644
--- a/app/helpers/search_helper.rb
+++ b/app/helpers/search_helper.rb
@@ -14,10 +14,12 @@ module SearchHelper
:events, _('Events'),
]
+ VALID_DISPLAYS = %w[full compatct map]
+
DEFAULT_DISPLAY = {
:articles => 'full',
:communities => 'compact',
- :enterprises => 'full',
+ :enterprises => 'compact',
:events => 'full',
:people => 'compact',
:products => 'full',
@@ -33,12 +35,12 @@ module SearchHelper
# FIXME remove it after search_controler refactored
include EventsHelper
- def multiple_search?
- ['index', 'category_index'].include?(params[:action]) || @searches.size > 1
+ def multiple_search?(searches=nil)
+ ['index', 'category_index'].include?(params[:action]) || (searches && searches.size > 1)
end
- def map_search?
- !multiple_search? && params[:display] == 'map'
+ def map_search?(searches=nil)
+ !multiple_search?(searches) && params[:display] == 'map'
end
def asset_class(asset)
@@ -70,8 +72,8 @@ module SearchHelper
[:articles, :enterprises, :events, :products].include?(asset)
end
- def display_results(asset = nil)
- if display_map?(asset) and map_search?
+ def display_results(searches=nil, asset=nil)
+ if display_map?(asset) && map_search?(searches)
partial = 'google_maps'
klass = 'map'
else
@@ -82,6 +84,14 @@ module SearchHelper
content_tag('div', render(:partial => partial), :class => "map-or-list-search-results #{klass}")
end
+ def display_filter(asset, display)
+ if VALID_DISPLAYS.include?(display) && send("display_#{display}?", asset)
+ display
+ else
+ DEFAULT_DISPLAY[asset]
+ end
+ end
+
def city_with_state(city)
if city and city.kind_of?(City)
s = city.parent
diff --git a/app/views/search/_compact_profile.html.erb b/app/views/search/_compact_profile.html.erb
index 06c5f79..d0ed3eb 100644
--- a/app/views/search/_compact_profile.html.erb
+++ b/app/views/search/_compact_profile.html.erb
@@ -1,4 +1,3 @@
-<% profile = item %>
<% filter_label = profile.send(@filter + '_label') %>
<% filter_label += show_date(profile.created_at) if @filter == 'more_recent' %>
diff --git a/app/views/search/_display_results.rhtml b/app/views/search/_display_results.rhtml
index 9203d54..2d738f0 100644
--- a/app/views/search/_display_results.rhtml
+++ b/app/views/search/_display_results.rhtml
@@ -5,18 +5,20 @@
">
<% if !search[:results].blank? %>
- <% if multiple_search? %>
+ <% if multiple_search?(@searches) %>
<%= @names[name] %>
<% if search[:results].total_entries > SearchController::MULTIPLE_SEARCH_LIMIT %>
<%= link_to(_('see all (%d)') % search[:results].total_entries, params.merge(:action => name), :class => 'see-more' ) %>
<% end %>
<% end %>
+ <% display = display_filter(name, params[:display]) %>
+
<% search[:results].each do |hit| %>
- <% partial = partial_for_class(hit.class, params[:display]) %>
- <% variable_name = partial.gsub("#{params[:display]}_", '').to_sym %>
+ <% partial = partial_for_class(hit.class, display) %>
+ <% variable_name = partial.gsub("#{display}_", '').to_sym %>
<%= render :partial => partial, :locals => {variable_name => hit} %>
<% end %>
diff --git a/app/views/search/_full_enterprise.html.erb b/app/views/search/_full_enterprise.html.erb
index 278a5c5..4e1ef23 100644
--- a/app/views/search/_full_enterprise.html.erb
+++ b/app/views/search/_full_enterprise.html.erb
@@ -1,28 +1,28 @@
- <%= profile_image_link profile, :portrait, 'div',
- @filter == 'more_recent' ? profile.send(@filter + '_label') + show_date(profile.created_at) : profile.send(@filter + '_label') %>
+ <%= profile_image_link enterprise, :portrait, 'div',
+ @filter == 'more_recent' ? enterprise.send(@filter + '_label') + show_date(enterprise.created_at) : enterprise.send(@filter + '_label') %>
- <%= link_to_homepage(profile.name, profile.identifier, :class => "search-result-title") %>
+ <%= link_to_homepage(enterprise.name, enterprise.identifier, :class => "search-result-title") %>
- <% if profile.description %>
- <% body_stripped = strip_tags(profile.description) %>
- <% elsif profile.home_page and profile.home_page.body %>
- <% body_stripped = strip_tags(profile.home_page.body) %>
+ <% if enterprise.description %>
+ <% body_stripped = strip_tags(enterprise.description) %>
+ <% elsif enterprise.home_page and enterprise.home_page.body %>
+ <% body_stripped = strip_tags(enterprise.home_page.body) %>
<% end %>
<%= excerpt(body_stripped, body_stripped.first(3), 200) if body_stripped %>
<%= _("City") %>
- <% if profile.region %>
- <%= city_with_state(profile.region) %>
+ <% if enterprise.region %>
+ <%= city_with_state(enterprise.region) %>
<% end %>
- <% profile.top_level_categorization.each do |parent, children| %>
+ <% enterprise.top_level_categorization.each do |parent, children| %>
<%= parent.name %>
diff --git a/app/views/search/category_index.rhtml b/app/views/search/category_index.rhtml
index 7b2ee19..843e0f7 100644
--- a/app/views/search/category_index.rhtml
+++ b/app/views/search/category_index.rhtml
@@ -7,7 +7,7 @@
<%= search_page_title(_('Search Results'), @category) %>
<%= render :partial => 'search_form', :locals => { :hint => '' } %>
<%= category_context(@category, params) %>
- <%= display_results %>
+ <%= display_results @searches %>
<% if @category %>
diff --git a/app/views/search/index.rhtml b/app/views/search/index.rhtml
index ec950d0..339df08 100644
--- a/app/views/search/index.rhtml
+++ b/app/views/search/index.rhtml
@@ -7,7 +7,7 @@
<%= search_page_title(_('Search Results'), @category) %>
<%= render :partial => 'search_form', :locals => { :hint => '' } %>
<%= category_context(@category, params) %>
- <%= display_results(@asset) %>
+ <%= display_results(@searches, @asset) %>
<% if @category %>
diff --git a/app/views/search/search_page.html.erb b/app/views/search/search_page.html.erb
index 252e05a..2222e51 100644
--- a/app/views/search/search_page.html.erb
+++ b/app/views/search/search_page.html.erb
@@ -3,7 +3,7 @@
<%= render :partial => 'search_form', :locals => { :hint => _("Type words about the %s you're looking for") % @asset.to_s.singularize } %>
<%= render :partial => 'results_header' %>
-<%= display_results(@asset) %>
+<%= display_results(@searches, @asset) %>
<% if params[:display] != 'map' %>
<%= pagination_links @searches[@asset][:results] %>
<% end %>
diff --git a/app/views/search/tag.rhtml b/app/views/search/tag.rhtml
index 2540146..337a6e3 100644
--- a/app/views/search/tag.rhtml
+++ b/app/views/search/tag.rhtml
@@ -7,7 +7,7 @@
<% end %>
<% cache_timeout(@tag_cache_key, 4.hour) do %>
- <%= display_results %>
+ <%= display_results @searches %>
<% end %>
diff --git a/lib/set_profile_region_from_city_state.rb b/lib/set_profile_region_from_city_state.rb
index 808fb5c..586f56b 100644
--- a/lib/set_profile_region_from_city_state.rb
+++ b/lib/set_profile_region_from_city_state.rb
@@ -27,14 +27,14 @@ module SetProfileRegionFromCityState
if @change_region
self.region = nil
state = search_region(State, self.state)
- region = search_region(City.where(:parent_id => state.id), self.city) if state
+ self.region = search_region(City.where(:parent_id => state.id), self.city) if state
end
end
private
def search_region(scope, query)
- return [] if !query
+ return nil if !query
query = query.downcase.strip
scope.where(['lower(name)=? OR lower(abbreviation)=? OR lower(acronym)=?', query, query, query]).first
end
diff --git a/plugins/solr/test/unit/search_helper_test.rb b/plugins/solr/test/unit/search_helper_test.rb
new file mode 100644
index 0000000..77b796e
--- /dev/null
+++ b/plugins/solr/test/unit/search_helper_test.rb
@@ -0,0 +1,137 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class SearchHelperTest < ActiveSupport::TestCase
+
+ include SearchHelper
+
+ should 'display facets menu' do
+ expects(:asset_class).with('asset')
+ expects(:render).with(:partial => 'facets_menu')
+ facets_menu 'asset', nil
+ end
+
+ should 'display facets_unselect menu' do
+ expects(:asset_class).with('asset')
+ expects(:render).with(:partial => 'facets_unselect_menu')
+ facets_unselect_menu 'asset'
+ end
+
+ should 'display facets javascript' do
+ expects(:text_field_tag).returns('
')
+ expects(:javascript_tag).with(regexp_matches(/id.*[\'array_item\'].*json_message/m)).returns(
+ '')
+ stubs(:jquery_token_input_messages_json).returns('json_message')
+ assert_equal '',
+ facet_javascript('id', '', ['array_item'])
+ end
+
+ should 'display empty array in facets javascript if array is nil' do
+ expects(:text_field_tag).returns('')
+ expects(:javascript_tag).with(regexp_matches(/id.*\[\].*json_message/m)).returns(
+ '')
+ stubs(:jquery_token_input_messages_json).returns('json_message')
+ assert_equal '',
+ facet_javascript('id', '', [])
+ end
+
+ should 'return html code for facet link' do
+ facet = {
+ :solr_field => 'facet_solr_field',
+ :label_id => 'facet_label_id'
+ }
+ params = {}
+ value = 'facet_value'
+ label = 'facet_label'
+ count = 1
+
+ expected_url = {:facet => {'facet_solr_field' => { 'facet_label_id' => ['facet_value']}}}
+
+ expects(:link_to).with('facet_label', expected_url, anything).returns('')
+ stubs(:content_tag).with(anything, '', anything).returns('')
+ stubs(:content_tag).with(anything, ' (1)', anything).returns('')
+ stubs(:content_tag).with(anything, '', anything).returns('')
+
+ assert_equal '',
+ facet_link_html(facet, params, value, label, count)
+ end
+
+ should 'return html code for facet link with extra label' do
+ facet = {
+ :solr_field => 'facet_solr_field',
+ :label_id => 'facet_label_id'
+ }
+ params = {}
+ value = 'facet_value'
+ label = ['facet_label', 'facet_extra']
+ count = 1
+
+ expected_url = {:facet => {'facet_solr_field' => { 'facet_label_id' => ['facet_value']}}}
+
+ expects(:link_to).with('facet_label', expected_url, anything).returns('')
+ stubs(:content_tag).with(anything, 'facet_extra', anything).returns('')
+ stubs(:content_tag).with(anything, ' (1)', anything).returns('')
+ stubs(:content_tag).with(anything, '', anything).returns('')
+
+ assert_equal '',
+ facet_link_html(facet, params, value, label, count)
+ end
+
+ should 'return html code for selected facet link' do
+ facet = {
+ :solr_field => 'facet_solr_field'
+ }
+ params = {:facet => {'facet_solr_field' => 'facet_value'}}
+ value = 'facet_value'
+ label = 'facet_label'
+ count = 1
+
+ expected_url = {:facet => {'facet_solr_field' => 'facet_value'}}
+
+ expects(:link_to).with('facet_label', expected_url, anything).returns('')
+ stubs(:content_tag).with(anything, '', anything).returns('')
+ stubs(:content_tag).with(anything, ' (1)', anything).returns('')
+ stubs(:content_tag).with(anything, '', {:class => 'facet-menu-item facet-result-link-selected'}).returns('')
+
+ assert_equal '',
+ facet_link_html(facet, params, value, label, count)
+ end
+
+ should 'show html for non-hash selected facets' do
+ klass = mock
+ klass.stubs(:facet_by_id).with(:facet_id).returns('klass_facet_by_id')
+ klass.stubs(:facet_label).with('klass_facet_by_id').returns('klass_facet_label')
+ klass.stubs(:facet_result_name).with('klass_facet_by_id', 'facet_value').returns('klass_facet_result_name')
+ params = {:facet => {:facet_id => 'facet_value'}}
+
+ expects(:content_tag).with(anything, 'klass_facet_label', anything).returns('')
+ expects(:content_tag).with(anything, 'klass_facet_result_name', anything).returns('')
+ expects(:link_to).with(anything, {:facet => {}}, anything).returns('')
+ expects(:content_tag).with(anything, '', anything).returns('')
+
+ environment = mock
+ assert_match '', facet_selecteds_html_for(environment, klass, params)
+ end
+
+ should 'show select tag for order_by' do
+ [:products, :events, :articles, :enterprises, :people, :communities].each do |asset|
+ params = {:order_by => 'Relevance'}
+
+ stubs(:params).returns(params)
+ stubs(:logged_in?).returns(false)
+ stubs(:options_for_select).with(instance_of(Array), params[:order_by]).returns('')
+ stubs(:select_tag).with(regexp_matches(/#{asset}/), '', anything).returns('')
+ expects(:content_tag).with(anything, regexp_matches(//), anything).returns('')
+
+ assert_equal '', order_by(asset)
+ end
+ end
+
+ should 'show total of assets found' do
+ [:products, :events, :articles, :enterprises, :people, :communities].each do |asset|
+ expects(:content_tag).with(anything, regexp_matches(/10.*#{asset}.*found/), anything).returns('')
+ assert_equal '', label_total_found(asset, 10)
+ end
+ end
+
+end
+
diff --git a/plugins/solr/test/unit/textile_article_test.rb b/plugins/solr/test/unit/textile_article_test.rb
new file mode 100644
index 0000000..332205f
--- /dev/null
+++ b/plugins/solr/test/unit/textile_article_test.rb
@@ -0,0 +1,10 @@
+require 'test_helper'
+
+class TextileArticleTest < ActiveSupport::TestCase
+
+ should 'define type facet' do
+ a = TextileArticle.new
+ assert_equal TextArticle.type_name, TextileArticle.send(:f_type_proc, a.send(:f_type))
+ end
+
+end
diff --git a/plugins/solr/test/unit/tiny_mce_article_test.rb b/plugins/solr/test/unit/tiny_mce_article_test.rb
index b2d720b..13d4b1d 100644
--- a/plugins/solr/test/unit/tiny_mce_article_test.rb
+++ b/plugins/solr/test/unit/tiny_mce_article_test.rb
@@ -15,4 +15,9 @@ class TinyMceArticleTest < ActiveSupport::TestCase
assert_includes TinyMceArticle.find_by_contents('article')[:results], tma
assert_includes Article.find_by_contents('article')[:results], tma
end
+
+ should 'define type facet' do
+ a = TinyMceArticle.new
+ assert_equal TextArticle.type_name, TinyMceArticle.send(:f_type_proc, a.send(:f_type))
+ end
end
diff --git a/test/factories.rb b/test/factories.rb
index 7b97fc2..ecaa9aa 100644
--- a/test/factories.rb
+++ b/test/factories.rb
@@ -21,9 +21,6 @@ module Noosfero::Factory
obj.add_category(category)
end
end
- if options[:search]
- obj.solr_save
- end
obj
end
diff --git a/test/functional/enterprise_registration_controller_test.rb b/test/functional/enterprise_registration_controller_test.rb
index 478b8c6..c9780b8 100644
--- a/test/functional/enterprise_registration_controller_test.rb
+++ b/test/functional/enterprise_registration_controller_test.rb
@@ -41,7 +41,7 @@ class EnterpriseRegistrationControllerTest < ActionController::TestCase
env = Environment.default
env.organization_approval_method = :admin
env.save
- region = fast_create(Region, {}, :search => true)
+ region = fast_create(Region, {})
data = { :name => 'My new enterprise', :identifier => 'mynew', :region => region }
create_enterprise = CreateEnterprise.new(data)
@@ -54,7 +54,7 @@ class EnterpriseRegistrationControllerTest < ActionController::TestCase
env = Environment.default
env.organization_approval_method = :none
env.save
- region = fast_create(Region, {}, :search => true)
+ region = fast_create(Region, {})
data = { :name => 'My new enterprise', :identifier => 'mynew', :region => region }
create_enterprise = CreateEnterprise.new(data)
diff --git a/test/functional/profile_search_controller_test.rb b/test/functional/profile_search_controller_test.rb
index fce3b8a..5ad31d1 100644
--- a/test/functional/profile_search_controller_test.rb
+++ b/test/functional/profile_search_controller_test.rb
@@ -6,8 +6,6 @@ class ProfileSearchController; def rescue_action(e) raise e end; end
class ProfileSearchControllerTest < ActionController::TestCase
def setup
- super
- TestSolr.enable
@controller = ProfileSearchController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
@@ -30,7 +28,7 @@ class ProfileSearchControllerTest < ActionController::TestCase
should 'search for articles' do
article = TextileArticle.create(:name => 'My article', :body => 'Article to test profile search', :profile => person)
- get 'index', :profile => person.identifier, :q => 'article profile'
+ get 'index', :profile => person.identifier, :q => 'article to test'
assert_includes assigns(:results), article
end
@@ -61,7 +59,7 @@ class ProfileSearchControllerTest < ActionController::TestCase
get 'index', :profile => person.identifier, :q => 'Article'
- assert_equal 10, assigns('results').docs.size
+ assert_equal 10, assigns('results').size
assert_tag :tag => 'a', :attributes => { :href => "/profile/#{person.identifier}/search?page=2&q=Article", :rel => 'next' }
end
@@ -69,7 +67,7 @@ class ProfileSearchControllerTest < ActionController::TestCase
article1 = TextileArticle.create(:name => 'Article 1', :abstract => 'Abstract to test', :body => 'Article to test profile search', :profile => person)
article2 = TextileArticle.create(:name => 'Article 2', :body => 'Another article to test profile search', :profile => person)
- get 'index', :profile => person.identifier, :q => 'article profile'
+ get 'index', :profile => person.identifier, :q => 'article to test'
assert_tag :tag => 'li', :descendant => { :tag => 'a', :content => article1.abstract, :attributes => { :class => /article-details/ }}
assert_no_tag :tag => 'li', :descendant => { :tag => 'a', :content => article1.body, :attributes => { :class => /article-details/ }}
@@ -90,7 +88,7 @@ class ProfileSearchControllerTest < ActionController::TestCase
article1 = TextileArticle.create(:name => 'Article 1', :body => 'Article to test profile search', :profile => person, :published => false)
article2 = TextileArticle.create(:name => 'Article 2', :body => 'Another article to test profile search', :profile => person)
- get 'index', :profile => person.identifier, :q => 'article profile'
+ get 'index', :profile => person.identifier, :q => 'article to test'
assert_no_tag :tag => 'li', :descendant => { :tag => 'a', :content => article1.body, :attributes => { :class => /article-details/ }}
@@ -101,7 +99,7 @@ class ProfileSearchControllerTest < ActionController::TestCase
article1 = TextileArticle.create(:name => 'Article 1', :body => 'Article to test profile search', :body => 'Article to test profile search', :profile => person)
article2 = TextileArticle.create(:name => 'Article 2', :body => 'Another article to test profile search', :profile => person)
- get 'index', :profile => person.identifier, :q => 'article profile'
+ get 'index', :profile => person.identifier, :q => 'article to test'
assert_tag :tag => 'div', :attributes => { :class => 'results-found-message' }, :content => /2 results found/
end
diff --git a/test/functional/search_controller_test.rb b/test/functional/search_controller_test.rb
index 02a0088..17d6a88 100644
--- a/test/functional/search_controller_test.rb
+++ b/test/functional/search_controller_test.rb
@@ -7,8 +7,6 @@ class SearchController; def rescue_action(e) raise e end; end
class SearchControllerTest < ActionController::TestCase
def setup
- super
- TestSolr.enable
@controller = SearchController.new
@request = ActionController::TestRequest.new
@request.stubs(:ssl?).returns(false)
@@ -60,7 +58,7 @@ class SearchControllerTest < ActionController::TestCase
should 'search only in specified types of content' do
get :articles, :query => 'something not important'
- assert_equal [:articles], assigns(:results).keys
+ assert_equal [:articles], assigns(:searches).keys
end
should 'render success in search' do
@@ -72,8 +70,8 @@ class SearchControllerTest < ActionController::TestCase
person = fast_create(Person)
art = create_article_with_optional_category('an article to be found', person)
- get 'articles', :query => 'article found'
- assert_includes assigns(:results)[:articles], art
+ get 'articles', :query => 'article to be found'
+ assert_includes assigns(:searches)[:articles][:results], art
end
# should 'get facets with articles search results' do
@@ -86,11 +84,11 @@ class SearchControllerTest < ActionController::TestCase
# art.save!
#
# get 'articles', :query => 'article found'
-# assert !assigns(:results)[:articles].facets.blank?
-# assert assigns(:results)[:articles].facets['facet_fields']['f_type_facet'][0][0] == 'Article'
-# assert assigns(:results)[:articles].facets['facet_fields']['f_profile_type_facet'][0][0] == 'Person'
-# assert assigns(:results)[:articles].facets['facet_fields']['f_category_facet'][0][0] == 'cat1'
-# assert assigns(:results)[:articles].facets['facet_fields']['f_category_facet'][1][0] == 'cat2'
+# assert !assigns(:searches)[:articles].facets.blank?
+# assert assigns(:searches)[:articles].facets['facet_fields']['f_type_facet'][0][0] == 'Article'
+# assert assigns(:searches)[:articles].facets['facet_fields']['f_profile_type_facet'][0][0] == 'Person'
+# assert assigns(:searches)[:articles].facets['facet_fields']['f_category_facet'][0][0] == 'cat1'
+# assert assigns(:searches)[:articles].facets['facet_fields']['f_category_facet'][1][0] == 'cat2'
# end
should 'redirect contents to articles' do
@@ -99,7 +97,7 @@ class SearchControllerTest < ActionController::TestCase
get 'contents', :query => 'article found'
# full description to avoid deprecation warning
- assert_redirected_to :controller => :search, :action => :articles, :query => 'article found', :display => 'list'
+ assert_redirected_to :controller => :search, :action => :articles, :query => 'article found'
end
# 'assets' outside any category
@@ -111,30 +109,30 @@ class SearchControllerTest < ActionController::TestCase
get :articles
- assert_includes assigns(:results)[:articles], art1
- assert_includes assigns(:results)[:articles], art2
+ assert_includes assigns(:searches)[:articles][:results], art1
+ assert_includes assigns(:searches)[:articles][:results], art2
end
-# should 'find enterprises' do
-# ent = create_profile_with_optional_category(Enterprise, 'teste')
-# get :enterprises, :query => 'teste'
-# assert_includes assigns(:results)[:enterprises], ent
-# assert !assigns(:results)[:enterprises].facets.nil?
-# end
+ should 'find enterprises' do
+ ent = create_profile_with_optional_category(Enterprise, 'teste')
+ get :enterprises, :query => 'teste'
+ assert_includes assigns(:searches)[:enterprises][:results], ent
+# assert !assigns(:searches)[:enterprises].facets.nil?
+ end
should 'list enterprises in general' do
ent1 = create_profile_with_optional_category(Enterprise, 'teste 1')
ent2 = create_profile_with_optional_category(Enterprise, 'teste 2')
get :enterprises
- assert_includes assigns(:results)[:enterprises], ent1
- assert_includes assigns(:results)[:enterprises], ent2
+ assert_includes assigns(:searches)[:enterprises][:results], ent1
+ assert_includes assigns(:searches)[:enterprises][:results], ent2
end
should 'search for people' do
p1 = create_user('people_1').person; p1.name = 'a beautiful person'; p1.save!
get :people, :query => 'beautiful'
- assert_includes assigns(:results)[:people], p1
+ assert_includes assigns(:searches)[:people][:results], p1
end
# should 'get facets with people search results' do
@@ -148,10 +146,10 @@ class SearchControllerTest < ActionController::TestCase
#
# get 'people', :query => 'Hildebrando'
#
-# assert !assigns(:results)[:people].facets.blank?
-# assert assigns(:results)[:people].facets['facet_fields']['f_region_facet'][0][0] == city.id.to_s
+# assert !assigns(:searches)[:people].facets.blank?
+# assert assigns(:searches)[:people].facets['facet_fields']['f_region_facet'][0][0] == city.id.to_s
#
-# categories_facet = assigns(:results)[:people].facets['facet_fields']['f_categories_facet']
+# categories_facet = assigns(:searches)[:people].facets['facet_fields']['f_categories_facet']
# assert_equal 2, categories_facet.count
# assert_equivalent [cat1.id.to_s, cat2.id.to_s], [categories_facet[0][0], categories_facet[1][0]]
# end
@@ -165,15 +163,15 @@ class SearchControllerTest < ActionController::TestCase
get :people
- assert_equivalent [p2,p1], assigns(:results)[:people]
+ assert_equivalent [p2,p1], assigns(:searches)[:people][:results]
end
-# should 'find communities' do
-# c1 = create_profile_with_optional_category(Community, 'a beautiful community')
-# get :communities, :query => 'beautiful'
-# assert_includes assigns(:results)[:communities], c1
-# assert !assigns(:results)[:communities].facets.nil?
-# end
+ should 'find communities' do
+ c1 = create_profile_with_optional_category(Community, 'a beautiful community')
+ get :communities, :query => 'beautiful'
+ assert_includes assigns(:searches)[:communities][:results], c1
+# assert !assigns(:searches)[:communities].facets.nil?
+ end
# 'assets' menu outside any category
should 'list communities in general' do
@@ -181,14 +179,14 @@ class SearchControllerTest < ActionController::TestCase
c2 = create_profile_with_optional_category(Community, 'another beautiful community')
get :communities
- assert_equivalent [c2, c1], assigns(:results)[:communities]
+ assert_equivalent [c2, c1], assigns(:searches)[:communities][:results]
end
should 'search for products' do
ent = create_profile_with_optional_category(Enterprise, 'teste')
prod = ent.products.create!(:name => 'a beautiful product', :product_category => @product_category)
get :products, :query => 'beautiful'
- assert_includes assigns(:results)[:products], prod
+ assert_includes assigns(:searches)[:products][:results], prod
end
# should 'get facets with products search results' do
@@ -203,11 +201,11 @@ class SearchControllerTest < ActionController::TestCase
# prod.save!
#
# get 'products', :query => 'Sound'
-# assert !assigns(:results)[:products].facets.blank?
-# assert assigns(:results)[:products].facets['facet_fields']['f_category_facet'][0][0] == @product_category.name
-# assert assigns(:results)[:products].facets['facet_fields']['f_region_facet'][0][0] == city.id.to_s
-# assert assigns(:results)[:products].facets['facet_fields']['f_qualifier_facet'][0][0] == "#{qualifier1.id} 0"
-# assert assigns(:results)[:products].facets['facet_fields']['f_qualifier_facet'][1][0] == "#{qualifier2.id} 0"
+# assert !assigns(:searches)[:products].facets.blank?
+# assert assigns(:searches)[:products].facets['facet_fields']['f_category_facet'][0][0] == @product_category.name
+# assert assigns(:searches)[:products].facets['facet_fields']['f_region_facet'][0][0] == city.id.to_s
+# assert assigns(:searches)[:products].facets['facet_fields']['f_qualifier_facet'][0][0] == "#{qualifier1.id} 0"
+# assert assigns(:searches)[:products].facets['facet_fields']['f_qualifier_facet'][1][0] == "#{qualifier2.id} 0"
# end
# 'assets' menu outside any category
@@ -221,7 +219,7 @@ class SearchControllerTest < ActionController::TestCase
# prod2 = ent2.products.create!(:name => 'another beautiful product', :product_category => @product_category)
#
# get :products
-# assert_equivalent [prod2, prod1], assigns(:results)[:products].docs
+# assert_equivalent [prod2, prod1], assigns(:searches)[:products].docs
# assert_match 'Highlights', @response.body
# end
@@ -284,7 +282,7 @@ class SearchControllerTest < ActionController::TestCase
get :enterprises, :page => '2'
- assert_equal 1, assigns(:results)[:enterprises].size
+ assert_equal 1, assigns(:searches)[:enterprises][:results].size
end
should 'display a given category' do
@@ -326,7 +324,7 @@ class SearchControllerTest < ActionController::TestCase
get :category_index, :category_path => ['parent-category'], :query => 'test_profile'
- assert_includes assigns(:results)[:people], p
+ assert_includes assigns(:searches)[:people][:results], p
end
# should 'find enterprise by product category' do
@@ -338,10 +336,10 @@ class SearchControllerTest < ActionController::TestCase
#
# get :index, :query => prod_cat.name
#
-# assert_includes assigns('results')[:enterprises], ent1
-# assert_not_includes assigns('results')[:enterprises], ent2
+# assert_includes assigns(:searches)[:enterprises][:results], ent1
+# assert_not_includes assigns(:searches)[:enterprises][:results], ent2
# end
-#
+
# should 'show only results in general search' do
# ent1 = create_profile_with_optional_category(Enterprise, 'test1')
# prod_cat = ProductCategory.create!(:name => 'pctest', :environment => Environment.default)
@@ -352,8 +350,8 @@ class SearchControllerTest < ActionController::TestCase
# get :index, :query => prod_cat.name
#
# assert assigns(:facets).blank?
-# assert_nil assigns(:results)[:enterprises].facets
-# assert_nil assigns(:results)[:products].facets
+# assert_nil assigns(:searches)[:enterprises].facets
+# assert_nil assigns(:searches)[:products].facets
# end
should 'render specific action when only one asset is enabled' do
@@ -370,23 +368,23 @@ class SearchControllerTest < ActionController::TestCase
get :index, :query => 'something'
end
-# should 'search all enabled assets in general search' do
-# ent1 = create_profile_with_optional_category(Enterprise, 'test enterprise')
-# prod_cat = ProductCategory.create!(:name => 'pctest', :environment => Environment.default)
-# prod = ent1.products.create!(:name => 'test product', :product_category => prod_cat)
-# art = Article.create!(:name => 'test article', :profile_id => fast_create(Person).id)
-# per = Person.create!(:name => 'test person', :identifier => 'test-person', :user_id => fast_create(User).id)
-# com = Community.create!(:name => 'test community')
-# eve = Event.create!(:name => 'test event', :profile_id => fast_create(Person).id)
-#
-# get :index, :query => 'test'
-#
-# [:articles, :enterprises, :people, :communities, :products, :events].select do |key, name|
-# !@controller.environment.enabled?('disable_asset_' + key.to_s)
-# end.each do |asset|
-# assert !assigns(:results)[asset].docs.empty?
-# end
-# end
+ should 'search all enabled assets in general search' do
+ ent1 = create_profile_with_optional_category(Enterprise, 'test enterprise')
+ prod_cat = ProductCategory.create!(:name => 'pctest', :environment => Environment.default)
+ prod = ent1.products.create!(:name => 'test product', :product_category => prod_cat)
+ art = Article.create!(:name => 'test article', :profile_id => fast_create(Person).id)
+ per = Person.create!(:name => 'test person', :identifier => 'test-person', :user_id => fast_create(User).id)
+ com = Community.create!(:name => 'test community')
+ eve = Event.create!(:name => 'test event', :profile_id => fast_create(Person).id)
+
+ get :index, :query => 'test'
+
+ [:articles, :enterprises, :people, :communities, :products, :events].select do |key, name|
+ !@controller.environment.enabled?('disable_asset_' + key.to_s)
+ end.each do |asset|
+ assert !assigns(:searches)[asset][:results].empty?
+ end
+ end
should 'display category image while in directory' do
parent = Category.create!(:name => 'category1', :environment => Environment.default)
@@ -399,15 +397,15 @@ class SearchControllerTest < ActionController::TestCase
assert_tag :tag => 'img', :attributes => { :src => /rails_thumb\.png/ }
end
-# should 'search for events' do
-# person = create_user('teste').person
-# ev = create_event(person, :name => 'an event to be found')
-#
-# get :events, :query => 'event found'
-#
-# assert_includes assigns(:results)[:events], ev
-# assert !assigns(:results)[:events].facets.nil?
-# end
+ should 'search for events' do
+ person = create_user('teste').person
+ event = create_event(person, :name => 'an event to be found')
+
+ get :events, :query => 'event to be found'
+
+ assert_includes assigns(:searches)[:events][:results], event
+# assert !assigns(:searches)[:events].facets.nil?
+ end
should 'return events of the day' do
person = create_user('someone').person
@@ -452,8 +450,8 @@ class SearchControllerTest < ActionController::TestCase
get :events
- assert_not_includes assigns(:results)[:events], ev1
- assert_includes assigns(:results)[:events], ev2
+ assert_not_includes assigns(:searches)[:events][:results], ev1
+ assert_includes assigns(:searches)[:events][:results], ev2
end
should 'list events for a given month' do
@@ -464,7 +462,7 @@ class SearchControllerTest < ActionController::TestCase
get :events, :year => '2008', :month => '1'
- assert_equal [ 'upcoming event 1' ], assigns(:results)[:events].map(&:name)
+ assert_equal [ 'upcoming event 1' ], assigns(:searches)[:events][:results].map(&:name)
end
%w[ people enterprises articles events communities products ].each do |asset|
@@ -482,7 +480,7 @@ class SearchControllerTest < ActionController::TestCase
get :products, :product_category => prod_cat.id
- assert_includes assigns(:results)[:products], p
+ assert_includes assigns(:searches)[:products][:results], p
end
# Testing random sequences always have a small chance of failing
@@ -494,16 +492,16 @@ class SearchControllerTest < ActionController::TestCase
# end
#
# get :products
-# result1 = assigns(:results)[:products].docs.map(&:id)
+# result1 = assigns(:searches)[:products][:results].map(&:id)
#
# (1..10).each do |n|
# get :products
# end
-# result2 = assigns(:results)[:products].docs.map(&:id)
+# result2 = assigns(:searches)[:products][:results].map(&:id)
#
# assert_not_equal result1, result2
# end
-#
+
# should 'remove far products by geolocalization empty logged search' do
# user = create_user('a_logged_user')
# # trigger geosearch
@@ -523,7 +521,7 @@ class SearchControllerTest < ActionController::TestCase
# prod4 = Product.create!(:name => 'produto 4', :enterprise_id => ent4.id, :product_category_id => cat.id)
#
# get :products
-# assert_equivalent [prod1, prod3, prod2], assigns(:results)[:products].docs
+# assert_equivalent [prod1, prod3, prod2], assigns(:searches)[:products].docs
# end
should 'display properly in conjuntion with a category' do
@@ -536,7 +534,7 @@ class SearchControllerTest < ActionController::TestCase
get :products, :category_path => cat.path.split('/'), :product_category => prod_cat1.id
- assert_includes assigns(:results)[:products], product
+ assert_includes assigns(:searches)[:products][:results], product
end
should 'provide calendar for events' do
@@ -555,9 +553,9 @@ class SearchControllerTest < ActionController::TestCase
person = create_user('teste').person
art = TextileArticle.create!(:name => 'an text_article article to be found', :profile => person)
- get 'articles', :query => 'article found'
+ get 'articles', :query => 'article to be found'
- assert_includes assigns(:results)[:articles], art
+ assert_includes assigns(:searches)[:articles][:results], art
end
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 < ActionController::TestCase
get :index, :query => 'test'
- assert_equal 20, assigns(:results)[:enterprises].total_entries
+ assert_equal 20, assigns(:searches)[:enterprises][:results].total_entries
end
should 'find products when enterprises has own hostname' do
@@ -591,7 +589,7 @@ class SearchControllerTest < ActionController::TestCase
ent.domains << Domain.new(:name => 'testent.com'); ent.save!
prod = ent.products.create!(:name => 'a beautiful product', :product_category => @product_category)
get 'products', :query => 'beautiful'
- assert_includes assigns(:results)[:products], prod
+ assert_includes assigns(:searches)[:products][:results], prod
end
should 'add script tag for google maps if searching products' do
@@ -657,7 +655,7 @@ class SearchControllerTest < ActionController::TestCase
get :people
assert_equal SearchController::BLOCKS_SEARCH_LIMIT+3, Person.count
- assert_equal SearchController::BLOCKS_SEARCH_LIMIT, assigns(:results)[:people].count
+ assert_equal SearchController::BLOCKS_SEARCH_LIMIT, assigns(:searches)[:people][:results].count
assert_tag :a, '', :attributes => {:class => 'next_page'}
end
@@ -667,7 +665,7 @@ class SearchControllerTest < ActionController::TestCase
c3 = create(Community, :name => 'Testing community 3')
get :communities
- assert_equal [c3,c2,c1] , assigns(:results)[:communities]
+ assert_equal [c3,c2,c1] , assigns(:searches)[:communities][:results]
end
should "paginate search of communities in groups of #{SearchController::BLOCKS_SEARCH_LIMIT}" do
@@ -677,7 +675,7 @@ class SearchControllerTest < ActionController::TestCase
get :communities
assert_equal SearchController::BLOCKS_SEARCH_LIMIT+3, Community.count
- assert_equal SearchController::BLOCKS_SEARCH_LIMIT, assigns(:results)[:communities].count
+ assert_equal SearchController::BLOCKS_SEARCH_LIMIT, assigns(:searches)[:communities][:results].count
assert_tag :a, '', :attributes => {:class => 'next_page'}
end
@@ -691,21 +689,21 @@ class SearchControllerTest < ActionController::TestCase
fast_create(ActionTracker::Record, :target_id => c2, :user_type => 'Profile', :user_id => person, :created_at => Time.now)
fast_create(ActionTracker::Record, :target_id => c2, :user_type => 'Profile', :user_id => person, :created_at => Time.now)
get :communities, :filter => 'more_active'
- assert_equal [c2,c1,c3] , assigns(:results)[:communities]
+ assert_equal [c2,c1,c3] , assigns(:searches)[:communities][:results]
end
should "only include visible people in more_recent filter" do
# assuming that all filters behave the same!
p1 = fast_create(Person, :visible => false)
get :people, :filter => 'more_recent'
- assert_not_includes assigns(:results), p1
+ assert_not_includes assigns(:searches)[:people][:results], p1
end
should "only include visible communities in more_recent filter" do
# assuming that all filters behave the same!
p1 = fast_create(Community, :visible => false)
get :communities, :filter => 'more_recent'
- assert_not_includes assigns(:results), p1
+ assert_not_includes assigns(:searches)[:communities][:results], p1
end
# should 'browse facets when query is not empty' do
@@ -729,17 +727,17 @@ class SearchControllerTest < ActionController::TestCase
should 'keep old urls working' do
get :assets, :asset => 'articles'
- assert_redirected_to :controller => :search, :action => :articles, :display => 'list'
+ assert_redirected_to :controller => :search, :action => :articles
get :assets, :asset => 'people'
- assert_redirected_to :controller => :search, :action => :people, :display => 'list'
+ assert_redirected_to :controller => :search, :action => :people
get :assets, :asset => 'communities'
- assert_redirected_to :controller => :search, :action => :communities, :display => 'list'
+ assert_redirected_to :controller => :search, :action => :communities
get :assets, :asset => 'products'
- assert_redirected_to :controller => :search, :action => :products, :display => 'list'
+ assert_redirected_to :controller => :search, :action => :products
get :assets, :asset => 'enterprises'
- assert_redirected_to :controller => :search, :action => :enterprises, :display => 'list'
+ assert_redirected_to :controller => :search, :action => :enterprises
get :assets, :asset => 'events'
- assert_redirected_to :controller => :search, :action => :events, :display => 'list'
+ assert_redirected_to :controller => :search, :action => :events
end
should 'show tag cloud' do
@@ -765,25 +763,25 @@ class SearchControllerTest < ActionController::TestCase
get :tag, :tag => 'two'
- assert_equal [a, a2], assigns(:results)[:tag]
+ assert_equal [a, a2], assigns(:searches)[:tag][:results]
get :tag, :tag => 'one'
- assert_equal [a], assigns(:results)[:tag]
+ assert_equal [a], assigns(:searches)[:tag][:results]
+ end
+
+ should 'not show assets from other environments' do
+ other_env = Environment.create!(:name => 'Another environment')
+ p1 = Person.create!(:name => 'Hildebrando', :identifier => 'hild', :user_id => fast_create(User).id, :environment_id => other_env.id)
+ p2 = Person.create!(:name => 'Adamastor', :identifier => 'adam', :user_id => fast_create(User).id)
+ art1 = Article.create!(:name => 'my article', :profile_id => p1.id)
+ art2 = Article.create!(:name => 'my article', :profile_id => p2.id)
+
+ get :articles, :query => 'my article'
+
+ assert_equal [art2], assigns(:searches)[:articles][:results]
end
-# should 'not show assets from other environments' do
-# other_env = Environment.create!(:name => 'Another environment')
-# p1 = Person.create!(:name => 'Hildebrando', :identifier => 'hild', :user_id => fast_create(User).id, :environment_id => other_env.id)
-# p2 = Person.create!(:name => 'Adamastor', :identifier => 'adam', :user_id => fast_create(User).id)
-# art1 = Article.create!(:name => 'my article', :profile_id => p1.id)
-# art2 = Article.create!(:name => 'my article', :profile_id => p2.id)
-#
-# get :articles, :query => 'my article'
-#
-# assert_equal [art2], assigns(:results)[:articles].docs
-# end
-#
# should 'order product results by more recent when requested' do
# ent = fast_create(Enterprise)
# prod1 = Product.create!(:name => 'product 1', :enterprise_id => ent.id, :product_category_id => @product_category.id)
@@ -799,7 +797,7 @@ class SearchControllerTest < ActionController::TestCase
#
# get :products, :query => 'product', :order_by => :more_recent
#
-# assert_equal [prod2, prod1, prod3], assigns(:results)[:products].docs
+# assert_equal [prod2, prod1, prod3], assigns(:searches)[:products].docs
# end
#
# should 'only list products from enabled enterprises' do
@@ -810,7 +808,8 @@ class SearchControllerTest < ActionController::TestCase
#
# get :products, :query => 'product'
#
-# assert_equal [prod1], assigns(:results)[:products].docs
+# assert_includes assigns(:searches)[:products][:results], prod1
+# assert_not_includes assigns(:searches)[:products][:results], prod2
# end
#
# should 'order product results by name when requested' do
@@ -825,7 +824,7 @@ class SearchControllerTest < ActionController::TestCase
#
# get :products, :query => 'product', :order_by => :name
#
-# assert_equal [prod3, prod2, prod1], assigns(:results)[:products].docs
+# assert_equal [prod3, prod2, prod1], assigns(:searches)[:products].docs
# end
#
# should 'order product results by closest when requested' do
@@ -845,7 +844,7 @@ class SearchControllerTest < ActionController::TestCase
# prod3 = Product.create!(:name => 'product 3', :enterprise_id => ent3.id, :product_category_id => cat.id)
#
# get :products, :query => 'product', :order_by => :closest
-# assert_equal [prod2, prod1, prod3], assigns(:results)[:products].docs
+# assert_equal [prod2, prod1, prod3], assigns(:searches)[:products].docs
# end
#
#
@@ -856,7 +855,7 @@ class SearchControllerTest < ActionController::TestCase
#
# get :events, :query => 'party', :order_by => :name
#
-# assert_equal [ev2, ev1], assigns(:results)[:events].docs
+# assert_equal [ev2, ev1], assigns(:searches)[:events].docs
# end
#
# should 'order articles by name when requested' do
@@ -866,7 +865,7 @@ class SearchControllerTest < ActionController::TestCase
#
# get :articles, :query => 'review', :order_by => :name
#
-# assert_equal [art2, art3, art1], assigns(:results)[:articles].docs
+# assert_equal [art2, art3, art1], assigns(:searches)[:articles].docs
# end
should 'order articles by more recent' do
@@ -877,7 +876,7 @@ class SearchControllerTest < ActionController::TestCase
get :articles, :filter => :more_recent
- assert_equal [art2, art1, art3], assigns(:results)[:articles]
+ assert_equal [art2, art1, art3], assigns(:searches)[:articles][:results]
end
# should 'order enterprise results by name when requested' do
@@ -887,7 +886,7 @@ class SearchControllerTest < ActionController::TestCase
#
# get :enterprises, :query => 'Company', :order_by => :name
#
-# assert_equal [ent2, ent1, ent3], assigns(:results)[:enterprises].docs
+# assert_equal [ent2, ent1, ent3], assigns(:searches)[:enterprises].docs
# end
#
# should 'order people results by name when requested' do
@@ -897,7 +896,7 @@ class SearchControllerTest < ActionController::TestCase
#
# get :people, :query => 'Silva', :order_by => :name
#
-# assert_equal [person3, person1, person2], assigns(:results)[:people].docs
+# assert_equal [person3, person1, person2], assigns(:searches)[:people].docs
# end
#
# should 'order community results by name when requested' do
@@ -907,7 +906,7 @@ class SearchControllerTest < ActionController::TestCase
#
# get :communities, :query => 'Group', :order_by => :name
#
-# assert_equal [com3, com2, com1], assigns(:results)[:communities].docs
+# assert_equal [com3, com2, com1], assigns(:searches)[:communities].docs
# end
#
# should 'raise error when requested to order by unknown filter' do
diff --git a/test/integration/assigning_validator_organizations_to_regions_test.rb b/test/integration/assigning_validator_organizations_to_regions_test.rb
index 06c5e4c..31a1d4c 100644
--- a/test/integration/assigning_validator_organizations_to_regions_test.rb
+++ b/test/integration/assigning_validator_organizations_to_regions_test.rb
@@ -3,7 +3,6 @@ require "#{File.dirname(__FILE__)}/../test_helper"
class AssigningValidatorOrganizationsToRegionsTest < ActionController::IntegrationTest
should 'be able to properly assign organizations as validators to regions' do
- TestSolr.enable
env = Environment.default
Organization.destroy_all
diff --git a/test/unit/search_helper_test.rb b/test/unit/search_helper_test.rb
index 73bddd1..1095225 100644
--- a/test/unit/search_helper_test.rb
+++ b/test/unit/search_helper_test.rb
@@ -35,7 +35,7 @@ class SearchHelperTest < ActiveSupport::TestCase
title = 'page_title'
category = mock
category.stubs(:name).returns('category_name')
- assert_equal 'page_titlecategory_name
',
+ assert_equal 'page_title - category_name
',
search_page_title(title, category)
end
@@ -58,22 +58,10 @@ class SearchHelperTest < ActiveSupport::TestCase
should 'display results with map' do
stubs(:params).returns({:display => 'map'})
@query = 'test'
- @results = {:products => [1,2]}
+ @searches = {:products => {:results => [1,2]}}
expects('render').with({:partial => 'google_maps'}).returns('render_return')
expects('content_tag').with('div', 'render_return', :class => 'map-or-list-search-results map')
- display_results true
- end
-
- should 'show display_list button when in map view' do
- stubs(:params).returns({:display => 'map'})
- expects(:button).with(:search, 'Display in list', {:display => 'list'}, anything)
- display_map_list_button
- end
-
- should 'show display_map button when in list view' do
- stubs(:params).returns({:display => ''})
- expects(:button).with(:search, 'Display in map', {:display => 'map'}, anything)
- display_map_list_button
+ display_results(@searches, :products)
end
should 'return full city name with state' do
@@ -125,135 +113,6 @@ class SearchHelperTest < ActiveSupport::TestCase
city.stubs(:name).returns('Feliz Deserto')
assert_equal 'Feliz Deserto', city_with_state(city)
end
-
- should 'display facets menu' do
- expects(:asset_class).with('asset')
- expects(:render).with(:partial => 'facets_menu')
- facets_menu 'asset', nil
- end
-
- should 'display facets_unselect menu' do
- expects(:asset_class).with('asset')
- expects(:render).with(:partial => 'facets_unselect_menu')
- facets_unselect_menu 'asset'
- end
-
- should 'display facets javascript' do
- expects(:text_field_tag).returns('')
- expects(:javascript_tag).with(regexp_matches(/id.*[\'array_item\'].*json_message/m)).returns(
- '')
- stubs(:jquery_token_input_messages_json).returns('json_message')
- assert_equal '',
- facet_javascript('id', '', ['array_item'])
- end
-
- should 'display empty array in facets javascript if array is nil' do
- expects(:text_field_tag).returns('')
- expects(:javascript_tag).with(regexp_matches(/id.*\[\].*json_message/m)).returns(
- '')
- stubs(:jquery_token_input_messages_json).returns('json_message')
- assert_equal '',
- facet_javascript('id', '', [])
- end
-
- should 'return html code for facet link' do
- facet = {
- :solr_field => 'facet_solr_field',
- :label_id => 'facet_label_id'
- }
- params = {}
- value = 'facet_value'
- label = 'facet_label'
- count = 1
-
- expected_url = {:facet => {'facet_solr_field' => { 'facet_label_id' => ['facet_value']}}}
-
- expects(:link_to).with('facet_label', expected_url, anything).returns('')
- stubs(:content_tag).with(anything, '', anything).returns('')
- stubs(:content_tag).with(anything, ' (1)', anything).returns('')
- stubs(:content_tag).with(anything, '', anything).returns('')
-
- assert_equal '',
- facet_link_html(facet, params, value, label, count)
- end
-
- should 'return html code for facet link with extra label' do
- facet = {
- :solr_field => 'facet_solr_field',
- :label_id => 'facet_label_id'
- }
- params = {}
- value = 'facet_value'
- label = ['facet_label', 'facet_extra']
- count = 1
-
- expected_url = {:facet => {'facet_solr_field' => { 'facet_label_id' => ['facet_value']}}}
-
- expects(:link_to).with('facet_label', expected_url, anything).returns('')
- stubs(:content_tag).with(anything, 'facet_extra', anything).returns('')
- stubs(:content_tag).with(anything, ' (1)', anything).returns('')
- stubs(:content_tag).with(anything, '', anything).returns('')
-
- assert_equal '',
- facet_link_html(facet, params, value, label, count)
- end
-
- should 'return html code for selected facet link' do
- facet = {
- :solr_field => 'facet_solr_field'
- }
- params = {:facet => {'facet_solr_field' => 'facet_value'}}
- value = 'facet_value'
- label = 'facet_label'
- count = 1
-
- expected_url = {:facet => {'facet_solr_field' => 'facet_value'}}
-
- expects(:link_to).with('facet_label', expected_url, anything).returns('')
- stubs(:content_tag).with(anything, '', anything).returns('')
- stubs(:content_tag).with(anything, ' (1)', anything).returns('')
- stubs(:content_tag).with(anything, '', {:class => 'facet-menu-item facet-result-link-selected'}).returns('')
-
- assert_equal '',
- facet_link_html(facet, params, value, label, count)
- end
-
- should 'show html for non-hash selected facets' do
- klass = mock
- klass.stubs(:facet_by_id).with(:facet_id).returns('klass_facet_by_id')
- klass.stubs(:facet_label).with('klass_facet_by_id').returns('klass_facet_label')
- klass.stubs(:facet_result_name).with('klass_facet_by_id', 'facet_value').returns('klass_facet_result_name')
- params = {:facet => {:facet_id => 'facet_value'}}
-
- expects(:content_tag).with(anything, 'klass_facet_label', anything).returns('')
- expects(:content_tag).with(anything, 'klass_facet_result_name', anything).returns('')
- expects(:link_to).with(anything, {:facet => {}}, anything).returns('')
- expects(:content_tag).with(anything, '', anything).returns('')
-
- environment = mock
- assert_match '', facet_selecteds_html_for(environment, klass, params)
- end
-
- should 'show select tag for order_by' do
- [:products, :events, :articles, :enterprises, :people, :communities].each do |asset|
- params = {:order_by => 'Relevance'}
-
- stubs(:params).returns(params)
- stubs(:logged_in?).returns(false)
- stubs(:options_for_select).with(instance_of(Array), params[:order_by]).returns('')
- stubs(:select_tag).with(regexp_matches(/#{asset}/), '', anything).returns('')
- expects(:content_tag).with(anything, regexp_matches(//), anything).returns('')
-
- assert_equal '', order_by(asset)
- end
- end
-
- should 'show total of assets found' do
- [:products, :events, :articles, :enterprises, :people, :communities].each do |asset|
- expects(:content_tag).with(anything, regexp_matches(/10.*#{asset}.*found/), anything).returns('')
- assert_equal '', label_total_found(asset, 10)
- end
- end
should 'return asset class from string' do
asset_names = ['products', 'events', 'articles', 'enterprises', 'people', 'communities']
@@ -263,12 +122,4 @@ class SearchHelperTest < ActiveSupport::TestCase
end
end
- should 'return asset table from string' do
- asset_classes = [Product, Event, Article, Enterprise, Person, Community]
- asset_tables = ['products', 'articles', 'articles', 'profiles', 'profiles', 'profiles']
- asset_classes.each_index do |i|
- assert_equal asset_tables[i], asset_table(asset_classes[i])
- end
- end
-
end
diff --git a/test/unit/set_profile_region_from_city_state_test.rb b/test/unit/set_profile_region_from_city_state_test.rb
index e3659dd..87f46c0 100644
--- a/test/unit/set_profile_region_from_city_state_test.rb
+++ b/test/unit/set_profile_region_from_city_state_test.rb
@@ -2,11 +2,6 @@ require File.dirname(__FILE__) + '/../test_helper'
class SetProfileRegionFromCityStateTest < ActiveSupport::TestCase
- def setup
- super
- TestSolr.enable
- end
-
should 'set city and state from names' do
s = State.create!(:name => 'Sao Paulo', :acronym => 'SP', :environment_id => Environment.default.id)
c = City.create!(:name => 'Pindamonhangaba', :parent_id => s.id, :environment_id => Environment.default.id)
diff --git a/test/unit/textile_article_test.rb b/test/unit/textile_article_test.rb
index 95618fb..5787505 100644
--- a/test/unit/textile_article_test.rb
+++ b/test/unit/textile_article_test.rb
@@ -182,9 +182,4 @@ class TextileArticleTest < ActiveSupport::TestCase
article
end
- should 'define type facet' do
- a = TextileArticle.new
- assert_equal TextArticle.type_name, TextileArticle.send(:f_type_proc, a.send(:f_type))
- end
-
end
diff --git a/test/unit/tiny_mce_article_test.rb b/test/unit/tiny_mce_article_test.rb
index aa2853c..56dd771 100644
--- a/test/unit/tiny_mce_article_test.rb
+++ b/test/unit/tiny_mce_article_test.rb
@@ -224,9 +224,4 @@ end
assert TinyMceArticle.new.tiny_mce?
end
- should 'define type facet' do
- a = TinyMceArticle.new
- assert_equal TextArticle.type_name, TinyMceArticle.send(:f_type_proc, a.send(:f_type))
- end
-
end
--
libgit2 0.21.2