Commit 8caf11c4903294b3fd5f21ce56a655621cb7338d
1 parent
f7c88798
Exists in
master
and in
29 other branches
product-categories-block: add 'catalog_only' option and define it as default
Showing
2 changed files
with
31 additions
and
2 deletions
Show diff stats
app/models/product_categories_block.rb
... | ... | @@ -33,8 +33,18 @@ class ProductCategoriesBlock < Block |
33 | 33 | end |
34 | 34 | end |
35 | 35 | |
36 | - def visible?(context=nil) | |
37 | - box.environment.enabled?('products_for_enterprises') | |
36 | + DISPLAY_OPTIONS['catalog_only'] = __('Only on the catalog') | |
37 | + | |
38 | + def display | |
39 | + settings[:display].nil? ? 'catalog_only' : super | |
40 | + end | |
41 | + | |
42 | + def display_catalog_only(context) | |
43 | + context[:params][:controller] == 'catalog' | |
44 | + end | |
45 | + | |
46 | + def visible?(*args) | |
47 | + box.environment.enabled?('products_for_enterprises') ? super(*args) : false | |
38 | 48 | end |
39 | 49 | |
40 | 50 | end | ... | ... |
test/unit/product_categories_block_test.rb
... | ... | @@ -13,4 +13,23 @@ class ProductCategoriesBlockTest < ActiveSupport::TestCase |
13 | 13 | block.box.environment.disable('products_for_enterprises') |
14 | 14 | assert !block.visible? |
15 | 15 | end |
16 | + | |
17 | + should 'have display option to show only on catalog' do | |
18 | + assert ProductCategoriesBlock::DISPLAY_OPTIONS.include?('catalog_only') | |
19 | + end | |
20 | + | |
21 | + should 'set display to catalog_only by default' do | |
22 | + assert_equal 'catalog_only', ProductCategoriesBlock.new.display | |
23 | + end | |
24 | + | |
25 | + should 'display block only on catalog if display is set to catalog_only' do | |
26 | + enterprise = fast_create(Enterprise) | |
27 | + box = fast_create(Box, :owner_id => enterprise.id, :owner_type => 'Profile') | |
28 | + block = ProductCategoriesBlock.new | |
29 | + block.box = box | |
30 | + block.box.environment.enable('products_for_enterprises') | |
31 | + | |
32 | + assert !block.visible?(:params => {:controller => 'any_other'}) | |
33 | + assert block.visible?(:params => {:controller => 'catalog'}) | |
34 | + end | |
16 | 35 | end | ... | ... |