Commit 1195da20b6313966ce016b3d48d24c0c7acbb012

Authored by AntonioTerceiro
1 parent de79cb02

ActionItem440: displaying list of products


git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2036 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/public/catalog_controller.rb
... ... @@ -12,7 +12,9 @@ class CatalogController < ApplicationController
12 12  
13 13 protected
14 14 def check_enterprise
15   - @profile.kind_of? Enterprise
  15 + unless @profile.kind_of? Enterprise
  16 + redirect_to :controller => 'profile', :profile => profile.identifier, :action => 'index'
  17 + end
16 18 end
17 19  
18 20 end
... ...
app/views/blocks/profile_info.rhtml
... ... @@ -6,6 +6,7 @@
6 6 <li><%= _('Since %{year}/%{month}') % { :year => block.owner.created_at.year, :month => block.owner.created_at.month } %></li>
7 7 <li><%= link_to _('Homepage'), block.owner.url %></li>
8 8 <li><%= link_to _('View profile'), block.owner.public_profile_url %></li>
  9 + <li><%= link_to(_('Products/Services'), :controller => 'catalog', :profile => block.owner.identifier) if block.owner.enterprise? %></li>
9 10 <% if !user.nil? and user.has_permission?('edit_profile', profile) %>
10 11 <li><%= link_to _('Control panel'), :controller => 'profile_editor' %></li>
11 12 <% end %>
... ...
app/views/catalog/index.rhtml
1   -<h2> <%= _('Catalog') %> </h2>
  1 +<h1> <%= _('%s:Products/Services') % @profile.name %> </h1>
2 2  
3   -<ul>
  3 +<table align='center'>
  4 + <tr>
  5 + <th colspan="2"><%= _('Product/Service') %></th>
  6 + <th><%= _('Price') %></th>
  7 + </tr>
4 8 <% @products.each do |p| %>
5   - <li>
6   - <%= link_to p.name, :action => 'show', :id => p %> <br/>
7   - <%= image_tag p.image.public_filename if p.image %> <br/>
8   - <%= p.price %> <br/><br/>
9   - </li>
  9 + <tr>
  10 + <td> <%= image_tag p.image.public_filename if p.image %> </td>
  11 + <td> <%= link_to p.name, :action => 'show', :id => p %> </td>
  12 + <td> <%= p.price || content_tag('em', _('not informed')) %> </th>
  13 + </tr>
10 14 <% end %>
11   -</ul>
  15 +</table>
... ...
app/views/catalog/show.rhtml
1   -<h2> <%= @product.name %> </h2>
  1 +<h1> <%= @product.name %> </h1>
2 2  
3   -<%= image_tag @product.image.public_filename if @product.image %> <br/>
4   -<%= @product.price %> <br/>
5   -<%= @product.description %> <br/>
  3 +<table>
  4 + <tr>
  5 + <td>
  6 + <%= image_tag @product.image.public_filename, :style => 'float: left;' if @product.image %>
  7 + </td>
  8 + <td>
  9 + <%= @product.description %>
  10 + </td>
  11 + </tr>
  12 + <tr>
  13 + <td colspan="2">
  14 + <ul>
  15 + <li>
  16 + <strong><%= _('Price:') %></strong><%= @product.price || _('not informed') %>
  17 + </li>
  18 + <li>
  19 + <%= _('Category: %s ') % link_to_category(@product.product_category) %> <br/>
  20 + </li>
  21 + </ul>
  22 + </td>
  23 + </tr>
  24 +</table>
6 25  
7 26  
8   -<%= _('Category: %s ') % link_to_category(@product.product_category) %> <br/>
  27 +
  28 +<% button_bar do %>
  29 + <%= button :back, _('View products/services listing'), :action => 'index', :id => nil %>
  30 +<% end %>
... ...
app/views/profile/index.rhtml
... ... @@ -25,6 +25,9 @@
25 25 <% if profile.kind_of? Organization %>
26 26 <li><%= link_to _('Members'), :action => 'members' %></li>
27 27 <% end %>
  28 + <% if profile.kind_of? Enterprise %>
  29 + <li><%= link_to _('Products/Services'), :controller => 'catalog', :action => 'index' %></li>
  30 + <% end %>
28 31  
29 32 <li>
30 33 <%= _('Tags:') %>
... ...
config/routes.rb
... ... @@ -41,6 +41,10 @@ ActionController::Routing::Routes.draw do |map|
41 41 # public profile information
42 42 map.profile 'profile/:profile/:action/:id', :controller => 'profile', :action => 'index', :id => /.*/, :profile => /[a-z][a-z0-9._-]*/
43 43  
  44 + # catalog
  45 + map.catalog 'catalog/:profile', :controller => 'catalog', :action => 'index'
  46 + map.product 'catalog/:profile/:id', :controller => 'catalog', :action => 'show'
  47 +
44 48 ######################################################
45 49 ## Controllers that are profile-specific (for profile admins )
46 50 ######################################################
... ... @@ -69,10 +73,7 @@ ActionController::Routing::Routes.draw do |map|
69 73 ## Test controllers.
70 74 ## FIXME: this should not be needed
71 75 ######################################################
72   - map.connect 'test/:controller/:action/:id' , :controller => /.*test.*/
73   -
74   - map.connect ':profile/catalog/:action/:id', :controller => 'catalog'
75   -
  76 + map.connect 'test/:controller/:action/:id' , :controller => /.*test.*/
