diff --git a/app/models/featured_products_block.rb b/app/models/featured_products_block.rb index c2a6bda..4331622 100644 --- a/app/models/featured_products_block.rb +++ b/app/models/featured_products_block.rb @@ -27,7 +27,7 @@ class FeaturedProductsBlock < Block def content(args={}) block = self - lambda do + proc do render :file => 'blocks/featured_products', :locals => { :block => block } end end diff --git a/test/unit/featured_products_block_test.rb b/test/unit/featured_products_block_test.rb index 8aef8bf..f2faf36 100644 --- a/test/unit/featured_products_block_test.rb +++ b/test/unit/featured_products_block_test.rb @@ -13,8 +13,8 @@ class FeaturedProductsBlockTest < ActiveSupport::TestCase profile = fast_create(Enterprise) products = [] category = fast_create(ProductCategory) - 3.times {|n| products.push(Product.create!(:name => "product #{n}", :enterprise_id => profile.id, :product_category_id => category.id)) } - featured_products_block = FeaturedProductsBlock.create!(:product_ids => products.map(&:id)) + 3.times {|n| products.push(create(Product, :name => "product #{n}", :enterprise_id => profile.id, :product_category_id => category.id)) } + featured_products_block = create(FeaturedProductsBlock, :product_ids => products.map(&:id)) assert_equal products, featured_products_block.products end @@ -61,12 +61,12 @@ class FeaturedProductsBlockTest < ActiveSupport::TestCase end should "an environment block collect product automatically" do - block = FeaturedProductsBlock.new() + block = build(FeaturedProductsBlock, ) block.product_ids = [] - enterprise = Enterprise.create!(:name => "My enterprise", :identifier => 'myenterprise', :environment => @environment) + enterprise = create(Enterprise, :name => "My enterprise", :identifier => 'myenterprise', :environment => @environment) category = fast_create(ProductCategory) 3.times {|n| - Product.create!(:name => "product #{n}", :enterprise_id => enterprise.id, + create(Product, :name => "product #{n}", :enterprise_id => enterprise.id, :highlighted => true, :product_category_id => category.id, :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') } ) @@ -77,12 +77,12 @@ class FeaturedProductsBlockTest < ActiveSupport::TestCase end should "an environment block collect just product with image automatically" do - block = FeaturedProductsBlock.new() + block = build(FeaturedProductsBlock, ) block.product_ids = [] - enterprise = Enterprise.create!(:name => "My enterprise", :identifier => 'myenterprise', :environment => @environment) + enterprise = create(Enterprise, :name => "My enterprise", :identifier => 'myenterprise', :environment => @environment) category = fast_create(ProductCategory) 3.times {|n| - Product.create!(:name => "product #{n}", :enterprise_id => enterprise.id, :highlighted => true, :product_category_id => category.id) + create(Product, :name => "product #{n}", :enterprise_id => enterprise.id, :highlighted => true, :product_category_id => category.id) } @environment.boxes.first.blocks<< block @@ -90,12 +90,12 @@ class FeaturedProductsBlockTest < ActiveSupport::TestCase end should "an environment block collect just highlighted product automatically" do - block = FeaturedProductsBlock.new() + block = build(FeaturedProductsBlock, ) block.product_ids = [] - enterprise = Enterprise.create!(:name => "My enterprise", :identifier => 'myenterprise', :environment => @environment) + enterprise = create(Enterprise, :name => "My enterprise", :identifier => 'myenterprise', :environment => @environment) category = fast_create(ProductCategory) 3.times {|n| - Product.create!(:name => "product #{n}", :enterprise_id => enterprise.id, :product_category_id => category.id, :image_builder => { + create(Product, :name => "product #{n}", :enterprise_id => enterprise.id, :product_category_id => category.id, :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') }) } @@ -112,19 +112,19 @@ class FeaturedProductsBlockTest < ActiveSupport::TestCase end should "return just highlighted products with image for selection" do - block = FeaturedProductsBlock.new() + block = build(FeaturedProductsBlock, ) block.product_ids = [] - enterprise = Enterprise.create!(:name => "My enterprise", :identifier => 'myenterprise', :environment => @environment) + enterprise = create(Enterprise, :name => "My enterprise", :identifier => 'myenterprise', :environment => @environment) category = fast_create(ProductCategory) products = [] 3.times {|n| - products.push(Product.create!(:name => "product #{n}", :enterprise_id => enterprise.id, + products.push(create(Product, :name => "product #{n}", :enterprise_id => enterprise.id, :highlighted => true, :product_category_id => category.id, :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') } )) } - Product.create!(:name => "product 4", :enterprise_id => enterprise.id, :product_category_id => category.id, :highlighted => true) - Product.create!(:name => "product 5", :enterprise_id => enterprise.id, :product_category_id => category.id, :image_builder => { + create(Product, :name => "product 4", :enterprise_id => enterprise.id, :product_category_id => category.id, :highlighted => true) + create(Product, :name => "product 5", :enterprise_id => enterprise.id, :product_category_id => category.id, :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') }) @environment.boxes.first.blocks<< block -- libgit2 0.21.2