Commit adbc99e5cece009ce78e79f7601d234b8622a673
1 parent
c6ec2f1e
Exists in
master
and in
22 other branches
rails3: fix featured_products_block test
PS: still with problem on image mass_assignment.
Showing
2 changed files
with
17 additions
and
17 deletions
Show diff stats
app/models/featured_products_block.rb
| @@ -27,7 +27,7 @@ class FeaturedProductsBlock < Block | @@ -27,7 +27,7 @@ class FeaturedProductsBlock < Block | ||
| 27 | 27 | ||
| 28 | def content(args={}) | 28 | def content(args={}) |
| 29 | block = self | 29 | block = self |
| 30 | - lambda do | 30 | + proc do |
| 31 | render :file => 'blocks/featured_products', :locals => { :block => block } | 31 | render :file => 'blocks/featured_products', :locals => { :block => block } |
| 32 | end | 32 | end |
| 33 | end | 33 | end |
test/unit/featured_products_block_test.rb
| @@ -13,8 +13,8 @@ class FeaturedProductsBlockTest < ActiveSupport::TestCase | @@ -13,8 +13,8 @@ class FeaturedProductsBlockTest < ActiveSupport::TestCase | ||
| 13 | profile = fast_create(Enterprise) | 13 | profile = fast_create(Enterprise) |
| 14 | products = [] | 14 | products = [] |
| 15 | category = fast_create(ProductCategory) | 15 | category = fast_create(ProductCategory) |
| 16 | - 3.times {|n| products.push(Product.create!(:name => "product #{n}", :enterprise_id => profile.id, :product_category_id => category.id)) } | ||
| 17 | - featured_products_block = FeaturedProductsBlock.create!(:product_ids => products.map(&:id)) | 16 | + 3.times {|n| products.push(create(Product, :name => "product #{n}", :enterprise_id => profile.id, :product_category_id => category.id)) } |
| 17 | + featured_products_block = create(FeaturedProductsBlock, :product_ids => products.map(&:id)) | ||
| 18 | assert_equal products, featured_products_block.products | 18 | assert_equal products, featured_products_block.products |
| 19 | end | 19 | end |
| 20 | 20 | ||
| @@ -61,12 +61,12 @@ class FeaturedProductsBlockTest < ActiveSupport::TestCase | @@ -61,12 +61,12 @@ class FeaturedProductsBlockTest < ActiveSupport::TestCase | ||
| 61 | end | 61 | end |
| 62 | 62 | ||
| 63 | should "an environment block collect product automatically" do | 63 | should "an environment block collect product automatically" do |
| 64 | - block = FeaturedProductsBlock.new() | 64 | + block = build(FeaturedProductsBlock, ) |
| 65 | block.product_ids = [] | 65 | block.product_ids = [] |
| 66 | - enterprise = Enterprise.create!(:name => "My enterprise", :identifier => 'myenterprise', :environment => @environment) | 66 | + enterprise = create(Enterprise, :name => "My enterprise", :identifier => 'myenterprise', :environment => @environment) |
| 67 | category = fast_create(ProductCategory) | 67 | category = fast_create(ProductCategory) |
| 68 | 3.times {|n| | 68 | 3.times {|n| |
| 69 | - Product.create!(:name => "product #{n}", :enterprise_id => enterprise.id, | 69 | + create(Product, :name => "product #{n}", :enterprise_id => enterprise.id, |
| 70 | :highlighted => true, :product_category_id => category.id, | 70 | :highlighted => true, :product_category_id => category.id, |
| 71 | :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') } | 71 | :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') } |
| 72 | ) | 72 | ) |
| @@ -77,12 +77,12 @@ class FeaturedProductsBlockTest < ActiveSupport::TestCase | @@ -77,12 +77,12 @@ class FeaturedProductsBlockTest < ActiveSupport::TestCase | ||
| 77 | end | 77 | end |
| 78 | 78 | ||
| 79 | should "an environment block collect just product with image automatically" do | 79 | should "an environment block collect just product with image automatically" do |
| 80 | - block = FeaturedProductsBlock.new() | 80 | + block = build(FeaturedProductsBlock, ) |
| 81 | block.product_ids = [] | 81 | block.product_ids = [] |
| 82 | - enterprise = Enterprise.create!(:name => "My enterprise", :identifier => 'myenterprise', :environment => @environment) | 82 | + enterprise = create(Enterprise, :name => "My enterprise", :identifier => 'myenterprise', :environment => @environment) |
| 83 | category = fast_create(ProductCategory) | 83 | category = fast_create(ProductCategory) |
| 84 | 3.times {|n| | 84 | 3.times {|n| |
| 85 | - Product.create!(:name => "product #{n}", :enterprise_id => enterprise.id, :highlighted => true, :product_category_id => category.id) | 85 | + create(Product, :name => "product #{n}", :enterprise_id => enterprise.id, :highlighted => true, :product_category_id => category.id) |
| 86 | } | 86 | } |
| 87 | @environment.boxes.first.blocks<< block | 87 | @environment.boxes.first.blocks<< block |
| 88 | 88 | ||
| @@ -90,12 +90,12 @@ class FeaturedProductsBlockTest < ActiveSupport::TestCase | @@ -90,12 +90,12 @@ class FeaturedProductsBlockTest < ActiveSupport::TestCase | ||
| 90 | end | 90 | end |
| 91 | 91 | ||
| 92 | should "an environment block collect just highlighted product automatically" do | 92 | should "an environment block collect just highlighted product automatically" do |
| 93 | - block = FeaturedProductsBlock.new() | 93 | + block = build(FeaturedProductsBlock, ) |
| 94 | block.product_ids = [] | 94 | block.product_ids = [] |
| 95 | - enterprise = Enterprise.create!(:name => "My enterprise", :identifier => 'myenterprise', :environment => @environment) | 95 | + enterprise = create(Enterprise, :name => "My enterprise", :identifier => 'myenterprise', :environment => @environment) |
| 96 | category = fast_create(ProductCategory) | 96 | category = fast_create(ProductCategory) |
| 97 | 3.times {|n| | 97 | 3.times {|n| |
| 98 | - Product.create!(:name => "product #{n}", :enterprise_id => enterprise.id, :product_category_id => category.id, :image_builder => { | 98 | + create(Product, :name => "product #{n}", :enterprise_id => enterprise.id, :product_category_id => category.id, :image_builder => { |
| 99 | :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') | 99 | :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') |
| 100 | }) | 100 | }) |
| 101 | } | 101 | } |
| @@ -112,19 +112,19 @@ class FeaturedProductsBlockTest < ActiveSupport::TestCase | @@ -112,19 +112,19 @@ class FeaturedProductsBlockTest < ActiveSupport::TestCase | ||
| 112 | end | 112 | end |
| 113 | 113 | ||
| 114 | should "return just highlighted products with image for selection" do | 114 | should "return just highlighted products with image for selection" do |
| 115 | - block = FeaturedProductsBlock.new() | 115 | + block = build(FeaturedProductsBlock, ) |
| 116 | block.product_ids = [] | 116 | block.product_ids = [] |
| 117 | - enterprise = Enterprise.create!(:name => "My enterprise", :identifier => 'myenterprise', :environment => @environment) | 117 | + enterprise = create(Enterprise, :name => "My enterprise", :identifier => 'myenterprise', :environment => @environment) |
| 118 | category = fast_create(ProductCategory) | 118 | category = fast_create(ProductCategory) |
| 119 | products = [] | 119 | products = [] |
| 120 | 3.times {|n| | 120 | 3.times {|n| |
| 121 | - products.push(Product.create!(:name => "product #{n}", :enterprise_id => enterprise.id, | 121 | + products.push(create(Product, :name => "product #{n}", :enterprise_id => enterprise.id, |
| 122 | :highlighted => true, :product_category_id => category.id, | 122 | :highlighted => true, :product_category_id => category.id, |
| 123 | :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') } | 123 | :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') } |
| 124 | )) | 124 | )) |
| 125 | } | 125 | } |
| 126 | - Product.create!(:name => "product 4", :enterprise_id => enterprise.id, :product_category_id => category.id, :highlighted => true) | ||
| 127 | - Product.create!(:name => "product 5", :enterprise_id => enterprise.id, :product_category_id => category.id, :image_builder => { | 126 | + create(Product, :name => "product 4", :enterprise_id => enterprise.id, :product_category_id => category.id, :highlighted => true) |
| 127 | + create(Product, :name => "product 5", :enterprise_id => enterprise.id, :product_category_id => category.id, :image_builder => { | ||
| 128 | :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') | 128 | :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') |
| 129 | }) | 129 | }) |
| 130 | @environment.boxes.first.blocks<< block | 130 | @environment.boxes.first.blocks<< block |