Commit 4199280abd7e6dd5c6f11f0926a017e1a619dce5

Authored by Rafael Reggiani Manzo
1 parent 8dfeff6c

Refactor ProductsBlock footer into helper/view

app/models/products_block.rb
@@ -19,10 +19,6 @@ class ProductsBlock < Block @@ -19,10 +19,6 @@ class ProductsBlock < Block
19 _('This block presents a list of your products.') 19 _('This block presents a list of your products.')
20 end 20 end
21 21
22 - def footer  
23 - link_to(_('View all products'), owner.public_profile_url.merge(:controller => 'catalog', :action => 'index'))  
24 - end  
25 -  
26 settings_items :product_ids, type: Array 22 settings_items :product_ids, type: Array
27 def product_ids=(array) 23 def product_ids=(array)
28 self.settings[:product_ids] = array 24 self.settings[:product_ids] = array
app/views/blocks/footers/products.html.erb 0 → 100644
@@ -0,0 +1 @@ @@ -0,0 +1 @@
  1 +<%= link_to(_('View all products'), block.owner.public_profile_url.merge(:controller => 'catalog', :action => 'index')) %>
test/unit/products_block_test.rb
@@ -20,18 +20,6 @@ class ProductsBlockTest &lt; ActiveSupport::TestCase @@ -20,18 +20,6 @@ class ProductsBlockTest &lt; ActiveSupport::TestCase
20 assert_not_equal Block.description, ProductsBlock.description 20 assert_not_equal Block.description, ProductsBlock.description
21 end 21 end
22 22
23 - should 'point to all products in footer' do  
24 - enterprise = create(Enterprise, :name => 'testenterprise', :identifier => 'testenterprise')  
25 - create(Product, :enterprise => enterprise, :name => 'product one', :product_category => @product_category)  
26 - create(Product, :enterprise => enterprise, :name => 'product two', :product_category => @product_category)  
27 -  
28 - block.stubs(:owner).returns(enterprise)  
29 -  
30 - footer = block.footer  
31 -  
32 - assert_tag_in_string footer, :tag => 'a', :attributes => { :href => /\/catalog\/testenterprise$/ }, :content => 'View all products'  
33 - end  
34 -  
35 should 'list 4 random products by default' do 23 should 'list 4 random products by default' do
36 enterprise = create(Enterprise, :name => 'testenterprise', :identifier => 'testenterprise') 24 enterprise = create(Enterprise, :name => 'testenterprise', :identifier => 'testenterprise')
37 create(Product, :enterprise => enterprise, :name => 'product one', :product_category => @product_category) 25 create(Product, :enterprise => enterprise, :name => 'product one', :product_category => @product_category)
@@ -105,21 +93,6 @@ class ProductsBlockTest &lt; ActiveSupport::TestCase @@ -105,21 +93,6 @@ class ProductsBlockTest &lt; ActiveSupport::TestCase
105 assert_equivalent [p1, p2, p3, p4], block.products 93 assert_equivalent [p1, p2, p3, p4], block.products
106 end 94 end
107 end 95 end
108 -  
109 - should 'generate footer when enterprise has own hostname' do  
110 - enterprise = create(Enterprise, :name => 'testenterprise', :identifier => 'testenterprise')  
111 - enterprise.domains << Domain.new(:name => 'sometest.com'); enterprise.save!  
112 - create(Product, :enterprise => enterprise, :name => 'product one', :product_category => @product_category)  
113 - create(Product, :enterprise => enterprise, :name => 'product two', :product_category => @product_category)  
114 -  
115 - block.stubs(:owner).returns(enterprise)  
116 -  
117 - footer = block.footer  
118 -  
119 - assert_tag_in_string footer, :tag => 'a', :attributes => { :href => /\/catalog\/testenterprise$/ }, :content => 'View all products'  
120 - end  
121 -  
122 -  
123 end 96 end
124 97
125 require 'boxes_helper' 98 require 'boxes_helper'
@@ -174,4 +147,29 @@ class ProductsBlockViewTest &lt; ActionView::TestCase @@ -174,4 +147,29 @@ class ProductsBlockViewTest &lt; ActionView::TestCase
174 content = render_block_content(block) 147 content = render_block_content(block)
175 assert_tag_in_string content, :tag => 'a', :attributes => { :style => /rails_minor.png/ } 148 assert_tag_in_string content, :tag => 'a', :attributes => { :style => /rails_minor.png/ }
176 end 149 end
  150 +
  151 + should 'point to all products in footer' do
  152 + enterprise = create(Enterprise, :name => 'testenterprise', :identifier => 'testenterprise')
  153 + create(Product, :enterprise => enterprise, :name => 'product one', :product_category => @product_category)
  154 + create(Product, :enterprise => enterprise, :name => 'product two', :product_category => @product_category)
  155 +
  156 + block.stubs(:owner).returns(enterprise)
  157 +
  158 + footer = render_block_footer(block)
  159 +
  160 + assert_tag_in_string footer, :tag => 'a', :attributes => { :href => /\/catalog\/testenterprise$/ }, :content => 'View all products'
  161 + end
  162 +
  163 + should 'generate footer when enterprise has own hostname' do
  164 + enterprise = create(Enterprise, :name => 'testenterprise', :identifier => 'testenterprise')
  165 + enterprise.domains << Domain.new(:name => 'sometest.com'); enterprise.save!
  166 + create(Product, :enterprise => enterprise, :name => 'product one', :product_category => @product_category)
  167 + create(Product, :enterprise => enterprise, :name => 'product two', :product_category => @product_category)
  168 +
  169 + block.stubs(:owner).returns(enterprise)
  170 +
  171 + footer = render_block_footer(block)
  172 +
  173 + assert_tag_in_string footer, :tag => 'a', :attributes => { :href => /\/catalog\/testenterprise$/ }, :content => 'View all products'
  174 + end
177 end 175 end