bsc_test.rb
2.41 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
require File.dirname(__FILE__) + '/../../../../../test/test_helper'
require File.dirname(__FILE__) + '/../../../../../app/models/uploaded_file'
require File.dirname(__FILE__) + '/../../../lib/ext/enterprise'
class BscPlugin::BscTest < Test::Unit::TestCase
VALID_CNPJ = '94.132.024/0001-48'
should 'validate presence of cnpj' do
bsc = BscPlugin::Bsc.new()
bsc.valid?
assert bsc.errors.invalid?(:cnpj)
end
should 'validate uniqueness of cnpj' do
bsc1 = BscPlugin::Bsc.create!({:business_name => 'Sample Bsc', :identifier => 'sample-bsc', :company_name => 'Sample Bsc Ltda.', :cnpj => VALID_CNPJ})
bsc2 = BscPlugin::Bsc.new(:cnpj => VALID_CNPJ)
bsc2.valid?
assert bsc2.errors.invalid?(:cnpj)
end
should 'have many enterprises' do
e1 = Enterprise.new(:name => 'Enterprise1', :identifier => 'enterprise1')
e2 = Enterprise.new(:name => 'Enterprise2', :identifier => 'enterprise2')
bsc = BscPlugin::Bsc.new(:business_name => 'Sample Bsc', :company_name => 'Sample Bsc Ltda.', :identifier => 'sample-bsc', :cnpj => VALID_CNPJ)
bsc.enterprises << e1
bsc.enterprises << e2
bsc.save!
assert_equal e1.bsc, bsc
assert_equal e2.bsc, bsc
end
should 'verify already requested enterprises' do
e1 = fast_create(Enterprise)
e2 = fast_create(Enterprise)
bsc = BscPlugin::Bsc.new()
task = BscPlugin::AssociateEnterprise.new(:target => e1, :bsc => bsc)
bsc.enterprise_requests.stubs(:pending).returns([task])
assert bsc.already_requested?(e1)
assert !bsc.already_requested?(e2)
end
should 'return associated enterprises products' do
e1 = fast_create(Enterprise)
e2 = fast_create(Enterprise)
category = fast_create(ProductCategory)
bsc = BscPlugin::Bsc.create!({:business_name => 'Sample Bsc', :identifier => 'sample-bsc', :company_name => 'Sample Bsc Ltda.', :cnpj => VALID_CNPJ})
p1 = fast_create(Product, :product_category_id => category.id)
p2 = fast_create(Product, :product_category_id => category.id)
p3 = fast_create(Product, :product_category_id => category.id)
e1.products << p1
e1.products << p2
e2.products << p3
bsc.enterprises << e1
bsc.enterprises << e2
bsc.reload
assert_includes bsc.products, p1
assert_includes bsc.products, p2
assert_includes bsc.products, p3
end
should 'not be able to create product' do
bsc = BscPlugin::Bsc.new
assert !bsc.create_product?
end
end