Commit 5534d8f9f9fc297da0744bb30657cdda7580720c

Authored by Leandro Santos
Committed by Antonio Terceiro
1 parent b620c41c

It was impossible to manage the enterprise products when if It has a lot of products registered.

Now the management is paginated.
app/controllers/my_profile/manage_products_controller.rb
@@ -17,7 +17,7 @@ class ManageProductsController < ApplicationController @@ -17,7 +17,7 @@ class ManageProductsController < ApplicationController
17 public 17 public
18 18
19 def index 19 def index
20 - @products = @profile.products 20 + @products = @profile.products.paginate(:per_page => 10, :page => params[:page])
21 end 21 end
22 22
23 def show 23 def show
app/views/manage_products/index.rhtml
@@ -22,6 +22,8 @@ @@ -22,6 +22,8 @@
22 <% end %> 22 <% end %>
23 </table> 23 </table>
24 24
  25 +<%= will_paginate @products %>
  26 +
25 <% button_bar do %> 27 <% button_bar do %>
26 <%= button :add, _('New product or service'), :action => 'new' %> 28 <%= button :add, _('New product or service'), :action => 'new' %>
27 <%= button :back, _('Back'), { :controller => 'profile_editor', :profile => @profile.identifier, :action => 'index' } %> 29 <%= button :back, _('Back'), { :controller => 'profile_editor', :profile => @profile.identifier, :action => 'index' } %>
test/functional/manage_products_controller_test.rb
@@ -305,4 +305,25 @@ class ManageProductsControllerTest &lt; Test::Unit::TestCase @@ -305,4 +305,25 @@ class ManageProductsControllerTest &lt; Test::Unit::TestCase
305 :descendant => {:tag => 'a', :attributes => { :id => 'edit-product-button-ui-inputs' }, :content => 'Add the inputs used by this product'} 305 :descendant => {:tag => 'a', :attributes => { :id => 'edit-product-button-ui-inputs' }, :content => 'Add the inputs used by this product'}
306 end 306 end
307 307
  308 + should 'not list all the products of enterprise' do
  309 + @enterprise.products = []
  310 + 1.upto(12) do |n|
  311 + fast_create(Product, :name => "test product_#{n}", :enterprise_id => @enterprise.id, :product_category_id => @product_category.id)
  312 + end
  313 + get :index, :profile => @enterprise.identifier
  314 + assert_equal 10, assigns(:products).count
  315 + end
  316 +
  317 + should 'paginate the manage products list of enterprise' do
  318 + @enterprise.products = []
  319 + 1.upto(12) do |n|
  320 + fast_create(Product, :name => "test product_#{n}", :enterprise_id => @enterprise.id, :product_category_id => @product_category.id)
  321 + end
  322 + get :index, :profile => @enterprise.identifier
  323 + assert_tag :tag => 'a', :attributes => { :rel => 'next', :href => "/myprofile/#{@enterprise.identifier}/manage_products?page=2" }
  324 +
  325 + get :index, :profile => @enterprise.identifier, :page => 2
  326 + assert_equal 2, assigns(:products).count
  327 + end
  328 +
308 end 329 end