product_test.rb
1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
require File.dirname(__FILE__) + '/../test_helper'
class ProductTest < Test::Unit::TestCase
should 'create product' do
assert_difference Product, :count do
p = Product.new(:name => 'test product1')
assert p.save
end
end
should 'destroy product' do
p = Product.create(:name => 'test product2')
assert_difference Product, :count, -1 do
p.destroy
end
end
should 'name be unique' do
Product.create(:name => 'test product3')
assert_no_difference Product, :count do
p = Product.new(:name => 'test product3')
assert !p.save
end
end
should 'list recent products' do
enterprise = Enterprise.create!(:name => "My enterprise", :identifier => 'my-enterprise')
Product.delete_all
p1 = enterprise.products.create!(:name => 'product 1')
p2 = enterprise.products.create!(:name => 'product 2')
p3 = enterprise.products.create!(:name => 'product 3')
assert_equal [p3, p2, p1], Product.recent
end
should 'list recent products with limit' do
enterprise = Enterprise.create!(:name => "My enterprise", :identifier => 'my-enterprise')
Product.delete_all
p1 = enterprise.products.create!(:name => 'product 1')
p2 = enterprise.products.create!(:name => 'product 2')
p3 = enterprise.products.create!(:name => 'product 3')
assert_equal [p3, p2], Product.recent(2)
end
should 'save image on create product' do
assert_difference Product, :count do
p = Product.create!(:name => 'test product1', :image_builder => {
:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')
})
assert_equal p.image(true).filename, 'rails.png'
end
end
end