Commit 9f003eb0ed27201771881656c0916e9b2f7eb9b7
1 parent
5955ed72
Exists in
web_steps_improvements
and in
9 other branches
Fix ProductsBlock unit tests and view
By removing the content method, it is now necessary to turn the test into a view one using the BoxesHelper method and properly stubbing other helpers.
Showing
1 changed file
with
36 additions
and
18 deletions
Show diff stats
test/unit/products_block_test.rb
@@ -20,21 +20,6 @@ class ProductsBlockTest < ActiveSupport::TestCase | @@ -20,21 +20,6 @@ class ProductsBlockTest < 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 "list owner products" 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.expects(:products).returns(enterprise.products) | ||
29 | - | ||
30 | - content = block.content | ||
31 | - | ||
32 | - assert_tag_in_string content, :content => 'Products' | ||
33 | - | ||
34 | - assert_tag_in_string content, :tag => 'li', :attributes => { :class => 'product' }, :descendant => { :tag => 'a', :content => /product one/ } | ||
35 | - assert_tag_in_string content, :tag => 'li', :attributes => { :class => 'product' }, :descendant => { :tag => 'a', :content => /product two/ } | ||
36 | - end | ||
37 | - | ||
38 | should 'point to all products in footer' do | 23 | should 'point to all products in footer' do |
39 | enterprise = create(Enterprise, :name => 'testenterprise', :identifier => 'testenterprise') | 24 | enterprise = create(Enterprise, :name => 'testenterprise', :identifier => 'testenterprise') |
40 | create(Product, :enterprise => enterprise, :name => 'product one', :product_category => @product_category) | 25 | create(Product, :enterprise => enterprise, :name => 'product one', :product_category => @product_category) |
@@ -134,13 +119,46 @@ class ProductsBlockTest < ActiveSupport::TestCase | @@ -134,13 +119,46 @@ class ProductsBlockTest < ActiveSupport::TestCase | ||
134 | assert_tag_in_string footer, :tag => 'a', :attributes => { :href => /\/catalog\/testenterprise$/ }, :content => 'View all products' | 119 | assert_tag_in_string footer, :tag => 'a', :attributes => { :href => /\/catalog\/testenterprise$/ }, :content => 'View all products' |
135 | end | 120 | end |
136 | 121 | ||
122 | + | ||
123 | +end | ||
124 | + | ||
125 | +require 'boxes_helper' | ||
126 | +require 'block_helper' | ||
127 | + | ||
128 | +class ProductsBlockViewTest < ActionView::TestCase | ||
129 | + include BoxesHelper | ||
130 | + | ||
131 | + ActionView::Base.send :include, BlockHelper | ||
132 | + | ||
133 | + def setup | ||
134 | + @block = ProductsBlock.new | ||
135 | + @product_category = fast_create(ProductCategory, :name => 'Products') | ||
136 | + end | ||
137 | + attr_reader :block | ||
138 | + | ||
139 | + should "list owner products" do | ||
140 | + enterprise = create(Enterprise, :name => 'testenterprise', :identifier => 'testenterprise') | ||
141 | + create(Product, :enterprise => enterprise, :name => 'product one', :product_category => @product_category) | ||
142 | + create(Product, :enterprise => enterprise, :name => 'product two', :product_category => @product_category) | ||
143 | + | ||
144 | + block.expects(:products).returns(enterprise.products) | ||
145 | + | ||
146 | + content = render_block_content(block) | ||
147 | + | ||
148 | + assert_tag_in_string content, :content => 'Products' | ||
149 | + | ||
150 | + assert_tag_in_string content, :tag => 'li', :attributes => { :class => 'product' }, :descendant => { :tag => 'a', :content => /product one/ } | ||
151 | + assert_tag_in_string content, :tag => 'li', :attributes => { :class => 'product' }, :descendant => { :tag => 'a', :content => /product two/ } | ||
152 | + end | ||
153 | + | ||
137 | should 'display the default minor image if thumbnails were not processed' do | 154 | should 'display the default minor image if thumbnails were not processed' do |
138 | enterprise = create(Enterprise, :name => 'testenterprise', :identifier => 'testenterprise') | 155 | enterprise = create(Enterprise, :name => 'testenterprise', :identifier => 'testenterprise') |
139 | create(Product, :enterprise => enterprise, :name => 'product', :product_category => @product_category, :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')}) | 156 | create(Product, :enterprise => enterprise, :name => 'product', :product_category => @product_category, :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')}) |
140 | 157 | ||
141 | block.expects(:products).returns(enterprise.products) | 158 | block.expects(:products).returns(enterprise.products) |
159 | + ActionView::Base.any_instance.stubs(:block_title).returns("") | ||
142 | 160 | ||
143 | - content = block.content | 161 | + content = render_block_content(block) |
144 | 162 | ||
145 | assert_tag_in_string content, :tag => 'a', :attributes => { :style => /image-loading-minor.png/ } | 163 | assert_tag_in_string content, :tag => 'a', :attributes => { :style => /image-loading-minor.png/ } |
146 | end | 164 | end |
@@ -151,9 +169,9 @@ class ProductsBlockTest < ActiveSupport::TestCase | @@ -151,9 +169,9 @@ class ProductsBlockTest < ActiveSupport::TestCase | ||
151 | 169 | ||
152 | process_delayed_job_queue | 170 | process_delayed_job_queue |
153 | block.expects(:products).returns(enterprise.products.reload) | 171 | block.expects(:products).returns(enterprise.products.reload) |
172 | + ActionView::Base.any_instance.stubs(:block_title).returns("") | ||
154 | 173 | ||
155 | - content = block.content | 174 | + content = render_block_content(block) |
156 | assert_tag_in_string content, :tag => 'a', :attributes => { :style => /rails_minor.png/ } | 175 | assert_tag_in_string content, :tag => 'a', :attributes => { :style => /rails_minor.png/ } |
157 | end | 176 | end |
158 | - | ||
159 | end | 177 | end |