Commit 90c996e42ee74b57d2d805ec6799c6501b780b3b

Authored by Rodrigo Souto
1 parent d482447c

[performance] Fixing broken tests

app/models/article.rb
@@ -192,7 +192,7 @@ class Article < ActiveRecord::Base @@ -192,7 +192,7 @@ class Article < ActiveRecord::Base
192 scoped_methods.last[:find] && 192 scoped_methods.last[:find] &&
193 scoped_methods.last[:find][:joins] && 193 scoped_methods.last[:find][:joins] &&
194 scoped_methods.last[:find][:joins].index('profiles') ) 194 scoped_methods.last[:find][:joins].index('profiles') )
195 - result.includes(:profile) 195 + result = result.includes(:profile)
196 end 196 end
197 197
198 pagination ? result.paginate({:page => 1, :per_page => limit}) : result 198 pagination ? result.paginate({:page => 1, :per_page => limit}) : result
test/functional/profile_design_controller_test.rb
@@ -322,11 +322,14 @@ class ProfileDesignControllerTest < ActionController::TestCase @@ -322,11 +322,14 @@ class ProfileDesignControllerTest < ActionController::TestCase
322 should 'be able to save FeedReaderBlock configurations' do 322 should 'be able to save FeedReaderBlock configurations' do
323 @box1.blocks << FeedReaderBlock.new(:address => 'feed address') 323 @box1.blocks << FeedReaderBlock.new(:address => 'feed address')
324 holder.blocks(true) 324 holder.blocks(true)
  325 + block = @box1.blocks.last
325 326
326 - post :save, :profile => 'designtestuser', :id => @box1.blocks[-1].id, :block => {:address => 'new feed address', :limit => '20'} 327 + post :save, :profile => 'designtestuser', :id => block.id, :block => {:address => 'new feed address', :limit => '20'}
327 328
328 - assert_equal 'new feed address', @box1.blocks[-1].address  
329 - assert_equal 20, @box1.blocks[-1].limit 329 + block.reload
  330 +
  331 + assert_equal 'new feed address', block.address
  332 + assert_equal 20, block.limit
330 end 333 end
331 334
332 should 'require login' do 335 should 'require login' do
test/unit/boxes_helper_test.rb
@@ -46,7 +46,8 @@ class BoxesHelperTest &lt; ActiveSupport::TestCase @@ -46,7 +46,8 @@ class BoxesHelperTest &lt; ActiveSupport::TestCase
46 b = p.blocks.select{|bk| !bk.kind_of?(MainBlock) }[0] 46 b = p.blocks.select{|bk| !bk.kind_of?(MainBlock) }[0]
47 b.display = 'never'; b.save! 47 b.display = 'never'; b.save!
48 box = b.box 48 box = b.box
49 - box.expects(:blocks).returns([b]) 49 + box.blocks = [b]
  50 + box.save!
50 expects(:display_block).with(b, '') 51 expects(:display_block).with(b, '')
51 expects(:request).returns(request) 52 expects(:request).returns(request)
52 stubs(:block_target).returns('') 53 stubs(:block_target).returns('')
@@ -64,7 +65,8 @@ class BoxesHelperTest &lt; ActiveSupport::TestCase @@ -64,7 +65,8 @@ class BoxesHelperTest &lt; ActiveSupport::TestCase
64 b = p.blocks.select{|bk| !bk.kind_of?(MainBlock) }[0] 65 b = p.blocks.select{|bk| !bk.kind_of?(MainBlock) }[0]
65 b.display = 'never'; b.save! 66 b.display = 'never'; b.save!
66 box = b.box 67 box = b.box
67 - box.expects(:blocks).returns([b]) 68 + box.blocks = [b]
  69 + box.save!
68 expects(:display_block).with(b, '').never 70 expects(:display_block).with(b, '').never
69 expects(:request).returns(request) 71 expects(:request).returns(request)
70 stubs(:block_target).returns('') 72 stubs(:block_target).returns('')
@@ -106,9 +108,7 @@ class BoxesHelperTest &lt; ActiveSupport::TestCase @@ -106,9 +108,7 @@ class BoxesHelperTest &lt; ActiveSupport::TestCase
106 108
107 should 'fill context with the article, request_path and locale' do 109 should 'fill context with the article, request_path and locale' do
108 request = mock() 110 request = mock()
109 - box = mock()  
110 -  
111 - box.expects(:blocks).returns([]) 111 + box = Box.create!(:owner => fast_create(Profile))
112 request.expects(:path).returns('/') 112 request.expects(:path).returns('/')
113 expects(:request).returns(request) 113 expects(:request).returns(request)
114 expects(:locale).returns('en') 114 expects(:locale).returns('en')
test/unit/enterprise_test.rb
@@ -482,9 +482,11 @@ class EnterpriseTest &lt; ActiveSupport::TestCase @@ -482,9 +482,11 @@ class EnterpriseTest &lt; ActiveSupport::TestCase
482 482
483 should 'reindex products with full category name after save' do 483 should 'reindex products with full category name after save' do
484 product = mock 484 product = mock
  485 + products = mock
485 product.expects(:category_full_name) 486 product.expects(:category_full_name)
486 - Enterprise.any_instance.stubs(:products).returns([product])  
487 - Enterprise.expects(:solr_batch_add).with(includes(product)) 487 + products.stubs(:includes).returns([product])
  488 + Enterprise.any_instance.stubs(:products).returns(products)
  489 + Enterprise.expects(:solr_batch_add).with([products])
488 ent = fast_create(Enterprise) 490 ent = fast_create(Enterprise)
489 ent.save! 491 ent.save!
490 end 492 end