Commit f2e2654423d3e7f7bde342e97eecf8b68a8278ff
Committed by
Joenio Costa
1 parent
c3ee2732
Exists in
master
and in
29 other branches
The catalog show all the enterprise products. When the enterprise has a lot of p…
…roducts and the user access the catalog the system crash or works slowly. (ActionItem1595)
Showing
4 changed files
with
46 additions
and
1 deletions
Show diff stats
app/controllers/public/catalog_controller.rb
@@ -4,7 +4,7 @@ class CatalogController < PublicController | @@ -4,7 +4,7 @@ class CatalogController < PublicController | ||
4 | before_filter :check_enterprise_and_environment | 4 | before_filter :check_enterprise_and_environment |
5 | 5 | ||
6 | def index | 6 | def index |
7 | - @products = @profile.products | 7 | + @products = @profile.products.paginate(:per_page => 10, :page => params[:page]) |
8 | end | 8 | end |
9 | 9 | ||
10 | protected | 10 | protected |
app/views/catalog/index.rhtml
features/manage_products.feature
@@ -11,6 +11,38 @@ Feature: manage products | @@ -11,6 +11,38 @@ Feature: manage products | ||
11 | | redemoinho | joaosilva | Rede Moinho | true | | 11 | | redemoinho | joaosilva | Rede Moinho | true | |
12 | And feature "disable_products_for_enterprises" is disabled on environment | 12 | And feature "disable_products_for_enterprises" is disabled on environment |
13 | 13 | ||
14 | + Scenario: paginate public listing products and services | ||
15 | + Given the following product_category | ||
16 | + | name | | ||
17 | + | Bicycle | | ||
18 | + And the following products | ||
19 | + | owner | category | name | description | | ||
20 | + | redemoinho | bicycle | Bike 1 | bicycle 1 | | ||
21 | + | redemoinho | bicycle | Bike 2 | bicycle 2 | | ||
22 | + | redemoinho | bicycle | Bike 3 | bicycle 3 | | ||
23 | + | redemoinho | bicycle | Bike 4 | bicycle 4 | | ||
24 | + | redemoinho | bicycle | Bike 5 | bicycle 5 | | ||
25 | + | redemoinho | bicycle | Bike 6 | bicycle 6 | | ||
26 | + | redemoinho | bicycle | Bike 7 | bicycle 7 | | ||
27 | + | redemoinho | bicycle | Bike 8 | bicycle 8 | | ||
28 | + | redemoinho | bicycle | Bike 9 | bicycle 9 | | ||
29 | + | redemoinho | bicycle | Bike 10| bicycle 10 | | ||
30 | + | redemoinho | bicycle | Bike 11| bicycle 11 | | ||
31 | + When I go to /catalog/redemoinho | ||
32 | + Then I should see "Bike 1" | ||
33 | + And I should see "Bike 2" | ||
34 | + And I should see "Bike 3" | ||
35 | + And I should see "Bike 4" | ||
36 | + And I should see "Bike 5" | ||
37 | + And I should see "Bike 6" | ||
38 | + And I should see "Bike 7" | ||
39 | + And I should see "Bike 8" | ||
40 | + And I should see "Bike 9" | ||
41 | + And I should see "Bike 10" | ||
42 | + And I should not see "Bike 11" | ||
43 | + When I follow "Next" | ||
44 | + Then I should see "Bike 11" | ||
45 | + | ||
14 | Scenario: listing products and services | 46 | Scenario: listing products and services |
15 | Given I am logged in as "joaosilva" | 47 | Given I am logged in as "joaosilva" |
16 | And I am on Rede Moinho's control panel | 48 | And I am on Rede Moinho's control panel |
test/functional/catalog_controller_test.rb
@@ -39,6 +39,17 @@ class CatalogControllerTest < Test::Unit::TestCase | @@ -39,6 +39,17 @@ class CatalogControllerTest < Test::Unit::TestCase | ||
39 | assert_kind_of Array, assigns(:products) | 39 | assert_kind_of Array, assigns(:products) |
40 | end | 40 | end |
41 | 41 | ||
42 | + should 'paginate enterprise products list' do | ||
43 | + 1.upto(12).map do | ||
44 | + fast_create(Product, :enterprise_id => @enterprise.id) | ||
45 | + end | ||
46 | + | ||
47 | + assert_equal 12, @enterprise.products.count | ||
48 | + get :index, :profile => @enterprise.identifier | ||
49 | + assert_equal 10, assigns(:products).count | ||
50 | + assert_tag :a, :attributes => {:class => 'next_page'} | ||
51 | + end | ||
52 | + | ||
42 | should 'not give access if environment do not let' do | 53 | should 'not give access if environment do not let' do |
43 | env = Environment.default | 54 | env = Environment.default |
44 | env.enable('disable_products_for_enterprises') | 55 | env.enable('disable_products_for_enterprises') |