diff --git a/app/controllers/public/search_controller.rb b/app/controllers/public/search_controller.rb index bcad937..d45c5c2 100644 --- a/app/controllers/public/search_controller.rb +++ b/app/controllers/public/search_controller.rb @@ -29,19 +29,6 @@ class SearchController < ApplicationController end end - def action_product_category - @products = category.products - @enterprises = category.products.map{|p| p.enterprise}.flatten.uniq - @users = category.consumers - end - - def action_category - @recent_articles = @finder.recent('articles') - @recent_comments = @finder.recent('comments') - @most_commented_articles = @finder.most_commented_articles - end - alias :action_region :action_category - public include SearchHelper @@ -58,7 +45,7 @@ class SearchController < ApplicationController ] # TODO don't hardcode like this >:-( - LIST_LIMIT = 10 + LIST_LIMIT = 20 def index @query = params[:query] || '' @@ -76,7 +63,18 @@ class SearchController < ApplicationController # view the summary of one category def category_index - send('action_' + category.class.name.underscore) + @results = {} + @names = {} + [ + [ :recent_people, _('Recently registered people'), @finder.recent('people') ], + [ :recent_communities, _('Recently created communities'), @finder.recent('communities') ], + [ :recent_articles, _('Recent articles'), @finder.recent('articles') ], + [ :recent_comments, _('Recent comments'), @finder.recent('comments') ], + [ :most_commented_articles, _('Most commented articles'), @finder.most_commented_articles ] + ].each do |key, name, list| + @results[key] = list + @names[key] = name + end end attr_reader :category diff --git a/app/views/search/_category.rhtml b/app/views/search/_category.rhtml deleted file mode 100644 index 0486f9e..0000000 --- a/app/views/search/_category.rhtml +++ /dev/null @@ -1,34 +0,0 @@ - -
-

<%= _('Recent articles') %>

-
- -
-
- -
- -
-

<%= _('Recent Comments') %>

-
-
    - <% @recent_comments.each do |comment| %> - <%= render :partial => 'comment', :object => comment %> - <% end %> -
-
-
- -
-

<%= _('Most commented articles') %>

-
-
    - <%= render :partial => 'article', :collection => @most_commented_articles %> -
-
-
- -
- diff --git a/app/views/search/_display_results.rhtml b/app/views/search/_display_results.rhtml index f0c8201..40d4ad7 100644 --- a/app/views/search/_display_results.rhtml +++ b/app/views/search/_display_results.rhtml @@ -1,6 +1,6 @@
-<% if @category %> +<% if @category && !@query.blank? %>
<%= link_to _('Search for "%s" in the whole site') % @query, :controller => 'search', :action => 'index', :category_path => [], :query => @query %> diff --git a/app/views/search/_product_category.rhtml b/app/views/search/_product_category.rhtml deleted file mode 100644 index 1d9d887..0000000 --- a/app/views/search/_product_category.rhtml +++ /dev/null @@ -1,29 +0,0 @@ -<%= link_to(_('I consume this'), {:profile => current_user.login, :controller => 'consumed_products', :action => 'new', 'consumption[product_category_id]' => @category.id }, :method => :post) if logged_in? %> - - -

<%= _('Products under this category:') %>

- - -

<%= _('Users that consumes products in this category:') %>

- -<% @users.each do |u| %> -

- <%= image_tag u.image.public_filename(:thumb) if u.image %>
- <%= link_to_homepage(u.name, u.identifier) %> -

-<% end %> diff --git a/app/views/search/_region.rhtml b/app/views/search/_region.rhtml deleted file mode 120000 index 859d4d2..0000000 --- a/app/views/search/_region.rhtml +++ /dev/null @@ -1 +0,0 @@ -_category.rhtml \ No newline at end of file diff --git a/app/views/search/assets.rhtml b/app/views/search/assets.rhtml index 260869b..dfa7cad 100644 --- a/app/views/search/assets.rhtml +++ b/app/views/search/assets.rhtml @@ -1,3 +1,3 @@ -

<%= @category ? (_('%{asset_name} in %{category}') % { :asset_name => @asset_name, :category => @category.full_name}) : @asset_name %>

+

<%= @category ? (_('%{asset_name} in %{category}') % { :asset_name => @asset_name, :category => @category.name}) : @asset_name %>

