From 5534d8f9f9fc297da0744bb30657cdda7580720c Mon Sep 17 00:00:00 2001 From: Leandro Nunes dos Santos Date: Mon, 9 Aug 2010 17:55:09 -0300 Subject: [PATCH] It was impossible to manage the enterprise products when if It has a lot of products registered. --- app/controllers/my_profile/manage_products_controller.rb | 2 +- app/views/manage_products/index.rhtml | 2 ++ test/functional/manage_products_controller_test.rb | 21 +++++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/app/controllers/my_profile/manage_products_controller.rb b/app/controllers/my_profile/manage_products_controller.rb index 9e3a954..15d4632 100644 --- a/app/controllers/my_profile/manage_products_controller.rb +++ b/app/controllers/my_profile/manage_products_controller.rb @@ -17,7 +17,7 @@ class ManageProductsController < ApplicationController public def index - @products = @profile.products + @products = @profile.products.paginate(:per_page => 10, :page => params[:page]) end def show diff --git a/app/views/manage_products/index.rhtml b/app/views/manage_products/index.rhtml index b2770b5..3613810 100644 --- a/app/views/manage_products/index.rhtml +++ b/app/views/manage_products/index.rhtml @@ -22,6 +22,8 @@ <% end %> +<%= will_paginate @products %> + <% button_bar do %> <%= button :add, _('New product or service'), :action => 'new' %> <%= button :back, _('Back'), { :controller => 'profile_editor', :profile => @profile.identifier, :action => 'index' } %> diff --git a/test/functional/manage_products_controller_test.rb b/test/functional/manage_products_controller_test.rb index 4638f3c..3854cd3 100644 --- a/test/functional/manage_products_controller_test.rb +++ b/test/functional/manage_products_controller_test.rb @@ -305,4 +305,25 @@ class ManageProductsControllerTest < Test::Unit::TestCase :descendant => {:tag => 'a', :attributes => { :id => 'edit-product-button-ui-inputs' }, :content => 'Add the inputs used by this product'} end + should 'not list all the products of enterprise' do + @enterprise.products = [] + 1.upto(12) do |n| + fast_create(Product, :name => "test product_#{n}", :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) + end + get :index, :profile => @enterprise.identifier + assert_equal 10, assigns(:products).count + end + + should 'paginate the manage products list of enterprise' do + @enterprise.products = [] + 1.upto(12) do |n| + fast_create(Product, :name => "test product_#{n}", :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) + end + get :index, :profile => @enterprise.identifier + assert_tag :tag => 'a', :attributes => { :rel => 'next', :href => "/myprofile/#{@enterprise.identifier}/manage_products?page=2" } + + get :index, :profile => @enterprise.identifier, :page => 2 + assert_equal 2, assigns(:products).count + end + end -- libgit2 0.21.2