Commit adbc99e5cece009ce78e79f7601d234b8622a673
1 parent
c6ec2f1e
Exists in
staging
and in
42 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
test/unit/featured_products_block_test.rb
... | ... | @@ -13,8 +13,8 @@ class FeaturedProductsBlockTest < ActiveSupport::TestCase |
13 | 13 | profile = fast_create(Enterprise) |
14 | 14 | products = [] |
15 | 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 | 18 | assert_equal products, featured_products_block.products |
19 | 19 | end |
20 | 20 | |
... | ... | @@ -61,12 +61,12 @@ class FeaturedProductsBlockTest < ActiveSupport::TestCase |
61 | 61 | end |
62 | 62 | |
63 | 63 | should "an environment block collect product automatically" do |
64 | - block = FeaturedProductsBlock.new() | |
64 | + block = build(FeaturedProductsBlock, ) | |
65 | 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 | 67 | category = fast_create(ProductCategory) |
68 | 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 | 70 | :highlighted => true, :product_category_id => category.id, |
71 | 71 | :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') } |
72 | 72 | ) |
... | ... | @@ -77,12 +77,12 @@ class FeaturedProductsBlockTest < ActiveSupport::TestCase |
77 | 77 | end |
78 | 78 | |
79 | 79 | should "an environment block collect just product with image automatically" do |
80 | - block = FeaturedProductsBlock.new() | |
80 | + block = build(FeaturedProductsBlock, ) | |
81 | 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 | 83 | category = fast_create(ProductCategory) |
84 | 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 | 87 | @environment.boxes.first.blocks<< block |
88 | 88 | |
... | ... | @@ -90,12 +90,12 @@ class FeaturedProductsBlockTest < ActiveSupport::TestCase |
90 | 90 | end |
91 | 91 | |
92 | 92 | should "an environment block collect just highlighted product automatically" do |
93 | - block = FeaturedProductsBlock.new() | |
93 | + block = build(FeaturedProductsBlock, ) | |
94 | 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 | 96 | category = fast_create(ProductCategory) |
97 | 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 | 99 | :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') |
100 | 100 | }) |
101 | 101 | } |
... | ... | @@ -112,19 +112,19 @@ class FeaturedProductsBlockTest < ActiveSupport::TestCase |
112 | 112 | end |
113 | 113 | |
114 | 114 | should "return just highlighted products with image for selection" do |
115 | - block = FeaturedProductsBlock.new() | |
115 | + block = build(FeaturedProductsBlock, ) | |
116 | 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 | 118 | category = fast_create(ProductCategory) |
119 | 119 | products = [] |
120 | 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 | 122 | :highlighted => true, :product_category_id => category.id, |
123 | 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 | 128 | :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') |
129 | 129 | }) |
130 | 130 | @environment.boxes.first.blocks<< block | ... | ... |