bsc_test.rb
2.25 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
75
76
77
78
79
80
81
82
require File.dirname(__FILE__) + '/../../../../../test/test_helper'
class BscPlugin::BscTest < ActiveSupport::TestCase
VALID_CNPJ = '94.132.024/0001-48'
def setup
@bsc = BscPlugin::Bsc.create!(:business_name => 'Sample Bsc', :company_name => 'Sample Bsc', :identifier => 'sample-bsc', :cnpj => VALID_CNPJ)
end
attr_accessor :bsc
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 = bsc
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.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)
task = BscPlugin::AssociateEnterprise.new(:target => e1, :bsc => bsc)
bsc.enterprise_requests.stubs(:pending).returns([task])
assert bsc.already_requested?(e1)
refute bsc.already_requested?(e2)
end
should 'return associated enterprises products' do
e1 = fast_create(Enterprise)
e2 = fast_create(Enterprise)
category = fast_create(ProductCategory)
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
refute bsc.create_product?
end
should 'have many contracts' do
contract1 = BscPlugin::Contract.create!(:bsc => bsc, :client_name => 'Marvin')
contract2 = BscPlugin::Contract.create!(:bsc => bsc, :client_name => 'Marvin')
assert_includes bsc.contracts, contract1
assert_includes bsc.contracts, contract2
end
end