From 8caf11c4903294b3fd5f21ce56a655621cb7338d Mon Sep 17 00:00:00 2001 From: Rodrigo Souto Date: Wed, 22 Jan 2014 20:20:34 +0000 Subject: [PATCH] product-categories-block: add 'catalog_only' option and define it as default --- app/models/product_categories_block.rb | 14 ++++++++++++-- test/unit/product_categories_block_test.rb | 19 +++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/app/models/product_categories_block.rb b/app/models/product_categories_block.rb index 47c2f61..c67a499 100644 --- a/app/models/product_categories_block.rb +++ b/app/models/product_categories_block.rb @@ -33,8 +33,18 @@ class ProductCategoriesBlock < Block end end - def visible?(context=nil) - box.environment.enabled?('products_for_enterprises') + DISPLAY_OPTIONS['catalog_only'] = __('Only on the catalog') + + def display + settings[:display].nil? ? 'catalog_only' : super + end + + def display_catalog_only(context) + context[:params][:controller] == 'catalog' + end + + def visible?(*args) + box.environment.enabled?('products_for_enterprises') ? super(*args) : false end end diff --git a/test/unit/product_categories_block_test.rb b/test/unit/product_categories_block_test.rb index 74382f0..8083806 100644 --- a/test/unit/product_categories_block_test.rb +++ b/test/unit/product_categories_block_test.rb @@ -13,4 +13,23 @@ class ProductCategoriesBlockTest < ActiveSupport::TestCase block.box.environment.disable('products_for_enterprises') assert !block.visible? end + + should 'have display option to show only on catalog' do + assert ProductCategoriesBlock::DISPLAY_OPTIONS.include?('catalog_only') + end + + should 'set display to catalog_only by default' do + assert_equal 'catalog_only', ProductCategoriesBlock.new.display + end + + should 'display block only on catalog if display is set to catalog_only' do + enterprise = fast_create(Enterprise) + box = fast_create(Box, :owner_id => enterprise.id, :owner_type => 'Profile') + block = ProductCategoriesBlock.new + block.box = box + block.box.environment.enable('products_for_enterprises') + + assert !block.visible?(:params => {:controller => 'any_other'}) + assert block.visible?(:params => {:controller => 'catalog'}) + end end -- libgit2 0.21.2