diff --git a/app/controllers/public/catalog_controller.rb b/app/controllers/public/catalog_controller.rb index 1620001..2dcd7b0 100644 --- a/app/controllers/public/catalog_controller.rb +++ b/app/controllers/public/catalog_controller.rb @@ -4,7 +4,7 @@ class CatalogController < PublicController before_filter :check_enterprise_and_environment def index - @products = @profile.products + @products = @profile.products.paginate(:per_page => 10, :page => params[:page]) end protected diff --git a/app/views/catalog/index.rhtml b/app/views/catalog/index.rhtml index 20db5d1..269ec26 100644 --- a/app/views/catalog/index.rhtml +++ b/app/views/catalog/index.rhtml @@ -1 +1,3 @@ <%= display_products_list @profile, @products %> + +<%= will_paginate @products %> diff --git a/features/manage_products.feature b/features/manage_products.feature index 806cecc..4942dcb 100644 --- a/features/manage_products.feature +++ b/features/manage_products.feature @@ -11,6 +11,38 @@ Feature: manage products | redemoinho | joaosilva | Rede Moinho | true | And feature "disable_products_for_enterprises" is disabled on environment + Scenario: paginate public listing products and services + Given the following product_category + | name | + | Bicycle | + And the following products + | owner | category | name | description | + | redemoinho | bicycle | Bike 1 | bicycle 1 | + | redemoinho | bicycle | Bike 2 | bicycle 2 | + | redemoinho | bicycle | Bike 3 | bicycle 3 | + | redemoinho | bicycle | Bike 4 | bicycle 4 | + | redemoinho | bicycle | Bike 5 | bicycle 5 | + | redemoinho | bicycle | Bike 6 | bicycle 6 | + | redemoinho | bicycle | Bike 7 | bicycle 7 | + | redemoinho | bicycle | Bike 8 | bicycle 8 | + | redemoinho | bicycle | Bike 9 | bicycle 9 | + | redemoinho | bicycle | Bike 10| bicycle 10 | + | redemoinho | bicycle | Bike 11| bicycle 11 | + When I go to /catalog/redemoinho + Then I should see "Bike 1" + And I should see "Bike 2" + And I should see "Bike 3" + And I should see "Bike 4" + And I should see "Bike 5" + And I should see "Bike 6" + And I should see "Bike 7" + And I should see "Bike 8" + And I should see "Bike 9" + And I should see "Bike 10" + And I should not see "Bike 11" + When I follow "Next" + Then I should see "Bike 11" + Scenario: listing products and services Given I am logged in as "joaosilva" And I am on Rede Moinho's control panel diff --git a/test/functional/catalog_controller_test.rb b/test/functional/catalog_controller_test.rb index c39b622..d8730f1 100644 --- a/test/functional/catalog_controller_test.rb +++ b/test/functional/catalog_controller_test.rb @@ -39,6 +39,17 @@ class CatalogControllerTest < Test::Unit::TestCase assert_kind_of Array, assigns(:products) end + should 'paginate enterprise products list' do + 1.upto(12).map do + fast_create(Product, :enterprise_id => @enterprise.id) + end + + assert_equal 12, @enterprise.products.count + get :index, :profile => @enterprise.identifier + assert_equal 10, assigns(:products).count + assert_tag :a, :attributes => {:class => 'next_page'} + end + should 'not give access if environment do not let' do env = Environment.default env.enable('disable_products_for_enterprises') -- libgit2 0.21.2