<%= render :partial => 'display_results' %> diff --git a/app/views/search/category_index.rhtml b/app/views/search/category_index.rhtml index f4222b1..edd7068 100644 --- a/app/views/search/category_index.rhtml +++ b/app/views/search/category_index.rhtml @@ -6,10 +6,8 @@

<%= _('Category: %s') % @category.name %>

-
- <%= render :partial => @category.class.name.underscore %> -
- + <%= render :partial => 'display_results' %> +

<%= _('Sub-categories') %>

<% if @category.children.empty? %> diff --git a/test/functional/search_controller_test.rb b/test/functional/search_controller_test.rb index f66067b..6565e0f 100644 --- a/test/functional/search_controller_test.rb +++ b/test/functional/search_controller_test.rb @@ -433,46 +433,62 @@ class SearchControllerTest < Test::Unit::TestCase end should 'list recent articles in the category' do - @controller.expects(:category).returns(@category).at_least_once recent = [] - finder = CategoryFinder.new(@category) - finder.expects(:recent).with('comments').returns(recent) - finder.expects(:recent).with('articles').returns(recent) - CategoryFinder.expects(:new).with(@category).returns(finder) + finger = CategoryFinder.new(@category) + finger.expects(:recent).with(anything).at_least_once + finger.expects(:recent).with('articles').returns(recent) + CategoryFinder.expects(:new).with(@category).returns(finger) get :category_index, :category_path => [ 'my-category' ] - assert_same recent, assigns(:recent_articles) + assert_same recent, assigns(:results)[:recent_articles] end should 'list recent comments in the category' do - @controller.expects(:category).returns(@category).at_least_once recent = [] - finder = CategoryFinder.new(@category) - finder.expects(:recent).with('comments').returns(recent) - finder.expects(:recent).with('articles').returns(recent) - CategoryFinder.expects(:new).with(@category).returns(finder) + finger = CategoryFinder.new(@category) + finger.expects(:recent).with(anything).at_least_once + finger.expects(:recent).with('comments').returns(recent) + CategoryFinder.expects(:new).with(@category).returns(finger) get :category_index, :category_path => [ 'my-category' ] - assert_same recent, assigns(:recent_comments) + assert_same recent, assigns(:results)[:recent_comments] end should 'list most commented articles in the category' do - @controller.expects(:category).returns(@category).at_least_once most_commented = [] - finder = CategoryFinder.new(@category) - finder.expects(:most_commented_articles).returns(most_commented) - CategoryFinder.expects(:new).with(@category).returns(finder) + finger = CategoryFinder.new(@category) + finger.expects(:most_commented_articles).returns(most_commented) + CategoryFinder.expects(:new).with(@category).returns(finger) get :category_index, :category_path => [ 'my-category' ] - assert_same most_commented, assigns(:most_commented_articles) + assert_same most_commented, assigns(:results)[:most_commented_articles] end - should 'display category of products' do - cat = ProductCategory.create!(:name => 'Food', :environment => Environment.default) - ent = Enterprise.create!(:name => 'Enterprise test', :identifier => 'enterprise_test') - p = cat.products.create!(:name => 'product test', :enterprise => ent) - get :category_index, :category_path => cat.path.split('/') - assert_includes assigns(:products), p + should 'list recently registered people in the category' do + recent_people = [] + finger = CategoryFinder.new(@category) + finger.expects(:recent).with(anything).at_least_once + finger.expects(:recent).with('people').returns(recent_people) + CategoryFinder.expects(:new).with(@category).returns(finger) + + get :category_index, :category_path => [ 'my-category' ] + assert_same recent_people, assigns(:results)[:recent_people] + end + + should 'list recently registered communities in the category' do + recent_communities = [] + finger = CategoryFinder.new(@category) + finger.expects(:recent).with(anything).at_least_once + finger.expects(:recent).with('communities').returns(recent_communities) + CategoryFinder.expects(:new).with(@category).returns(finger) + + get :category_index, :category_path => [ 'my-category' ] + assert_same recent_communities, assigns(:results)[:recent_communities] + end + + should 'not list "Search for ..." in category_index' do + get :category_index, :category_path => [ 'my-category' ] + assert_no_tag :content => /Search for ".*" in the whole site/ end # SECURITY -- libgit2 0.21.2