From 4199280abd7e6dd5c6f11f0926a017e1a619dce5 Mon Sep 17 00:00:00 2001 From: Rafael Reggiani Manzo Date: Thu, 10 Mar 2016 10:17:58 -0300 Subject: [PATCH] Refactor ProductsBlock footer into helper/view --- app/models/products_block.rb | 4 ---- app/views/blocks/footers/products.html.erb | 1 + test/unit/products_block_test.rb | 52 +++++++++++++++++++++++++--------------------------- 3 files changed, 26 insertions(+), 31 deletions(-) create mode 100644 app/views/blocks/footers/products.html.erb diff --git a/app/models/products_block.rb b/app/models/products_block.rb index d54dc29..bb80037 100644 --- a/app/models/products_block.rb +++ b/app/models/products_block.rb @@ -19,10 +19,6 @@ class ProductsBlock < Block _('This block presents a list of your products.') end - def footer - link_to(_('View all products'), owner.public_profile_url.merge(:controller => 'catalog', :action => 'index')) - end - settings_items :product_ids, type: Array def product_ids=(array) self.settings[:product_ids] = array diff --git a/app/views/blocks/footers/products.html.erb b/app/views/blocks/footers/products.html.erb new file mode 100644 index 0000000..5fa18ff --- /dev/null +++ b/app/views/blocks/footers/products.html.erb @@ -0,0 +1 @@ +<%= link_to(_('View all products'), block.owner.public_profile_url.merge(:controller => 'catalog', :action => 'index')) %> diff --git a/test/unit/products_block_test.rb b/test/unit/products_block_test.rb index 44c28b5..c3825c5 100644 --- a/test/unit/products_block_test.rb +++ b/test/unit/products_block_test.rb @@ -20,18 +20,6 @@ class ProductsBlockTest < ActiveSupport::TestCase assert_not_equal Block.description, ProductsBlock.description end - should 'point to all products in footer' do - enterprise = create(Enterprise, :name => 'testenterprise', :identifier => 'testenterprise') - create(Product, :enterprise => enterprise, :name => 'product one', :product_category => @product_category) - create(Product, :enterprise => enterprise, :name => 'product two', :product_category => @product_category) - - block.stubs(:owner).returns(enterprise) - - footer = block.footer - - assert_tag_in_string footer, :tag => 'a', :attributes => { :href => /\/catalog\/testenterprise$/ }, :content => 'View all products' - end - should 'list 4 random products by default' do enterprise = create(Enterprise, :name => 'testenterprise', :identifier => 'testenterprise') create(Product, :enterprise => enterprise, :name => 'product one', :product_category => @product_category) @@ -105,21 +93,6 @@ class ProductsBlockTest < ActiveSupport::TestCase assert_equivalent [p1, p2, p3, p4], block.products end end - - should 'generate footer when enterprise has own hostname' do - enterprise = create(Enterprise, :name => 'testenterprise', :identifier => 'testenterprise') - enterprise.domains << Domain.new(:name => 'sometest.com'); enterprise.save! - create(Product, :enterprise => enterprise, :name => 'product one', :product_category => @product_category) - create(Product, :enterprise => enterprise, :name => 'product two', :product_category => @product_category) - - block.stubs(:owner).returns(enterprise) - - footer = block.footer - - assert_tag_in_string footer, :tag => 'a', :attributes => { :href => /\/catalog\/testenterprise$/ }, :content => 'View all products' - end - - end require 'boxes_helper' @@ -174,4 +147,29 @@ class ProductsBlockViewTest < ActionView::TestCase content = render_block_content(block) assert_tag_in_string content, :tag => 'a', :attributes => { :style => /rails_minor.png/ } end + + should 'point to all products in footer' do + enterprise = create(Enterprise, :name => 'testenterprise', :identifier => 'testenterprise') + create(Product, :enterprise => enterprise, :name => 'product one', :product_category => @product_category) + create(Product, :enterprise => enterprise, :name => 'product two', :product_category => @product_category) + + block.stubs(:owner).returns(enterprise) + + footer = render_block_footer(block) + + assert_tag_in_string footer, :tag => 'a', :attributes => { :href => /\/catalog\/testenterprise$/ }, :content => 'View all products' + end + + should 'generate footer when enterprise has own hostname' do + enterprise = create(Enterprise, :name => 'testenterprise', :identifier => 'testenterprise') + enterprise.domains << Domain.new(:name => 'sometest.com'); enterprise.save! + create(Product, :enterprise => enterprise, :name => 'product one', :product_category => @product_category) + create(Product, :enterprise => enterprise, :name => 'product two', :product_category => @product_category) + + block.stubs(:owner).returns(enterprise) + + footer = render_block_footer(block) + + assert_tag_in_string footer, :tag => 'a', :attributes => { :href => /\/catalog\/testenterprise$/ }, :content => 'View all products' + end end -- libgit2 0.21.2