diff --git a/app/controllers/public/catalog_controller.rb b/app/controllers/public/catalog_controller.rb
index 569bd73..8cdb825 100644
--- a/app/controllers/public/catalog_controller.rb
+++ b/app/controllers/public/catalog_controller.rb
@@ -12,7 +12,9 @@ class CatalogController < ApplicationController
protected
def check_enterprise
- @profile.kind_of? Enterprise
+ unless @profile.kind_of? Enterprise
+ redirect_to :controller => 'profile', :profile => profile.identifier, :action => 'index'
+ end
end
end
diff --git a/app/views/blocks/profile_info.rhtml b/app/views/blocks/profile_info.rhtml
index adea1b3..5b0eeca 100644
--- a/app/views/blocks/profile_info.rhtml
+++ b/app/views/blocks/profile_info.rhtml
@@ -6,6 +6,7 @@
<%= _('Since %{year}/%{month}') % { :year => block.owner.created_at.year, :month => block.owner.created_at.month } %>
<%= link_to _('Homepage'), block.owner.url %>
<%= link_to _('View profile'), block.owner.public_profile_url %>
+ <%= link_to(_('Products/Services'), :controller => 'catalog', :profile => block.owner.identifier) if block.owner.enterprise? %>
<% if !user.nil? and user.has_permission?('edit_profile', profile) %>
<%= link_to _('Control panel'), :controller => 'profile_editor' %>
<% end %>
diff --git a/app/views/catalog/index.rhtml b/app/views/catalog/index.rhtml
index d71e7ef..0a795a3 100644
--- a/app/views/catalog/index.rhtml
+++ b/app/views/catalog/index.rhtml
@@ -1,11 +1,15 @@
- <%= _('Catalog') %>
+ <%= _('%s:Products/Services') % @profile.name %>
-
+
+
+ <%= _('Product/Service') %> |
+ <%= _('Price') %> |
+
<% @products.each do |p| %>
- -
- <%= link_to p.name, :action => 'show', :id => p %>
- <%= image_tag p.image.public_filename if p.image %>
- <%= p.price %>
-
+
+ <%= image_tag p.image.public_filename if p.image %> |
+ <%= link_to p.name, :action => 'show', :id => p %> |
+ <%= p.price || content_tag('em', _('not informed')) %>
+ |
<% end %>
-
+
diff --git a/app/views/catalog/show.rhtml b/app/views/catalog/show.rhtml
index fcfc583..a129c99 100644
--- a/app/views/catalog/show.rhtml
+++ b/app/views/catalog/show.rhtml
@@ -1,8 +1,30 @@
- <%= @product.name %>
+ <%= @product.name %>
-<%= image_tag @product.image.public_filename if @product.image %>
-<%= @product.price %>
-<%= @product.description %>
+
+
+
+ <%= image_tag @product.image.public_filename, :style => 'float: left;' if @product.image %>
+ |
+
+ <%= @product.description %>
+ |
+
+
+
+
+ -
+ <%= _('Price:') %><%= @product.price || _('not informed') %>
+
+ -
+ <%= _('Category: %s ') % link_to_category(@product.product_category) %>
+
+
+ |
+
+
-<%= _('Category: %s ') % link_to_category(@product.product_category) %>
+
+<% button_bar do %>
+ <%= button :back, _('View products/services listing'), :action => 'index', :id => nil %>
+<% end %>
diff --git a/app/views/profile/index.rhtml b/app/views/profile/index.rhtml
index 9f85426..82f8587 100644
--- a/app/views/profile/index.rhtml
+++ b/app/views/profile/index.rhtml
@@ -25,6 +25,9 @@
<% if profile.kind_of? Organization %>
- <%= link_to _('Members'), :action => 'members' %>
<% end %>
+ <% if profile.kind_of? Enterprise %>
+ - <%= link_to _('Products/Services'), :controller => 'catalog', :action => 'index' %>
+ <% end %>
-
<%= _('Tags:') %>
diff --git a/config/routes.rb b/config/routes.rb
index f0d62c6..d852947 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -41,6 +41,10 @@ ActionController::Routing::Routes.draw do |map|
# public profile information
map.profile 'profile/:profile/:action/:id', :controller => 'profile', :action => 'index', :id => /.*/, :profile => /[a-z][a-z0-9._-]*/
+ # catalog
+ map.catalog 'catalog/:profile', :controller => 'catalog', :action => 'index'
+ map.product 'catalog/:profile/:id', :controller => 'catalog', :action => 'show'
+
######################################################
## Controllers that are profile-specific (for profile admins )
######################################################
@@ -69,10 +73,7 @@ ActionController::Routing::Routes.draw do |map|
## Test controllers.
## FIXME: this should not be needed
######################################################
- map.connect 'test/:controller/:action/:id' , :controller => /.*test.*/
-
- map.connect ':profile/catalog/:action/:id', :controller => 'catalog'
-
+ map.connect 'test/:controller/:action/:id' , :controller => /.*test.*/
# *content viewing*
# XXX this route must come last so other routes have priority over it.
diff --git a/script/anhetegua b/script/anhetegua
index 5fdbd42..2aca233 100755
--- a/script/anhetegua
+++ b/script/anhetegua
@@ -147,13 +147,6 @@ colivre = new_validator(ba, "Colivre", 'colivre', Enterprise)
# Role for own things
owner_role = Profile::Roles.admin
-# root user of the system, admin_role for him, the assignment of the role for him and the ownership of the system homepage
-root = User.create!(:login => 'root', :email => 'root@noosfero.org', :password => 'root', :password_confirmation => 'root').person
-admin_role = Environment::Roles.admin
-
-RoleAssignment.create!(:accessor => root, :role => admin_role, :resource => Environment.default)
-RoleAssignment.create!(:accessor => root, :role => owner_role, :resource => Environment.default)
-
# Sample user and sample enterprise owned by him
ze = User.create!(:login => 'ze', :email => 'ze@localhost.localdomain', :password => 'test', :password_confirmation => 'test').person
empa = Enterprise.create!(:name => 'Cooperativa A', :identifier => 'coop_a')
diff --git a/test/functional/catalog_controller_test.rb b/test/functional/catalog_controller_test.rb
index b8ab996..2f9d596 100644
--- a/test/functional/catalog_controller_test.rb
+++ b/test/functional/catalog_controller_test.rb
@@ -9,6 +9,8 @@ class CatalogControllerTest < Test::Unit::TestCase
@controller = CatalogController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
+
+ @enterprise = Enterprise.create!(:name => 'My enterprise', :identifier => 'testent')
end
def test_local_files_reference
@@ -19,18 +21,48 @@ class CatalogControllerTest < Test::Unit::TestCase
def test_valid_xhtml
assert_valid_xhtml
end
+
+ should 'not display for non-enterprises' do
+ u = create_user('testinguser').person
+ get :index, :profile => 'testinguser'
+ assert_redirected_to :controller => "profile", :profile => 'testinguser'
+ end
+
+ should 'display for enterprises' do
+ get :index, :profile => 'testent'
+ assert_response :success
+ end
should 'list products of enterprise' do
ent = Enterprise.create!(:identifier => 'test_enterprise1', :name => 'Test enteprise1')
get :index, :profile => ent.identifier
- assert_tag :tag => 'h2', :content => /Catalog/
+ assert_kind_of Array, assigns(:products)
end
should 'show product of enterprise' do
ent = Enterprise.create!(:identifier => 'test_enterprise1', :name => 'Test enteprise1')
prod = ent.products.create!(:name => 'Product test')
get :show, :id => prod.id, :profile => ent.identifier
- assert_tag :tag => 'h2', :content => /#{prod.name}/
+ assert_tag :tag => 'h1', :content => /#{prod.name}/
+ end
+
+ should 'link back to index from product show' do
+ ent = Enterprise.create!(:identifier => 'test_enterprise1', :name => 'Test enteprise1')
+ prod = ent.products.create!(:name => 'Product test')
+ get :show, :id => prod.id, :profile => ent.identifier
+ assert_tag({
+ :tag => 'div',
+ :attributes => {
+ :class => /main-block/
+ },
+ :descendant => {
+ :tag => 'a',
+ :attributes => {
+ :href => '/catalog/test_enterprise1'
+ }
+ }
+ })
+
end
end
diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb
index 12f6da5..0912505 100644
--- a/test/functional/profile_controller_test.rb
+++ b/test/functional/profile_controller_test.rb
@@ -220,4 +220,16 @@ class ProfileControllerTest < Test::Unit::TestCase
assert_tag :tag => 'div', :attributes => { :id => 'profile-disabled' }, :content => Environment.default.message_for_disabled_enterprise
end
+ should 'display "Products" link for enterprise' do
+ ent = Enterprise.create!(:name => 'my test enterprise', :identifier => 'my-test-enterprise', :enabled => false)
+
+ get :index, :profile => 'my-test-enterprise'
+ assert_tag :tag => 'a', :attributes => { :href => '/catalog/my-test-enterprise'}, :content => /Products\/Services/
+ end
+
+ should 'not display "Products" link for people' do
+ get :index, :profile => 'ze'
+ assert_no_tag :tag => 'a', :attributes => { :href => '/catalog/my-test-enterprise'}, :content => /Products\/Services/
+ end
+
end
diff --git a/test/integration/routing_test.rb b/test/integration/routing_test.rb
index cd2b0dc..eaf8d49 100644
--- a/test/integration/routing_test.rb
+++ b/test/integration/routing_test.rb
@@ -139,4 +139,9 @@ class RoutingTest < ActionController::IntegrationTest
assert_routing('/ze_with_underscore', :controller => 'content_viewer', :action => 'view_page', :profile => 'ze_with_underscore', :page => [])
end
+ def test_catalog_routing
+ assert_routing('/catalog/colivre', :controller => 'catalog', :action => 'index', :profile => 'colivre')
+ assert_routing('/catalog/colivre/1234', :controller => 'catalog', :action => 'show', :profile => 'colivre', :id => '1234')
+ end
+
end
diff --git a/test/test_helper.rb b/test/test_helper.rb
index 4455efa..699bdc6 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -63,7 +63,7 @@ class Test::Unit::TestCase
end
def create_admin_user(env)
- admin_user = User.find_by_login('root_user') || User.create!(:login => 'root_user', :email => 'root@noosfero.org', :password => 'root', :password_confirmation => 'root')
+ admin_user = User.find_by_login('adminuser') || User.create!(:login => 'adminuser', :email => 'adminuser@noosfero.org', :password => 'adminuser', :password_confirmation => 'adminuser')
admin_role = Role.find_by_name('admin_role') || Role.create!(:name => 'admin_role', :permissions => ['view_environment_admin_panel','edit_environment_features', 'edit_environment_design', 'manage_environment_categories', 'manage_environment_roles', 'manage_environment_validators'])
RoleAssignment.create!(:accessor => admin_user.person, :role => admin_role, :resource => env) unless admin_user.person.role_assignments.map{|ra|[ra.role, ra.accessor, ra.resource]}.include?([admin_role, admin_user, env])
admin_user.login
--
libgit2 0.21.2