diff --git a/app/views/search/_category.rhtml b/app/views/search/_category.rhtml
new file mode 100644
index 0000000..ae00189
--- /dev/null
+++ b/app/views/search/_category.rhtml
@@ -0,0 +1,24 @@
+
+
diff --git a/app/views/search/_comment.rhtml b/app/views/search/_comment.rhtml
index f8563f2..ebc500c 100644
--- a/app/views/search/_comment.rhtml
+++ b/app/views/search/_comment.rhtml
@@ -1,10 +1,8 @@
-
-
-
- <%= link_to(hit.title, hit.url) %>
-
-
-
- <%= strip_tags(hit.body) %>
-
+
+ <%= link_to(hit.title, hit.url)%>
+
+ <%= _('by %s, on "%s"') % [hit.author_name, link_to(hit.article.name, hit.article.url)] %>
+
+
+
diff --git a/app/views/search/_product.rhtml b/app/views/search/_product.rhtml
index 1dc4678..aa1a226 100644
--- a/app/views/search/_product.rhtml
+++ b/app/views/search/_product.rhtml
@@ -1,5 +1,6 @@
<%# FIXME add more information %>
+
<%= image_tag(hit.image.public_filename(:minor)) if hit.image %>
@@ -13,3 +14,4 @@
<%= _('Category: %s') % link_to_category(hit.product_category) %>
+
diff --git a/app/views/search/_product_category.rhtml b/app/views/search/_product_category.rhtml
new file mode 100644
index 0000000..1d9d887
--- /dev/null
+++ b/app/views/search/_product_category.rhtml
@@ -0,0 +1,29 @@
+<%= 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? %>
+
+ - <%= n_("One product in this category.", "%{num} products in this category.", @products.size) % { :num => @products.size } %>
+ - <%= n_("One enterprise sells products in this category.", "%{num} enterprises sells products in this category.", @enterprises.size) % { :num => @enterprises.size} %>
+ - <%= n_("One user consumes this product.", "%{num} users consumes this product", @users.size) % {:num => @users.size} %>
+
+
+
<%= _('Products under this category:') %>
+
+ <% @products.each do |p| %>
+ -
+ <%= image_tag p.image.public_filename(:thumb) if p.image%>
+ <%= link_to_product(p) %>
+ <% if p.price %>
+ <%= _('Price: %d') % p.price %>
+ <% end %>
+ <%= _('Enterprise:') %> <%= link_to_homepage p.enterprise.name, p.enterprise.identifier %>
+
+ <% end %>
+
+
+
<%= _('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/_profile.rhtml b/app/views/search/_profile.rhtml
index 0d21f7f..fca8153 100644
--- a/app/views/search/_profile.rhtml
+++ b/app/views/search/_profile.rhtml
@@ -1,8 +1,9 @@
<%# FIXME add more information %>
-
-
- <%= image_tag(hit.image.public_filename(:minor)) if hit.image %>
-
- <%= link_to_homepage(hit.name, hit.identifier) %>
-
-
+
+
+ <%= image_tag(hit.image.public_filename(:minor)) if hit.image %>
+
+ <%= link_to_homepage(hit.name, hit.identifier) %>
+
+
+
diff --git a/app/views/search/_region.rhtml b/app/views/search/_region.rhtml
new file mode 120000
index 0000000..859d4d2
--- /dev/null
+++ b/app/views/search/_region.rhtml
@@ -0,0 +1 @@
+_category.rhtml
\ No newline at end of file
diff --git a/app/views/search/category_index.rhtml b/app/views/search/category_index.rhtml
new file mode 100644
index 0000000..25465d1
--- /dev/null
+++ b/app/views/search/category_index.rhtml
@@ -0,0 +1,29 @@
+
+
+
+ <%= @category.ancestors.reverse.map { |a| link_to_category(a, false) }.join(' → ') %>
+
+
+
<%= _('Category: %s') % @category.name %>
+
+
+ <%= render :partial => @category.class.name.underscore %>
+
+
+
+
<%= _('Sub-categories') %>
+
+ <% if @category.children.empty? %>
+
<%= _('No sub-categories') %>
+ <% else %>
+
+ <% @category.children.each do |c| %>
+ - <%= link_to_category(c) %>
+ <% end %>
+
+ <% end %>
+
+
+
+
+
diff --git a/app/views/search/index.rhtml b/app/views/search/index.rhtml
index 3b5e892..7f2fee1 100644
--- a/app/views/search/index.rhtml
+++ b/app/views/search/index.rhtml
@@ -4,9 +4,11 @@
<% if !results.nil? and !results.empty? %>
<%= @names[name] %>
+
<% results.each do |hit| %>
<%= render :partial => partial_for_class(hit.class), :locals => { :hit => hit } %>
<% end %>
+
<% end %>
<% end %>
diff --git a/app/views/shared/categories_menu.rhtml b/app/views/shared/categories_menu.rhtml
index 7a34bc7..7b1c596 100644
--- a/app/views/shared/categories_menu.rhtml
+++ b/app/views/shared/categories_menu.rhtml
@@ -5,7 +5,7 @@
<%= item.name %>
<% item.children.each do |child| %>
- - <%= link_to(content_tag('span', child.name), :controller => 'category', :action => 'view', :category_path => child.explode_path) %>
+ - <%= link_to(content_tag('span', child.name), :controller => 'search', :action => 'category_index', :category_path => child.explode_path) %>
<% end %>
diff --git a/config/routes.rb b/config/routes.rb
index 1cfe8f6..a10d0e9 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -29,13 +29,12 @@ ActionController::Routing::Routes.draw do |map|
# tags
map.tag 'tag', :controller => 'search', :action => 'tags'
map.tag 'tag/:tag', :controller => 'search', :action => 'tag'
-
+ # categories index
+ map.category 'cat/*category_path', :controller => 'search', :action => 'category_index'
+ map.assets 'assets/:asset/*category_path', :controller => 'search', :action => 'assets'
# search
map.connect 'search/:action/*category_path', :controller => 'search'
- # categories controller
- map.connect 'cat', :controller => 'category', :action => 'index'
- map.category 'cat/*category_path', :controller => 'category', :action => 'view'
# public profile information
map.profile 'profile/:profile/:action/:id', :controller => 'profile', :action => 'index'
diff --git a/test/functional/category_controller_test.rb b/test/functional/category_controller_test.rb
deleted file mode 100644
index b14212a..0000000
--- a/test/functional/category_controller_test.rb
+++ /dev/null
@@ -1,61 +0,0 @@
-require File.dirname(__FILE__) + '/../test_helper'
-require 'category_controller'
-
-# Re-raise errors caught by the controller.
-class CategoryController; def rescue_action(e) raise e end; end
-
-class CategoryControllerTest < Test::Unit::TestCase
- def setup
- @controller = CategoryController.new
- @request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.new
-
- @category = Category.create!(:name => 'my category', :environment => Environment.default)
- end
-
- def test_should_display_a_given_category
- get :view, :category_path => [ 'my-category' ]
- assert_equal @category, assigns(:category)
- end
-
- should 'expose category in a method' do
- get :view, :category_path => [ 'my-category' ]
- assert_same assigns(:category), @controller.category
- end
-
- should 'list recent articles in the category' do
- @controller.expects(:category).returns(@category).at_least_once
- recent = []
- @category.expects(:recent_articles).returns(recent)
-
- get :view, :category_path => [ 'my-category' ]
- assert_same recent, assigns(:recent_articles)
- end
-
- should 'list recent comments in the category' do
- @controller.expects(:category).returns(@category).at_least_once
- recent = []
- @category.expects(:recent_comments).returns(recent)
-
- get :view, :category_path => [ 'my-category' ]
- assert_same recent, assigns(:recent_comments)
- end
-
- should 'list most commented articles in the category' do
- @controller.expects(:category).returns(@category).at_least_once
- most_commented = []
- @category.expects(:most_commented_articles).returns(most_commented)
-
- get :view, :category_path => [ 'my-category' ]
- assert_same most_commented, assigns(: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 :view, :category_path => cat.path.split('/')
- assert_includes assigns(:products), p
- end
-
-end
diff --git a/test/functional/search_controller_test.rb b/test/functional/search_controller_test.rb
index ec64992..7f2cc27 100644
--- a/test/functional/search_controller_test.rb
+++ b/test/functional/search_controller_test.rb
@@ -9,6 +9,8 @@ class SearchControllerTest < Test::Unit::TestCase
@controller = SearchController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
+
+ @category = Category.create!(:name => 'my category', :environment => Environment.default)
end
should 'filter stop words' do
@@ -52,11 +54,10 @@ class SearchControllerTest < Test::Unit::TestCase
should 'search for articles in a specific category' do
person = create_user('teste').person
- category = Category.create!(:name => 'my category', :environment => Environment.default)
# in category
art1 = person.articles.build(:name => 'an article to be found')
- art1.categories << category
+ art1.categories << @category
art1.save!
# not in category
@@ -83,11 +84,10 @@ class SearchControllerTest < Test::Unit::TestCase
should 'search in comments in a specific category' do
person = create_user('teste').person
- category = Category.create!(:name => 'my category', :environment => Environment.default)
# in category
art1 = person.articles.build(:name => 'an article to be found')
- art1.categories << category
+ art1.categories << @category
art1.save!
comment1 = art1.comments.build(:title => 'comment to be found', :body => 'hfyfyh', :author => person); comment1.save!
@@ -108,10 +108,9 @@ class SearchControllerTest < Test::Unit::TestCase
end
should 'find enterprises in a specified category' do
- category = Category.create!(:name => 'my category', :environment => Environment.default)
# in category
- ent1 = Enterprise.create!(:name => 'testing enterprise 1', :identifier => 'test1', :categories => [category])
+ ent1 = Enterprise.create!(:name => 'testing enterprise 1', :identifier => 'test1', :categories => [@category])
# not in category
ent2 = Enterprise.create!(:name => 'testing enterprise 2', :identifier => 'test2')
@@ -132,8 +131,7 @@ class SearchControllerTest < Test::Unit::TestCase
end
should 'find people in a specific category' do
- c = Category.create!(:name => 'my category', :environment => Environment.default)
- p1 = create_user('people_1').person; p1.name = 'a beautiful person'; p1.categories << c; p1.save!
+ p1 = create_user('people_1').person; p1.name = 'a beautiful person'; p1.categories << @category; p1.save!
p2 = create_user('people_2').person; p2.name = 'another beautiful person'; p2.save!
get :index, :category_path => [ 'my-category' ], :query => 'beautiful', :find_in => [ 'people' ]
assert_includes assigns(:results)[:people], p1
@@ -150,10 +148,9 @@ class SearchControllerTest < Test::Unit::TestCase
end
should 'find communities in a specified category' do
- c = Category.create!(:name => 'my category', :environment => Environment.default)
c1 = Community.create!(:name => 'a beautiful community', :identifier => 'bea_comm', :environment => Environment.default)
c2 = Community.create!(:name => 'another beautiful community', :identifier => 'an_bea_comm', :environment => Environment.default)
- c1.categories << c; c1.save!
+ c1.categories << @category; c1.save!
get :index, :category_path => [ 'my-category' ], :query => 'beautiful', :find_in => [ 'communities' ]
assert_includes assigns(:results)[:communities], c1
assert_not_includes assigns(:results)[:communities], c2
@@ -169,8 +166,7 @@ class SearchControllerTest < Test::Unit::TestCase
end
should 'find products in a specific category' do
- c = Category.create!(:name => 'my category', :environment => Environment.default)
- ent1 = Enterprise.create!(:name => 'teste1', :identifier => 'teste1'); ent1.categories << c
+ ent1 = Enterprise.create!(:name => 'teste1', :identifier => 'teste1'); ent1.categories << @category
ent2 = Enterprise.create!(:name => 'teste2', :identifier => 'teste2')
prod1 = ent1.products.create!(:name => 'a beautiful product')
prod2 = ent2.products.create!(:name => 'another beautiful product')
@@ -261,4 +257,49 @@ class SearchControllerTest < Test::Unit::TestCase
assert_tag :tag => 'form' , :attributes => { :method => 'get' }
end
+ def test_should_display_a_given_category
+ get :category_index, :category_path => [ 'my-category' ]
+ assert_equal @category, assigns(:category)
+ end
+
+ should 'expose category in a method' do
+ get :category_index, :category_path => [ 'my-category' ]
+ assert_same assigns(:category), @controller.category
+ end
+
+ should 'list recent articles in the category' do
+ @controller.expects(:category).returns(@category).at_least_once
+ recent = []
+ @category.expects(:recent_articles).returns(recent)
+
+ get :category_index, :category_path => [ 'my-category' ]
+ assert_same recent, assigns(:recent_articles)
+ end
+
+ should 'list recent comments in the category' do
+ @controller.expects(:category).returns(@category).at_least_once
+ recent = []
+ @category.expects(:recent_comments).returns(recent)
+
+ get :category_index, :category_path => [ 'my-category' ]
+ assert_same recent, assigns(:recent_comments)
+ end
+
+ should 'list most commented articles in the category' do
+ @controller.expects(:category).returns(@category).at_least_once
+ most_commented = []
+ @category.expects(:most_commented_articles).returns(most_commented)
+
+ get :category_index, :category_path => [ 'my-category' ]
+ assert_same most_commented, assigns(: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
+ end
+
end
diff --git a/test/integration/routing_test.rb b/test/integration/routing_test.rb
index d31be90..70aa7d6 100644
--- a/test/integration/routing_test.rb
+++ b/test/integration/routing_test.rb
@@ -69,8 +69,7 @@ class RoutingTest < ActionController::IntegrationTest
end
def test_category_browser
- assert_routing('/cat/products/eletronics', :controller => 'category', :action => 'view', :category_path => [ 'products', 'eletronics'])
- assert_routing('/cat', :controller => 'category', :action => 'index')
+ assert_routing('/cat/products/eletronics', :controller => 'search', :action => 'category_index', :category_path => [ 'products', 'eletronics'])
end
#FIXME remove this if design_blocks is not going to be used; or uncomment otherwise;
@@ -99,4 +98,8 @@ class RoutingTest < ActionController::IntegrationTest
assert_routing('/search/filter/a/b', :controller => 'search', :action => 'filter', :category_path => ['a','b'])
end
+ def test_assets_routing
+ assert_routing('/assets/my-asset/a/b/c', :controller => 'search', :action => 'assets', :asset => 'my-asset', :category_path => ['a', 'b', 'c'])
+ end
+
end
diff --git a/test/unit/application_helper_test.rb b/test/unit/application_helper_test.rb
index 26cee55..542098f 100644
--- a/test/unit/application_helper_test.rb
+++ b/test/unit/application_helper_test.rb
@@ -67,7 +67,7 @@ class ApplicationHelperTest < Test::Unit::TestCase
cat.expects(:full_name).returns('category name')
result = "/cat/my-category/my-subcatagory"
- expects(:link_to).with('category name', :controller => 'category', :action => 'view', :category_path => ['my-category', 'my-subcatagory']).returns(result)
+ expects(:link_to).with('category name', :controller => 'search', :action => 'category_index', :category_path => ['my-category', 'my-subcatagory']).returns(result)
assert_same result, link_to_category(cat)
end
--
libgit2 0.21.2