76 77  
77 78 # *content viewing*
78 79 # XXX this route must come last so other routes have priority over it.
... ...
script/anhetegua
... ... @@ -147,13 +147,6 @@ colivre = new_validator(ba, &quot;Colivre&quot;, &#39;colivre&#39;, Enterprise)
147 147 # Role for own things
148 148 owner_role = Profile::Roles.admin
149 149  
150   -# root user of the system, admin_role for him, the assignment of the role for him and the ownership of the system homepage
151   -root = User.create!(:login => 'root', :email => 'root@noosfero.org', :password => 'root', :password_confirmation => 'root').person
152   -admin_role = Environment::Roles.admin
153   -
154   -RoleAssignment.create!(:accessor => root, :role => admin_role, :resource => Environment.default)
155   -RoleAssignment.create!(:accessor => root, :role => owner_role, :resource => Environment.default)
156   -
157 150 # Sample user and sample enterprise owned by him
158 151 ze = User.create!(:login => 'ze', :email => 'ze@localhost.localdomain', :password => 'test', :password_confirmation => 'test').person
159 152 empa = Enterprise.create!(:name => 'Cooperativa A', :identifier => 'coop_a')
... ...
test/functional/catalog_controller_test.rb
... ... @@ -9,6 +9,8 @@ class CatalogControllerTest &lt; Test::Unit::TestCase
9 9 @controller = CatalogController.new
10 10 @request = ActionController::TestRequest.new
11 11 @response = ActionController::TestResponse.new
  12 +
  13 + @enterprise = Enterprise.create!(:name => 'My enterprise', :identifier => 'testent')
12 14 end
13 15  
14 16 def test_local_files_reference
... ... @@ -19,18 +21,48 @@ class CatalogControllerTest &lt; Test::Unit::TestCase
19 21 def test_valid_xhtml
20 22 assert_valid_xhtml
21 23 end
  24 +
  25 + should 'not display for non-enterprises' do
  26 + u = create_user('testinguser').person
  27 + get :index, :profile => 'testinguser'
  28 + assert_redirected_to :controller => "profile", :profile => 'testinguser'
  29 + end
  30 +
  31 + should 'display for enterprises' do
  32 + get :index, :profile => 'testent'
  33 + assert_response :success
  34 + end
22 35  
23 36 should 'list products of enterprise' do
24 37 ent = Enterprise.create!(:identifier => 'test_enterprise1', :name => 'Test enteprise1')
25 38 get :index, :profile => ent.identifier
26   - assert_tag :tag => 'h2', :content => /Catalog/
  39 + assert_kind_of Array, assigns(:products)
27 40 end
28 41  
29 42 should 'show product of enterprise' do
30 43 ent = Enterprise.create!(:identifier => 'test_enterprise1', :name => 'Test enteprise1')
31 44 prod = ent.products.create!(:name => 'Product test')
32 45 get :show, :id => prod.id, :profile => ent.identifier
33   - assert_tag :tag => 'h2', :content => /#{prod.name}/
  46 + assert_tag :tag => 'h1', :content => /#{prod.name}/
  47 + end
  48 +
  49 + should 'link back to index from product show' do
  50 + ent = Enterprise.create!(:identifier => 'test_enterprise1', :name => 'Test enteprise1')
  51 + prod = ent.products.create!(:name => 'Product test')
  52 + get :show, :id => prod.id, :profile => ent.identifier
  53 + assert_tag({
  54 + :tag => 'div',
  55 + :attributes => {
  56 + :class => /main-block/
  57 + },
  58 + :descendant => {
  59 + :tag => 'a',
  60 + :attributes => {
  61 + :href => '/catalog/test_enterprise1'
  62 + }
  63 + }
  64 + })
  65 +
34 66 end
35 67  
36 68 end
... ...
test/functional/profile_controller_test.rb
... ... @@ -220,4 +220,16 @@ class ProfileControllerTest &lt; Test::Unit::TestCase
220 220 assert_tag :tag => 'div', :attributes => { :id => 'profile-disabled' }, :content => Environment.default.message_for_disabled_enterprise
221 221 end
222 222  
  223 + should 'display "Products" link for enterprise' do
  224 + ent = Enterprise.create!(:name => 'my test enterprise', :identifier => 'my-test-enterprise', :enabled => false)
  225 +
  226 + get :index, :profile => 'my-test-enterprise'
  227 + assert_tag :tag => 'a', :attributes => { :href => '/catalog/my-test-enterprise'}, :content => /Products\/Services/
  228 + end
  229 +
  230 + should 'not display "Products" link for people' do
  231 + get :index, :profile => 'ze'
  232 + assert_no_tag :tag => 'a', :attributes => { :href => '/catalog/my-test-enterprise'}, :content => /Products\/Services/
  233 + end
  234 +
223 235 end
... ...
test/integration/routing_test.rb
... ... @@ -139,4 +139,9 @@ class RoutingTest &lt; ActionController::IntegrationTest
139 139 assert_routing('/ze_with_underscore', :controller => 'content_viewer', :action => 'view_page', :profile => 'ze_with_underscore', :page => [])
140 140 end
141 141  
  142 + def test_catalog_routing
  143 + assert_routing('/catalog/colivre', :controller => 'catalog', :action => 'index', :profile => 'colivre')
  144 + assert_routing('/catalog/colivre/1234', :controller => 'catalog', :action => 'show', :profile => 'colivre', :id => '1234')
  145 + end
  146 +
142 147 end
... ...
test/test_helper.rb
... ... @@ -63,7 +63,7 @@ class Test::Unit::TestCase
63 63 end
64 64  
65 65 def create_admin_user(env)
66   - admin_user = User.find_by_login('root_user') || User.create!(:login => 'root_user', :email => 'root@noosfero.org', :password => 'root', :password_confirmation => 'root')
  66 + admin_user = User.find_by_login('adminuser') || User.create!(:login => 'adminuser', :email => 'adminuser@noosfero.org', :password => 'adminuser', :password_confirmation => 'adminuser')
67 67 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'])
68 68 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])
69 69 admin_user.login
... ...