Commit f300fee3cf94e351a7f385e49b28bece0e4f5d8d
1 parent
6d4cd4e6
Exists in
master
and in
27 other branches
rails3: fix products_block test
PS: still breaking because of missing controller called from link_to.
Showing
2 changed files
with
38 additions
and
41 deletions
Show diff stats
app/models/products_block.rb
test/unit/products_block_test.rb
| ... | ... | @@ -21,10 +21,9 @@ class ProductsBlockTest < ActiveSupport::TestCase |
| 21 | 21 | end |
| 22 | 22 | |
| 23 | 23 | should "list owner products" do |
| 24 | - | |
| 25 | - enterprise = Enterprise.create!(:name => 'testenterprise', :identifier => 'testenterprise') | |
| 26 | - enterprise.products.create!(:name => 'product one', :product_category => @product_category) | |
| 27 | - enterprise.products.create!(:name => 'product two', :product_category => @product_category) | |
| 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) | |
| 28 | 27 | |
| 29 | 28 | block.expects(:products).returns(enterprise.products) |
| 30 | 29 | |
| ... | ... | @@ -34,13 +33,12 @@ class ProductsBlockTest < ActiveSupport::TestCase |
| 34 | 33 | |
| 35 | 34 | assert_tag_in_string content, :tag => 'li', :attributes => { :class => 'product' }, :descendant => { :tag => 'a', :content => /product one/ } |
| 36 | 35 | assert_tag_in_string content, :tag => 'li', :attributes => { :class => 'product' }, :descendant => { :tag => 'a', :content => /product two/ } |
| 37 | - | |
| 38 | 36 | end |
| 39 | 37 | |
| 40 | 38 | should 'point to all products in footer' do |
| 41 | - enterprise = Enterprise.create!(:name => 'testenterprise', :identifier => 'testenterprise') | |
| 42 | - enterprise.products.create!(:name => 'product one', :product_category => @product_category) | |
| 43 | - enterprise.products.create!(:name => 'product two', :product_category => @product_category) | |
| 39 | + enterprise = create(Enterprise, :name => 'testenterprise', :identifier => 'testenterprise') | |
| 40 | + create(Product, :enterprise => enterprise, :name => 'product one', :product_category => @product_category) | |
| 41 | + create(Product, :enterprise => enterprise, :name => 'product two', :product_category => @product_category) | |
| 44 | 42 | |
| 45 | 43 | block.stubs(:owner).returns(enterprise) |
| 46 | 44 | |
| ... | ... | @@ -50,12 +48,12 @@ class ProductsBlockTest < ActiveSupport::TestCase |
| 50 | 48 | end |
| 51 | 49 | |
| 52 | 50 | should 'list 4 random products by default' do |
| 53 | - enterprise = Enterprise.create!(:name => 'testenterprise', :identifier => 'testenterprise') | |
| 54 | - enterprise.products.create!(:name => 'product one', :product_category => @product_category) | |
| 55 | - enterprise.products.create!(:name => 'product two', :product_category => @product_category) | |
| 56 | - enterprise.products.create!(:name => 'product three', :product_category => @product_category) | |
| 57 | - enterprise.products.create!(:name => 'product four', :product_category => @product_category) | |
| 58 | - enterprise.products.create!(:name => 'product five', :product_category => @product_category) | |
| 51 | + enterprise = create(Enterprise, :name => 'testenterprise', :identifier => 'testenterprise') | |
| 52 | + create(Product, :enterprise => enterprise, :name => 'product one', :product_category => @product_category) | |
| 53 | + create(Product, :enterprise => enterprise, :name => 'product two', :product_category => @product_category) | |
| 54 | + create(Product, :enterprise => enterprise, :name => 'product three', :product_category => @product_category) | |
| 55 | + create(Product, :enterprise => enterprise, :name => 'product four', :product_category => @product_category) | |
| 56 | + create(Product, :enterprise => enterprise, :name => 'product five', :product_category => @product_category) | |
| 59 | 57 | |
| 60 | 58 | block.stubs(:owner).returns(enterprise) |
| 61 | 59 | |
| ... | ... | @@ -63,10 +61,10 @@ class ProductsBlockTest < ActiveSupport::TestCase |
| 63 | 61 | end |
| 64 | 62 | |
| 65 | 63 | should 'list all products if less than 4 by default' do |
| 66 | - enterprise = Enterprise.create!(:name => 'testenterprise', :identifier => 'testenterprise') | |
| 67 | - enterprise.products.create!(:name => 'product one', :product_category => @product_category) | |
| 68 | - enterprise.products.create!(:name => 'product two', :product_category => @product_category) | |
| 69 | - enterprise.products.create!(:name => 'product three', :product_category => @product_category) | |
| 64 | + enterprise = create(Enterprise, :name => 'testenterprise', :identifier => 'testenterprise') | |
| 65 | + create(Product, :enterprise => enterprise, :name => 'product one', :product_category => @product_category) | |
| 66 | + create(Product, :enterprise => enterprise, :name => 'product two', :product_category => @product_category) | |
| 67 | + create(Product, :enterprise => enterprise, :name => 'product three', :product_category => @product_category) | |
| 70 | 68 | |
| 71 | 69 | block.stubs(:owner).returns(enterprise) |
| 72 | 70 | |
| ... | ... | @@ -75,13 +73,12 @@ class ProductsBlockTest < ActiveSupport::TestCase |
| 75 | 73 | |
| 76 | 74 | |
| 77 | 75 | should 'be able to set product_ids and have them listed' do |
| 78 | - enterprise = Enterprise.create!(:name => 'testenterprise', :identifier => 'testenterprise') | |
| 79 | - | |
| 80 | - p1 = enterprise.products.create!(:name => 'product one', :product_category => @product_category) | |
| 81 | - p2 = enterprise.products.create!(:name => 'product two', :product_category => @product_category) | |
| 82 | - p3 = enterprise.products.create!(:name => 'product three', :product_category => @product_category) | |
| 83 | - p4 = enterprise.products.create!(:name => 'product four', :product_category => @product_category) | |
| 84 | - p5 = enterprise.products.create!(:name => 'product five', :product_category => @product_category) | |
| 76 | + enterprise = create(Enterprise, :name => 'testenterprise', :identifier => 'testenterprise') | |
| 77 | + p1 = create(Product, :enterprise => enterprise, :name => 'product one', :product_category => @product_category) | |
| 78 | + p2 = create(Product, :enterprise => enterprise, :name => 'product two', :product_category => @product_category) | |
| 79 | + p3 = create(Product, :enterprise => enterprise, :name => 'product three', :product_category => @product_category) | |
| 80 | + p4 = create(Product, :enterprise => enterprise, :name => 'product four', :product_category => @product_category) | |
| 81 | + p5 = create(Product, :enterprise => enterprise, :name => 'product five', :product_category => @product_category) | |
| 85 | 82 | |
| 86 | 83 | block.stubs(:owner).returns(enterprise) |
| 87 | 84 | |
| ... | ... | @@ -90,9 +87,9 @@ class ProductsBlockTest < ActiveSupport::TestCase |
| 90 | 87 | end |
| 91 | 88 | |
| 92 | 89 | should 'save product_ids' do |
| 93 | - enterprise = Enterprise.create!(:name => 'testenterprise', :identifier => 'testenterprise') | |
| 94 | - p1 = enterprise.products.create!(:name => 'product one', :product_category => @product_category) | |
| 95 | - p2 = enterprise.products.create!(:name => 'product two', :product_category => @product_category) | |
| 90 | + enterprise = create(Enterprise, :name => 'testenterprise', :identifier => 'testenterprise') | |
| 91 | + p1 = create(Product, :enterprise => enterprise, :name => 'product one', :product_category => @product_category) | |
| 92 | + p2 = create(Product, :enterprise => enterprise, :name => 'product two', :product_category => @product_category) | |
| 96 | 93 | |
| 97 | 94 | block = ProductsBlock.new |
| 98 | 95 | enterprise.boxes.first.blocks << block |
| ... | ... | @@ -109,11 +106,11 @@ class ProductsBlockTest < ActiveSupport::TestCase |
| 109 | 106 | end |
| 110 | 107 | |
| 111 | 108 | should 'not repeat products' do |
| 112 | - enterprise = Enterprise.create!(:name => 'test_enterprise', :identifier => 'test_enterprise') | |
| 113 | - p1 = enterprise.products.create!(:name => 'product one', :product_category => @product_category) | |
| 114 | - p2 = enterprise.products.create!(:name => 'product two', :product_category => @product_category) | |
| 115 | - p3 = enterprise.products.create!(:name => 'product three', :product_category => @product_category) | |
| 116 | - p4 = enterprise.products.create!(:name => 'product four', :product_category => @product_category) | |
| 109 | + enterprise = create(Enterprise, :name => 'testenterprise', :identifier => 'testenterprise') | |
| 110 | + p1 = create(Product, :enterprise => enterprise, :name => 'product one', :product_category => @product_category) | |
| 111 | + p2 = create(Product, :enterprise => enterprise, :name => 'product two', :product_category => @product_category) | |
| 112 | + p3 = create(Product, :enterprise => enterprise, :name => 'product three', :product_category => @product_category) | |
| 113 | + p4 = create(Product, :enterprise => enterprise, :name => 'product four', :product_category => @product_category) | |
| 117 | 114 | |
| 118 | 115 | block = ProductsBlock.new |
| 119 | 116 | enterprise.boxes.first.blocks << block |
| ... | ... | @@ -125,10 +122,10 @@ class ProductsBlockTest < ActiveSupport::TestCase |
| 125 | 122 | end |
| 126 | 123 | |
| 127 | 124 | should 'generate footer when enterprise has own hostname' do |
| 128 | - enterprise = Enterprise.create!(:name => 'testenterprise', :identifier => 'testenterprise') | |
| 125 | + enterprise = create(Enterprise, :name => 'testenterprise', :identifier => 'testenterprise') | |
| 129 | 126 | enterprise.domains << Domain.new(:name => 'sometest.com'); enterprise.save! |
| 130 | - enterprise.products.create!(:name => 'product one', :product_category => @product_category) | |
| 131 | - enterprise.products.create!(:name => 'product two', :product_category => @product_category) | |
| 127 | + create(Product, :enterprise => enterprise, :name => 'product one', :product_category => @product_category) | |
| 128 | + create(Product, :enterprise => enterprise, :name => 'product two', :product_category => @product_category) | |
| 132 | 129 | |
| 133 | 130 | block.stubs(:owner).returns(enterprise) |
| 134 | 131 | |
| ... | ... | @@ -138,8 +135,8 @@ class ProductsBlockTest < ActiveSupport::TestCase |
| 138 | 135 | end |
| 139 | 136 | |
| 140 | 137 | should 'display the default minor image if thumbnails were not processed' do |
| 141 | - enterprise = Enterprise.create!(:name => 'testenterprise', :identifier => 'testenterprise') | |
| 142 | - enterprise.products.create!(:name => 'product', :product_category => @product_category, :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')}) | |
| 138 | + 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')}) | |
| 143 | 140 | |
| 144 | 141 | block.expects(:products).returns(enterprise.products) |
| 145 | 142 | |
| ... | ... | @@ -149,8 +146,8 @@ class ProductsBlockTest < ActiveSupport::TestCase |
| 149 | 146 | end |
| 150 | 147 | |
| 151 | 148 | should 'display the thumbnail image if thumbnails were processed' do |
| 152 | - enterprise = Enterprise.create!(:name => 'testenterprise', :identifier => 'testenterprise') | |
| 153 | - enterprise.products.create!(:name => 'product', :product_category => @product_category, :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')}) | |
| 149 | + enterprise = create(Enterprise, :name => 'testenterprise', :identifier => 'testenterprise') | |
| 150 | + create(Product, :enterprise => enterprise, :name => 'product', :product_category => @product_category, :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')}) | |
| 154 | 151 | |
| 155 | 152 | process_delayed_job_queue |
| 156 | 153 | block.expects(:products).returns(enterprise.products.reload) | ... | ... |