rconomic 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +6 -14
- data/.travis.yml +0 -1
- data/Gemfile +0 -1
- data/lib/economic/account.rb +3 -5
- data/lib/economic/cash_book.rb +1 -1
- data/lib/economic/cash_book_entry.rb +92 -94
- data/lib/economic/creditor.rb +1 -1
- data/lib/economic/creditor_contact.rb +15 -17
- data/lib/economic/creditor_entry.rb +0 -1
- data/lib/economic/current_invoice.rb +32 -35
- data/lib/economic/current_invoice_line.rb +14 -2
- data/lib/economic/debtor.rb +60 -37
- data/lib/economic/debtor_contact.rb +26 -20
- data/lib/economic/endpoint.rb +72 -0
- data/lib/economic/entity/handle.rb +35 -21
- data/lib/economic/entity/mapper.rb +41 -0
- data/lib/economic/entity.rb +58 -34
- data/lib/economic/invoice.rb +15 -2
- data/lib/economic/proxies/account_proxy.rb +2 -3
- data/lib/economic/proxies/actions/find_by_ci_number.rb +4 -2
- data/lib/economic/proxies/actions/find_by_date_interval.rb +0 -1
- data/lib/economic/proxies/actions/find_by_name.rb +5 -1
- data/lib/economic/proxies/cash_book_entry_proxy.rb +1 -1
- data/lib/economic/proxies/entity_proxy.rb +15 -8
- data/lib/economic/session.rb +27 -31
- data/lib/rconomic/version.rb +1 -1
- data/rconomic.gemspec +1 -5
- data/spec/economic/cash_book_entry_spec.rb +27 -5
- data/spec/economic/cash_book_spec.rb +6 -6
- data/spec/economic/creditor_contact_spec.rb +24 -15
- data/spec/economic/creditor_spec.rb +9 -9
- data/spec/economic/current_invoice_line_spec.rb +7 -7
- data/spec/economic/current_invoice_spec.rb +82 -33
- data/spec/economic/debtor_contact_spec.rb +25 -15
- data/spec/economic/debtor_entry_spec.rb +3 -3
- data/spec/economic/debtor_spec.rb +49 -15
- data/spec/economic/endpoint_spec.rb +71 -0
- data/spec/economic/entity/handle_spec.rb +42 -49
- data/spec/economic/entity/mapper_spec.rb +54 -0
- data/spec/economic/entity_spec.rb +78 -72
- data/spec/economic/entry_spec.rb +3 -3
- data/spec/economic/invoice_spec.rb +37 -18
- data/spec/economic/proxies/actions/find_by_name_spec.rb +15 -12
- data/spec/economic/proxies/cash_book_entry_proxy_spec.rb +26 -24
- data/spec/economic/proxies/cash_book_proxy_spec.rb +23 -21
- data/spec/economic/proxies/creditor_contact_proxy_spec.rb +12 -16
- data/spec/economic/proxies/creditor_entry_proxy_spec.rb +18 -14
- data/spec/economic/proxies/creditor_proxy_spec.rb +23 -26
- data/spec/economic/proxies/current_invoice_line_proxy_spec.rb +17 -20
- data/spec/economic/proxies/current_invoice_proxy_spec.rb +38 -41
- data/spec/economic/proxies/debtor_contact_proxy_spec.rb +12 -15
- data/spec/economic/proxies/debtor_entry_proxy_spec.rb +18 -14
- data/spec/economic/proxies/debtor_proxy_spec.rb +31 -34
- data/spec/economic/proxies/entry_proxy_spec.rb +26 -22
- data/spec/economic/proxies/invoice_proxy_spec.rb +18 -21
- data/spec/economic/session_spec.rb +57 -44
- data/spec/fixtures/{spec_entity_create_from_data → account_create_from_data}/success.xml +5 -5
- data/spec/fixtures/{spec_entity_delete → account_delete}/success.xml +1 -1
- data/spec/fixtures/{spec_entity_get_data → account_get_data}/success.xml +5 -5
- data/spec/fixtures/{spec_entity_update_from_data → account_update_from_data}/success.xml +5 -5
- data/spec/fixtures/cash_book_entry_create_creditor_invoice/success.xml +2 -2
- data/spec/fixtures/cash_book_entry_create_creditor_payment/success.xml +2 -2
- data/spec/fixtures/creditor_contact_create_from_data/success.xml +10 -0
- data/spec/fixtures/debtor_contact_create_from_data/success.xml +10 -0
- data/spec/fixtures/debtor_create_from_data/success.xml +57 -0
- data/spec/spec_helper.rb +10 -104
- data/spec/support/api_requests.rb +20 -0
- data/spec/support/factories.rb +65 -0
- data/spec/support/fixtures.rb +9 -0
- metadata +27 -31
@@ -8,7 +8,7 @@ describe Economic::CashBookProxy do
|
|
8
8
|
describe ".new" do
|
9
9
|
|
10
10
|
it "stores session" do
|
11
|
-
subject.session.
|
11
|
+
expect(subject.session).to equal(session)
|
12
12
|
end
|
13
13
|
|
14
14
|
end
|
@@ -16,11 +16,11 @@ describe Economic::CashBookProxy do
|
|
16
16
|
describe ".build" do
|
17
17
|
|
18
18
|
it "instantiates a new CashBook" do
|
19
|
-
subject.build.
|
19
|
+
expect(subject.build).to be_instance_of(Economic::CashBook)
|
20
20
|
end
|
21
21
|
|
22
22
|
it "assigns the session to the CashBook" do
|
23
|
-
subject.build.session.
|
23
|
+
expect(subject.build.session).to equal(session)
|
24
24
|
end
|
25
25
|
|
26
26
|
end
|
@@ -28,52 +28,54 @@ describe Economic::CashBookProxy do
|
|
28
28
|
describe ".all" do
|
29
29
|
|
30
30
|
it "returns multiple cashbooks" do
|
31
|
-
|
32
|
-
|
31
|
+
stub_request('CashBook_GetAll', nil, :multiple)
|
32
|
+
stub_request('CashBook_GetDataArray', nil, :multiple)
|
33
33
|
|
34
34
|
all = subject.all
|
35
|
-
all.size.
|
36
|
-
all.each { |cash_book| cash_book.
|
35
|
+
expect(all.size).to eq(2)
|
36
|
+
all.each { |cash_book| expect(cash_book).to be_instance_of(Economic::CashBook) }
|
37
37
|
end
|
38
38
|
|
39
39
|
it "properly fills out handles of cash books" do
|
40
40
|
# Issue #12
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
stub_request('CashBook_GetAll', nil, :multiple)
|
42
|
+
stub_request('CashBook_GetDataArray', nil, :multiple)
|
43
|
+
stub_request('CashBook_GetData', nil, :success)
|
44
|
+
stub_request('CashBook_GetAll', nil, :multiple)
|
45
|
+
stub_request('CashBook_GetDataArray', nil, :multiple)
|
44
46
|
|
45
47
|
cash_book = subject.find(subject.all.first.handle)
|
46
|
-
subject.all.first.handle.
|
48
|
+
expect(subject.all.first.handle).to eq(cash_book.handle)
|
47
49
|
end
|
48
50
|
end
|
49
51
|
|
50
52
|
describe ".get_name" do
|
51
53
|
|
52
54
|
it 'returns a cash book with a name' do
|
53
|
-
|
55
|
+
mock_request('CashBook_GetName', {"cashBookHandle" => { "Number" => "52" }}, :success)
|
54
56
|
result = subject.get_name("52")
|
55
|
-
result.
|
56
|
-
result.number.
|
57
|
-
result.name.
|
57
|
+
expect(result).to be_instance_of(Economic::CashBook)
|
58
|
+
expect(result.number).to eq("52")
|
59
|
+
expect(result.name).to be_a(String)
|
58
60
|
end
|
59
61
|
|
60
62
|
end
|
61
63
|
|
62
64
|
describe "#last" do
|
63
65
|
it "returns the last cash book" do
|
64
|
-
|
65
|
-
|
66
|
+
stub_request('CashBook_GetAll', nil, :multiple)
|
67
|
+
stub_request('CashBook_GetDataArray', nil, :multiple)
|
66
68
|
|
67
|
-
subject.all.last.name.
|
69
|
+
expect(subject.all.last.name).to eq("Another cash book")
|
68
70
|
end
|
69
71
|
end
|
70
72
|
|
71
73
|
describe "#[]" do
|
72
74
|
it "returns the specific cash book" do
|
73
|
-
|
74
|
-
|
75
|
+
stub_request('CashBook_GetAll', nil, :multiple)
|
76
|
+
stub_request('CashBook_GetDataArray', nil, :multiple)
|
75
77
|
|
76
|
-
subject.all[1].name.
|
78
|
+
expect(subject.all[1].name).to eq("Another cash book")
|
77
79
|
end
|
78
80
|
end
|
79
81
|
end
|
@@ -6,21 +6,21 @@ describe Economic::CreditorContactProxy do
|
|
6
6
|
|
7
7
|
describe ".new" do
|
8
8
|
it "stores session" do
|
9
|
-
subject.session.
|
9
|
+
expect(subject.session).to equal(session)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
describe ".build" do
|
14
14
|
it "instantiates a new CreditorContact" do
|
15
|
-
subject.build.
|
15
|
+
expect(subject.build).to be_instance_of(Economic::CreditorContact)
|
16
16
|
end
|
17
17
|
|
18
18
|
it "assigns the session to the CreditorContact" do
|
19
|
-
subject.build.session.
|
19
|
+
expect(subject.build.session).to equal(session)
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should not build a partial CreditorContact" do
|
23
|
-
subject.build.
|
23
|
+
expect(subject.build).to_not be_partial
|
24
24
|
end
|
25
25
|
|
26
26
|
context "when owner is a Creditor" do
|
@@ -28,38 +28,34 @@ describe Economic::CreditorContactProxy do
|
|
28
28
|
subject { creditor.contacts }
|
29
29
|
|
30
30
|
it "should use the Creditors session" do
|
31
|
-
subject.build.session.
|
31
|
+
expect(subject.build.session).to eq(creditor.session)
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should initialize with values from Creditor" do
|
35
35
|
contact = subject.build
|
36
|
-
contact.creditor_handle.
|
36
|
+
expect(contact.creditor_handle).to eq(creditor.handle)
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
41
|
describe ".find" do
|
42
|
-
before :each do
|
43
|
-
savon.stubs('CreditorContact_GetData').returns(:success)
|
44
|
-
end
|
45
|
-
|
46
42
|
it "gets contact data from API" do
|
47
|
-
|
43
|
+
mock_request('CreditorContact_GetData', {'entityHandle' => {'Id' => 42}}, :success)
|
48
44
|
subject.find(42)
|
49
45
|
end
|
50
46
|
|
51
47
|
it "returns CreditorContact object" do
|
52
|
-
|
48
|
+
stub_request('CreditorContact_GetData', nil, :success)
|
49
|
+
expect(subject.find(42)).to be_instance_of(Economic::CreditorContact)
|
53
50
|
end
|
54
51
|
end
|
55
52
|
|
56
53
|
describe "#find_by_name" do
|
57
54
|
it "uses the FindByName command" do
|
58
|
-
Economic::Proxies::Actions::FindByName.
|
55
|
+
expect(Economic::Proxies::Actions::FindByName).to receive(:new).
|
59
56
|
with(subject, "Bob").
|
60
|
-
|
61
|
-
subject.find_by_name("Bob").
|
57
|
+
and_return(lambda { "Result" })
|
58
|
+
expect(subject.find_by_name("Bob")).to eq("Result")
|
62
59
|
end
|
63
60
|
end
|
64
61
|
end
|
65
|
-
|
@@ -6,44 +6,48 @@ describe Economic::CreditorEntryProxy do
|
|
6
6
|
|
7
7
|
describe "new" do
|
8
8
|
it "stores session" do
|
9
|
-
subject.session.
|
9
|
+
expect(subject.session).to equal(session)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
describe "#find_by_invoice_number" do
|
14
14
|
it 'should be able to find multiple creditor entries' do
|
15
|
-
|
16
|
-
subject.find_by_invoice_number('123').
|
15
|
+
mock_request("CreditorEntry_FindByInvoiceNumber", {'invoiceNumber' => '123'}, :many)
|
16
|
+
expect(subject.find_by_invoice_number('123')).to eq([1, 2])
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'should handle a single serial number in the response' do
|
20
|
-
|
21
|
-
subject.find_by_invoice_number('123').
|
20
|
+
stub_request("CreditorEntry_FindByInvoiceNumber", nil, :single)
|
21
|
+
expect(subject.find_by_invoice_number('123')).to eq([1])
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
describe "#find" do
|
26
26
|
it 'should get a creditor entry by serial number' do
|
27
|
-
|
28
|
-
subject.find('123').
|
27
|
+
mock_request("CreditorEntry_GetData", {'entityHandle' => { 'SerialNumber' => '123' }}, :success)
|
28
|
+
expect(subject.find('123')).to be_instance_of(Economic::CreditorEntry)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
describe "#match" do
|
33
33
|
it 'should match two creditor entries by serial numbers' do
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
34
|
+
stub_request(
|
35
|
+
"CreditorEntry_MatchEntries",
|
36
|
+
{:entries => {
|
37
|
+
"CreditorEntryHandle" => [
|
38
|
+
{"SerialNumber"=>1},
|
39
|
+
{"SerialNumber"=>2}
|
40
|
+
]
|
41
|
+
}},
|
42
|
+
:success
|
43
|
+
)
|
40
44
|
subject.match(1, 2)
|
41
45
|
end
|
42
46
|
end
|
43
47
|
|
44
48
|
describe "#entity_class" do
|
45
49
|
it "should return Economic::CreditorEntry" do
|
46
|
-
Economic::CreditorEntryProxy.entity_class.
|
50
|
+
expect(Economic::CreditorEntryProxy.entity_class).to eq(Economic::CreditorEntry)
|
47
51
|
end
|
48
52
|
end
|
49
53
|
end
|
@@ -6,40 +6,37 @@ describe Economic::CreditorProxy do
|
|
6
6
|
|
7
7
|
describe "new" do
|
8
8
|
it "stores session" do
|
9
|
-
subject.session.
|
9
|
+
expect(subject.session).to equal(session)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
describe "find" do
|
14
|
-
before :each do
|
15
|
-
savon.stubs('Creditor_GetData').returns(:success)
|
16
|
-
end
|
17
|
-
|
18
14
|
it "gets creditor data from API" do
|
19
|
-
|
15
|
+
mock_request('Creditor_GetData', {'entityHandle' => {'Number' => 42}}, :success)
|
20
16
|
subject.find(42)
|
21
17
|
end
|
22
18
|
|
23
19
|
it "returns Creditor object" do
|
24
|
-
|
20
|
+
stub_request('Creditor_GetData', nil, :success)
|
21
|
+
expect(subject.find(42)).to be_instance_of(Economic::Creditor)
|
25
22
|
end
|
26
23
|
end
|
27
24
|
|
28
25
|
describe "find_by_number" do
|
29
26
|
it "can find a creditor" do
|
30
|
-
|
27
|
+
mock_request('Creditor_FindByNumber', {'number' => '1'}, :found)
|
31
28
|
result = subject.find_by_number('1')
|
32
|
-
result.
|
33
|
-
result.number.
|
34
|
-
result.partial.
|
35
|
-
result.persisted.
|
36
|
-
result.handle.
|
29
|
+
expect(result).to be_instance_of(Economic::Creditor)
|
30
|
+
expect(result.number).to eq(1)
|
31
|
+
expect(result.partial).to be_true
|
32
|
+
expect(result.persisted).to be_true
|
33
|
+
expect(result.handle).to eq(Economic::Entity::Handle.new({ :number => 1 }))
|
37
34
|
end
|
38
35
|
|
39
36
|
it "returns nil when there is no creditor" do
|
40
|
-
|
37
|
+
mock_request('Creditor_FindByNumber', {'number' => '1'}, :not_found)
|
41
38
|
result = subject.find_by_number('1')
|
42
|
-
result.
|
39
|
+
expect(result).to be_nil
|
43
40
|
end
|
44
41
|
end
|
45
42
|
|
@@ -47,35 +44,35 @@ describe Economic::CreditorProxy do
|
|
47
44
|
subject { session.creditors.build }
|
48
45
|
|
49
46
|
it "instantiates a new Creditor" do
|
50
|
-
subject.
|
47
|
+
expect(subject).to be_instance_of(Economic::Creditor)
|
51
48
|
end
|
52
49
|
|
53
50
|
it "assigns the session to the Creditor" do
|
54
|
-
subject.session.
|
51
|
+
expect(subject.session).to equal(session)
|
55
52
|
end
|
56
53
|
end
|
57
54
|
|
58
55
|
describe "#entity_class" do
|
59
56
|
it "should return Economic::Creditor" do
|
60
|
-
Economic::CreditorProxy.entity_class.
|
57
|
+
expect(Economic::CreditorProxy.entity_class).to eq(Economic::Creditor)
|
61
58
|
end
|
62
59
|
end
|
63
60
|
|
64
61
|
describe ".all" do
|
65
62
|
it "returns a single creditor" do
|
66
|
-
|
67
|
-
|
63
|
+
stub_request('Creditor_GetAll', nil, :single)
|
64
|
+
mock_request('Creditor_GetData', {'entityHandle' => {'Number' => 1}}, :success)
|
68
65
|
all = subject.all
|
69
|
-
all.size.
|
70
|
-
all.first.
|
66
|
+
expect(all.size).to eq(1)
|
67
|
+
expect(all.first).to be_instance_of(Economic::Creditor)
|
71
68
|
end
|
72
69
|
|
73
70
|
it "returns multiple creditors" do
|
74
|
-
|
75
|
-
|
71
|
+
mock_request('Creditor_GetAll', nil, :multiple)
|
72
|
+
stub_request('Creditor_GetDataArray', nil, :multiple)
|
76
73
|
all = subject.all
|
77
|
-
all.size.
|
78
|
-
all.first.
|
74
|
+
expect(all.size).to eq(2)
|
75
|
+
expect(all.first).to be_instance_of(Economic::Creditor)
|
79
76
|
end
|
80
77
|
end
|
81
78
|
end
|
@@ -7,11 +7,11 @@ describe Economic::CurrentInvoiceLineProxy do
|
|
7
7
|
|
8
8
|
describe "new" do
|
9
9
|
it "stores owner" do
|
10
|
-
subject.owner.
|
10
|
+
expect(subject.owner).to eq(invoice)
|
11
11
|
end
|
12
12
|
|
13
13
|
it "stores session" do
|
14
|
-
subject.session.
|
14
|
+
expect(subject.session).to eq(invoice.session)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -20,72 +20,69 @@ describe Economic::CurrentInvoiceLineProxy do
|
|
20
20
|
line = Economic::CurrentInvoiceLine.new
|
21
21
|
subject.append(line)
|
22
22
|
subject.append(line)
|
23
|
-
subject.size.
|
23
|
+
expect(subject.size).to eq(1)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
describe ".build" do
|
28
28
|
it "instantiates a new CurrentInvoiceLine" do
|
29
|
-
subject.build.
|
29
|
+
expect(subject.build).to be_instance_of(Economic::CurrentInvoiceLine)
|
30
30
|
end
|
31
31
|
|
32
32
|
it "assigns the session to the CurrentInvoiceLine" do
|
33
|
-
subject.build.session.
|
33
|
+
expect(subject.build.session).to eq(session)
|
34
34
|
end
|
35
35
|
|
36
36
|
it "should not build a partial CurrentInvoiceLine" do
|
37
|
-
subject.build.
|
37
|
+
expect(subject.build).to_not be_partial
|
38
38
|
end
|
39
39
|
|
40
40
|
it "adds the built line to proxy items" do
|
41
|
-
line = subject.build
|
42
|
-
subject.first.
|
41
|
+
line = subject.build(:number => 5)
|
42
|
+
expect(subject.first).to eq(line)
|
43
43
|
end
|
44
44
|
|
45
45
|
context "when owner is a CurrentInvoice" do
|
46
46
|
subject { invoice.lines }
|
47
47
|
|
48
48
|
it "should use the Debtors session" do
|
49
|
-
subject.build.session.
|
49
|
+
expect(subject.build.session).to eq(invoice.session)
|
50
50
|
end
|
51
51
|
|
52
52
|
it "should initialize with values from CurrentInvoice" do
|
53
53
|
invoice_line = subject.build
|
54
|
-
invoice_line.invoice_handle.
|
54
|
+
expect(invoice_line.invoice_handle).to eq(invoice.handle)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
59
|
describe ".find" do
|
60
|
-
before :each do
|
61
|
-
savon.stubs('CurrentInvoiceLine_GetData').returns(:success)
|
62
|
-
end
|
63
|
-
|
64
60
|
it "gets invoice_line data from API" do
|
65
|
-
|
61
|
+
mock_request('CurrentInvoiceLine_GetData', {'entityHandle' => {'Number' => 42}}, :success)
|
66
62
|
subject.find(42)
|
67
63
|
end
|
68
64
|
|
69
65
|
it "returns CurrentInvoiceLine object" do
|
70
|
-
|
66
|
+
stub_request('CurrentInvoiceLine_GetData', nil, :success)
|
67
|
+
expect(subject.find(42)).to be_instance_of(Economic::CurrentInvoiceLine)
|
71
68
|
end
|
72
69
|
end
|
73
70
|
|
74
71
|
describe "enumerable" do
|
75
72
|
it "can be empty" do
|
76
|
-
subject.
|
73
|
+
expect(subject).to be_empty
|
77
74
|
end
|
78
75
|
|
79
76
|
it "can be appended to" do
|
80
|
-
line = Economic::CurrentInvoiceLine.new
|
77
|
+
line = Economic::CurrentInvoiceLine.new(:number => 5)
|
81
78
|
subject << line
|
82
|
-
subject.last.
|
79
|
+
expect(subject.last).to eq(line)
|
83
80
|
end
|
84
81
|
|
85
82
|
it "can be iterated over" do
|
86
83
|
line = Economic::CurrentInvoiceLine.new
|
87
84
|
subject << line
|
88
|
-
subject.all? { |l| l.is_a?(Economic::CurrentInvoiceLine) }.
|
85
|
+
expect(subject.all? { |l| l.is_a?(Economic::CurrentInvoiceLine) }).to be_true
|
89
86
|
end
|
90
87
|
end
|
91
88
|
end
|
@@ -7,21 +7,21 @@ describe Economic::CurrentInvoiceProxy do
|
|
7
7
|
|
8
8
|
describe ".new" do
|
9
9
|
it "stores session" do
|
10
|
-
subject.session.
|
10
|
+
expect(subject.session).to equal(session)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
14
|
describe ".build" do
|
15
15
|
it "instantiates a new CurrentInvoice" do
|
16
|
-
subject.build.
|
16
|
+
expect(subject.build).to be_instance_of(Economic::CurrentInvoice)
|
17
17
|
end
|
18
18
|
|
19
19
|
it "assigns the session to the CurrentInvoice" do
|
20
|
-
subject.build.session.
|
20
|
+
expect(subject.build.session).to equal(session)
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should not build a partial CurrentInvoice" do
|
24
|
-
subject.build.
|
24
|
+
expect(subject.build).to_not be_partial
|
25
25
|
end
|
26
26
|
|
27
27
|
context "when owner is a Debtor" do
|
@@ -29,37 +29,34 @@ describe Economic::CurrentInvoiceProxy do
|
|
29
29
|
subject { debtor.current_invoices }
|
30
30
|
|
31
31
|
it "should use the Debtors session" do
|
32
|
-
subject.build.session.
|
32
|
+
expect(subject.build.session).to eq(debtor.session)
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should initialize with values from Debtor" do
|
36
36
|
invoice = subject.build
|
37
37
|
|
38
|
-
invoice.debtor_name.
|
39
|
-
invoice.debtor_address.
|
40
|
-
invoice.debtor_postal_code.
|
41
|
-
invoice.debtor_city.
|
38
|
+
expect(invoice.debtor_name).to eq(debtor.name)
|
39
|
+
expect(invoice.debtor_address).to eq(debtor.address)
|
40
|
+
expect(invoice.debtor_postal_code).to eq(debtor.postal_code)
|
41
|
+
expect(invoice.debtor_city).to eq(debtor.city)
|
42
42
|
|
43
|
-
invoice.debtor_handle.
|
44
|
-
invoice.term_of_payment_handle.
|
45
|
-
invoice.layout_handle.
|
46
|
-
invoice.currency_handle.
|
43
|
+
expect(invoice.debtor_handle).to eq(debtor.handle)
|
44
|
+
expect(invoice.term_of_payment_handle).to eq(debtor.term_of_payment_handle)
|
45
|
+
expect(invoice.layout_handle).to eq(debtor.layout_handle)
|
46
|
+
expect(invoice.currency_handle).to eq(debtor.currency_handle)
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
51
|
describe ".find" do
|
52
|
-
before :each do
|
53
|
-
savon.stubs('CurrentInvoice_GetData').returns(:success)
|
54
|
-
end
|
55
|
-
|
56
52
|
it "gets invoice data from API" do
|
57
|
-
|
53
|
+
mock_request('CurrentInvoice_GetData', {'entityHandle' => {'Id' => 42}}, :success)
|
58
54
|
subject.find(42)
|
59
55
|
end
|
60
56
|
|
61
57
|
it "returns CurrentInvoice object" do
|
62
|
-
|
58
|
+
stub_request('CurrentInvoice_GetData', nil, :success)
|
59
|
+
expect(subject.find(42)).to be_instance_of(Economic::CurrentInvoice)
|
63
60
|
end
|
64
61
|
end
|
65
62
|
|
@@ -68,25 +65,25 @@ describe Economic::CurrentInvoiceProxy do
|
|
68
65
|
let(:unto) { Time.now }
|
69
66
|
|
70
67
|
it "should be able to return a single current invoice" do
|
71
|
-
|
72
|
-
|
68
|
+
mock_request('CurrentInvoice_FindByDateInterval', {'first' => from.iso8601, 'last' => unto.iso8601}, :single)
|
69
|
+
stub_request('CurrentInvoice_GetDataArray', nil, :single)
|
73
70
|
results = subject.find_by_date_interval(from, unto)
|
74
|
-
results.size.
|
75
|
-
results.first.
|
71
|
+
expect(results.size).to eq(1)
|
72
|
+
expect(results.first).to be_instance_of(Economic::CurrentInvoice)
|
76
73
|
end
|
77
74
|
|
78
75
|
it "should be able to return multiple invoices" do
|
79
|
-
|
80
|
-
|
76
|
+
mock_request('CurrentInvoice_FindByDateInterval', {'first' => from.iso8601, 'last' => unto.iso8601}, :many)
|
77
|
+
stub_request('CurrentInvoice_GetDataArray', nil, :multiple)
|
81
78
|
results = subject.find_by_date_interval(from, unto)
|
82
|
-
results.size.
|
83
|
-
results.first.
|
79
|
+
expect(results.size).to eq(2)
|
80
|
+
expect(results.first).to be_instance_of(Economic::CurrentInvoice)
|
84
81
|
end
|
85
82
|
|
86
83
|
it "should be able to return nothing" do
|
87
|
-
|
84
|
+
mock_request('CurrentInvoice_FindByDateInterval', {'first' => from.iso8601, 'last' => unto.iso8601}, :none)
|
88
85
|
results = subject.find_by_date_interval(from, unto)
|
89
|
-
results.size.
|
86
|
+
expect(results.size).to eq(0)
|
90
87
|
end
|
91
88
|
|
92
89
|
end
|
@@ -94,29 +91,29 @@ describe Economic::CurrentInvoiceProxy do
|
|
94
91
|
describe ".all" do
|
95
92
|
|
96
93
|
it "returns an empty array when there are no current invoices" do
|
97
|
-
|
98
|
-
subject.all.size.
|
94
|
+
stub_request('CurrentInvoice_GetAll', nil, :none)
|
95
|
+
expect(subject.all.size).to eq(0)
|
99
96
|
end
|
100
97
|
|
101
98
|
it "finds and adds a single current invoice" do
|
102
|
-
|
103
|
-
|
99
|
+
stub_request('CurrentInvoice_GetAll', nil, :single)
|
100
|
+
mock_request('CurrentInvoice_GetData', {'entityHandle' => {'Id' => 1}}, :success)
|
104
101
|
|
105
102
|
current_invoices = subject.all
|
106
|
-
current_invoices.
|
103
|
+
expect(current_invoices).to be_instance_of(Economic::CurrentInvoiceProxy)
|
107
104
|
|
108
|
-
current_invoices.size.
|
109
|
-
current_invoices.first.
|
105
|
+
expect(current_invoices.size).to eq(1)
|
106
|
+
expect(current_invoices.first).to be_instance_of(Economic::CurrentInvoice)
|
110
107
|
end
|
111
108
|
|
112
109
|
it "adds multiple current invoices" do
|
113
|
-
|
114
|
-
|
110
|
+
stub_request('CurrentInvoice_GetAll', nil, :multiple)
|
111
|
+
stub_request('CurrentInvoice_GetDataArray', nil, :multiple)
|
115
112
|
|
116
113
|
current_invoices = subject.all
|
117
|
-
current_invoices.size.
|
118
|
-
current_invoices.first.
|
119
|
-
current_invoices.last.
|
114
|
+
expect(current_invoices.size).to eq(2)
|
115
|
+
expect(current_invoices.first).to be_instance_of(Economic::CurrentInvoice)
|
116
|
+
expect(current_invoices.last).to be_instance_of(Economic::CurrentInvoice)
|
120
117
|
end
|
121
118
|
|
122
119
|
end
|