rconomic 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.travis.yml +1 -2
- data/Gemfile +1 -0
- data/README.md +6 -1
- data/lib/economic/account.rb +5 -7
- data/lib/economic/cash_book.rb +8 -10
- data/lib/economic/cash_book_entry.rb +1 -1
- data/lib/economic/creditor.rb +1 -1
- data/lib/economic/creditor_contact.rb +2 -2
- data/lib/economic/current_invoice.rb +10 -13
- data/lib/economic/current_invoice_line.rb +3 -3
- data/lib/economic/debtor.rb +1 -1
- data/lib/economic/debtor_contact.rb +2 -2
- data/lib/economic/entity.rb +19 -19
- data/lib/economic/invoice.rb +6 -6
- data/lib/economic/proxies/account_proxy.rb +4 -6
- data/lib/economic/proxies/actions/find_by_ci_number.rb +3 -5
- data/lib/economic/proxies/actions/find_by_date_interval.rb +4 -7
- data/lib/economic/proxies/actions/find_by_name.rb +71 -0
- data/lib/economic/proxies/actions/find_by_number.rb +3 -5
- data/lib/economic/proxies/cash_book_entry_proxy.rb +16 -13
- data/lib/economic/proxies/cash_book_proxy.rb +7 -23
- data/lib/economic/proxies/creditor_contact_proxy.rb +6 -49
- data/lib/economic/proxies/creditor_entry_proxy.rb +13 -19
- data/lib/economic/proxies/creditor_proxy.rb +6 -8
- data/lib/economic/proxies/current_invoice_line_proxy.rb +3 -9
- data/lib/economic/proxies/current_invoice_proxy.rb +12 -20
- data/lib/economic/proxies/debtor_contact_proxy.rb +6 -49
- data/lib/economic/proxies/debtor_entry_proxy.rb +9 -14
- data/lib/economic/proxies/debtor_proxy.rb +1 -1
- data/lib/economic/proxies/entity_proxy.rb +21 -20
- data/lib/economic/proxies/entry_proxy.rb +14 -20
- data/lib/economic/session.rb +21 -12
- data/lib/economic/support/string.rb +5 -1
- data/lib/rconomic.rb +2 -1
- data/lib/rconomic/version.rb +1 -1
- data/rconomic.gemspec +0 -2
- data/spec/economic/current_invoice_spec.rb +1 -1
- data/spec/economic/entity_spec.rb +4 -3
- data/spec/economic/proxies/actions/find_by_name_spec.rb +48 -0
- data/spec/economic/proxies/cash_book_proxy_spec.rb +30 -5
- data/spec/economic/proxies/creditor_contact_proxy_spec.rb +10 -0
- data/spec/economic/proxies/current_invoice_line_proxy_spec.rb +3 -3
- data/spec/economic/proxies/current_invoice_proxy_spec.rb +5 -5
- data/spec/economic/proxies/debtor_contact_proxy_spec.rb +10 -1
- data/spec/economic/proxies/debtor_entry_proxy_spec.rb +2 -2
- data/spec/economic/proxies/invoice_proxy_spec.rb +3 -3
- data/spec/economic/session_spec.rb +44 -3
- data/spec/fixtures/cash_book_get_data/success.xml +14 -0
- data/spec/fixtures/cash_book_get_data_array/multiple.xml +23 -0
- data/spec/fixtures/creditor_contact_find_by_name/multiple.xml +15 -0
- data/spec/fixtures/creditor_contact_find_by_name/none.xml +9 -0
- data/spec/fixtures/debtor_contact_find_by_name/multiple.xml +15 -0
- data/spec/fixtures/debtor_contact_find_by_name/none.xml +9 -0
- data/spec/spec_helper.rb +6 -0
- metadata +10 -16
@@ -3,12 +3,10 @@ require 'economic/proxies/entity_proxy'
|
|
3
3
|
module Economic
|
4
4
|
class EntryProxy < EntityProxy
|
5
5
|
def find_by_date_interval(from_date, to_date)
|
6
|
-
response =
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
}
|
11
|
-
end
|
6
|
+
response = request('FindByDateInterval', {
|
7
|
+
'fromDate' => from_date,
|
8
|
+
'toDate' => to_date
|
9
|
+
})
|
12
10
|
|
13
11
|
build_array(response)
|
14
12
|
end
|
@@ -19,29 +17,25 @@ module Economic
|
|
19
17
|
# max_number = 2**31 - 1 # Maximum int32.
|
20
18
|
#
|
21
19
|
def find_by_serial_number_interval(min_number, max_number)
|
22
|
-
response =
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
}
|
27
|
-
end
|
20
|
+
response = request('FindBySerialNumberInterval', {
|
21
|
+
'minNumber' => min_number,
|
22
|
+
'maxNumber' => max_number
|
23
|
+
})
|
28
24
|
|
29
25
|
build_array(response)
|
30
26
|
end
|
31
27
|
|
32
28
|
def get_last_used_serial_number
|
33
|
-
response =
|
29
|
+
response = request('GetLastUsedSerialNumber')
|
34
30
|
response.to_i
|
35
31
|
end
|
36
32
|
|
37
33
|
def find(serial_number)
|
38
|
-
response =
|
39
|
-
|
40
|
-
'
|
41
|
-
|
42
|
-
|
43
|
-
}
|
44
|
-
end
|
34
|
+
response = request('GetData', {
|
35
|
+
'entityHandle' => {
|
36
|
+
'SerialNumber' => serial_number
|
37
|
+
}
|
38
|
+
})
|
45
39
|
|
46
40
|
build(response)
|
47
41
|
end
|
data/lib/economic/session.rb
CHANGED
@@ -8,24 +8,18 @@ module Economic
|
|
8
8
|
self.password = password
|
9
9
|
end
|
10
10
|
|
11
|
-
# Returns the Savon::Client used to connect to e-conomic
|
12
|
-
def client
|
13
|
-
@client ||= Savon::Client.new do
|
14
|
-
wsdl.document = File.expand_path(File.join(File.dirname(__FILE__), "economic.wsdl"))
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
11
|
# Authenticates with e-conomic
|
19
12
|
def connect
|
13
|
+
client.http.headers.delete("Cookie")
|
20
14
|
response = client.request :economic, :connect do
|
21
15
|
soap.body = {
|
22
16
|
:agreementNumber => self.agreement_number,
|
23
17
|
:userName => self.user_name,
|
24
|
-
:password => self.password
|
25
|
-
:order! => [:agreementNumber, :userName, :password]
|
18
|
+
:password => self.password
|
26
19
|
}
|
27
20
|
end
|
28
|
-
|
21
|
+
|
22
|
+
@cookie = response.http.headers["Set-Cookie"]
|
29
23
|
end
|
30
24
|
|
31
25
|
# Provides access to the DebtorContacts
|
@@ -77,8 +71,13 @@ module Economic
|
|
77
71
|
@entries ||= EntryProxy.new(self)
|
78
72
|
end
|
79
73
|
|
80
|
-
|
81
|
-
|
74
|
+
# Requests an action from the API endpoint
|
75
|
+
def request(action, data = nil)
|
76
|
+
client.http.headers["Cookie"] = @cookie
|
77
|
+
|
78
|
+
response = client.request(:economic, action) do
|
79
|
+
soap.body = data if data
|
80
|
+
end
|
82
81
|
response_hash = response.to_hash
|
83
82
|
|
84
83
|
response_key = "#{action}_response".intern
|
@@ -94,5 +93,15 @@ module Economic
|
|
94
93
|
def session
|
95
94
|
self
|
96
95
|
end
|
96
|
+
|
97
|
+
private
|
98
|
+
|
99
|
+
# Returns the Savon::Client used to connect to e-conomic
|
100
|
+
# Cached on class-level to avoid loading the big wsdl file more than once (can take several hunder megabytes of ram after a while...)
|
101
|
+
def client
|
102
|
+
@@client ||= Savon::Client.new do
|
103
|
+
wsdl.document = File.expand_path(File.join(File.dirname(__FILE__), "economic.wsdl"))
|
104
|
+
end
|
105
|
+
end
|
97
106
|
end
|
98
107
|
end
|
@@ -1,6 +1,10 @@
|
|
1
1
|
module Economic
|
2
2
|
module Support
|
3
3
|
module String
|
4
|
+
def self.camel_back(name)
|
5
|
+
name[0,1].downcase + name[1..-1]
|
6
|
+
end
|
7
|
+
|
4
8
|
def self.demodulize(class_name_in_module)
|
5
9
|
class_name_in_module.to_s.gsub(/^.*::/, '')
|
6
10
|
end
|
@@ -21,4 +25,4 @@ module Economic
|
|
21
25
|
end
|
22
26
|
end
|
23
27
|
end
|
24
|
-
end
|
28
|
+
end
|
data/lib/rconomic.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# Dependencies
|
2
2
|
require 'time'
|
3
3
|
require 'savon'
|
4
|
-
require 'active_support/ordered_hash'
|
5
4
|
|
6
5
|
require 'economic/support/string'
|
7
6
|
require 'economic/session'
|
@@ -34,6 +33,8 @@ require 'economic/proxies/debtor_entry_proxy'
|
|
34
33
|
require 'economic/proxies/creditor_entry_proxy'
|
35
34
|
require 'economic/proxies/entry_proxy'
|
36
35
|
|
36
|
+
require 'economic/proxies/actions/find_by_name'
|
37
|
+
|
37
38
|
# http://www.e-conomic.com/apidocs/Documentation/index.html
|
38
39
|
# https://www.e-conomic.com/secure/api1/EconomicWebService.asmx
|
39
40
|
#
|
data/lib/rconomic/version.rb
CHANGED
data/rconomic.gemspec
CHANGED
@@ -23,8 +23,6 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.add_runtime_dependency "savon", "0.9.5"
|
24
24
|
s.add_runtime_dependency "gyoku", "0.4.4"
|
25
25
|
|
26
|
-
s.add_runtime_dependency "activesupport", "~> 3.0"
|
27
|
-
|
28
26
|
s.files = `git ls-files`.split("\n").reject { |filename| ['.gitignore'].include?(filename) }
|
29
27
|
s.test_files = `git ls-files -- {spec}/*`.split("\n")
|
30
28
|
s.require_paths = ["lib"]
|
@@ -116,7 +116,7 @@ describe Economic::CurrentInvoice do
|
|
116
116
|
|
117
117
|
it 'should request with the right key for handle' do
|
118
118
|
savon.stubs('Invoice_GetData').returns(:success)
|
119
|
-
savon.expects("CurrentInvoice_BookWithNumber").with('currentInvoiceHandle' => { 'Id' => 512 }, 'number' => 123
|
119
|
+
savon.expects("CurrentInvoice_BookWithNumber").with('currentInvoiceHandle' => { 'Id' => 512 }, 'number' => 123).returns(:success)
|
120
120
|
subject.book_with_number(123)
|
121
121
|
end
|
122
122
|
end
|
@@ -3,6 +3,7 @@ require './spec/spec_helper'
|
|
3
3
|
class SpecEntity < Economic::Entity
|
4
4
|
has_properties :id, :foo, :baz
|
5
5
|
|
6
|
+
def build_soap_data; {}; end
|
6
7
|
def existing_method; end
|
7
8
|
|
8
9
|
def proxy; Economic::SpecEntityProxy.new(session); end
|
@@ -75,11 +76,11 @@ describe Economic::Entity do
|
|
75
76
|
|
76
77
|
describe "soap_action" do
|
77
78
|
it "returns the name for the given soap action on this class" do
|
78
|
-
subject.
|
79
|
+
subject.soap_action_name(:get_data).should == :spec_entity_get_data
|
79
80
|
|
80
81
|
class Car < Economic::Entity; end
|
81
|
-
Car.
|
82
|
-
Car.
|
82
|
+
Car.soap_action_name(:start_engine).should == :car_start_engine
|
83
|
+
Car.soap_action_name('StartEngine').should == :car_start_engine
|
83
84
|
end
|
84
85
|
end
|
85
86
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require './spec/spec_helper'
|
2
|
+
|
3
|
+
describe Economic::Proxies::Actions::FindByName do
|
4
|
+
let(:session) { make_session }
|
5
|
+
let(:proxy) { Economic::CreditorContactProxy.new(session) }
|
6
|
+
|
7
|
+
subject {
|
8
|
+
Economic::Proxies::Actions::FindByName.new(proxy, "Bob")
|
9
|
+
}
|
10
|
+
|
11
|
+
describe "#call" do
|
12
|
+
before :each do
|
13
|
+
savon.stubs('CreditorContact_FindByName').returns(:multiple)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "gets contact data from the API" do
|
17
|
+
savon.expects('CreditorContact_FindByName').with('name' => 'Bob').returns(:multiple)
|
18
|
+
subject.call
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns creditor contacts" do
|
22
|
+
subject.call.first.should be_instance_of(Economic::CreditorContact)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns empty when nothing is found" do
|
26
|
+
savon.stubs('CreditorContact_FindByName').returns(:none)
|
27
|
+
subject.call.should be_empty
|
28
|
+
end
|
29
|
+
|
30
|
+
context "when calling proxy is owned by session" do
|
31
|
+
it "returns all creditor contacts" do
|
32
|
+
subject.call.size.should == 2
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "when calling proxy is owned by a creditor" do
|
37
|
+
it "returns only contacts for creditor" do
|
38
|
+
savon.stubs("CreditorContact_GetData").returns(:success)
|
39
|
+
savon.stubs("Creditor_GetData").returns(:success)
|
40
|
+
creditor = session.creditors.build
|
41
|
+
proxy = Economic::CreditorContactProxy.new(creditor)
|
42
|
+
action = Economic::Proxies::Actions::FindByName.new(proxy, "Bob")
|
43
|
+
action.call.each { |contact| contact.creditor.should == creditor }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -28,15 +28,23 @@ describe Economic::CashBookProxy do
|
|
28
28
|
describe ".all" do
|
29
29
|
|
30
30
|
it "returns multiple cashbooks" do
|
31
|
-
savon.
|
32
|
-
savon.
|
33
|
-
|
31
|
+
savon.stubs('CashBook_GetAll').returns(:multiple)
|
32
|
+
savon.stubs('CashBook_GetDataArray').returns(:multiple)
|
33
|
+
|
34
34
|
all = subject.all
|
35
35
|
all.size.should == 2
|
36
|
-
all
|
37
|
-
all[1].should be_instance_of(Economic::CashBook)
|
36
|
+
all.each { |cash_book| cash_book.should be_instance_of(Economic::CashBook) }
|
38
37
|
end
|
39
38
|
|
39
|
+
it "properly fills out handles of cash books" do
|
40
|
+
# Issue #12
|
41
|
+
savon.stubs('CashBook_GetAll').returns(:multiple)
|
42
|
+
savon.stubs('CashBook_GetData').returns(:success)
|
43
|
+
savon.stubs('CashBook_GetDataArray').returns(:multiple)
|
44
|
+
|
45
|
+
cash_book = subject.find(subject.all.first.handle)
|
46
|
+
subject.all.first.handle.should == cash_book.handle
|
47
|
+
end
|
40
48
|
end
|
41
49
|
|
42
50
|
describe ".get_name" do
|
@@ -51,4 +59,21 @@ describe Economic::CashBookProxy do
|
|
51
59
|
|
52
60
|
end
|
53
61
|
|
62
|
+
describe "#last" do
|
63
|
+
it "returns the last cash book" do
|
64
|
+
savon.stubs('CashBook_GetAll').returns(:multiple)
|
65
|
+
savon.stubs('CashBook_GetDataArray').returns(:multiple)
|
66
|
+
|
67
|
+
subject.all.last.name.should == "Another cash book"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "#[]" do
|
72
|
+
it "returns the specific cash book" do
|
73
|
+
savon.stubs('CashBook_GetAll').returns(:multiple)
|
74
|
+
savon.stubs('CashBook_GetDataArray').returns(:multiple)
|
75
|
+
|
76
|
+
subject.all[1].name.should == "Another cash book"
|
77
|
+
end
|
78
|
+
end
|
54
79
|
end
|
@@ -52,4 +52,14 @@ describe Economic::CreditorContactProxy do
|
|
52
52
|
subject.find(42).should be_instance_of(Economic::CreditorContact)
|
53
53
|
end
|
54
54
|
end
|
55
|
+
|
56
|
+
describe "#find_by_name" do
|
57
|
+
it "uses the FindByName command" do
|
58
|
+
Economic::Proxies::Actions::FindByName.expects(:new).
|
59
|
+
with(subject, "Bob").
|
60
|
+
returns(lambda { "Result" })
|
61
|
+
subject.find_by_name("Bob").should == "Result"
|
62
|
+
end
|
63
|
+
end
|
55
64
|
end
|
65
|
+
|
@@ -20,7 +20,7 @@ describe Economic::CurrentInvoiceLineProxy do
|
|
20
20
|
line = Economic::CurrentInvoiceLine.new
|
21
21
|
subject.append(line)
|
22
22
|
subject.append(line)
|
23
|
-
subject.
|
23
|
+
subject.size.should == 1
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -39,7 +39,7 @@ describe Economic::CurrentInvoiceLineProxy do
|
|
39
39
|
|
40
40
|
it "adds the built line to proxy items" do
|
41
41
|
line = subject.build
|
42
|
-
subject.
|
42
|
+
subject.first.should == line
|
43
43
|
end
|
44
44
|
|
45
45
|
context "when owner is a CurrentInvoice" do
|
@@ -79,7 +79,7 @@ describe Economic::CurrentInvoiceLineProxy do
|
|
79
79
|
it "can be appended to" do
|
80
80
|
line = Economic::CurrentInvoiceLine.new
|
81
81
|
subject << line
|
82
|
-
subject.
|
82
|
+
subject.last.should == line
|
83
83
|
end
|
84
84
|
|
85
85
|
it "can be iterated over" do
|
@@ -68,7 +68,7 @@ describe Economic::CurrentInvoiceProxy do
|
|
68
68
|
let(:unto) { Time.now }
|
69
69
|
|
70
70
|
it "should be able to return a single current invoice" do
|
71
|
-
savon.expects('CurrentInvoice_FindByDateInterval').with('first' => from.iso8601, 'last' => unto.iso8601
|
71
|
+
savon.expects('CurrentInvoice_FindByDateInterval').with('first' => from.iso8601, 'last' => unto.iso8601).returns(:single)
|
72
72
|
savon.expects('CurrentInvoice_GetDataArray').returns(:single)
|
73
73
|
results = subject.find_by_date_interval(from, unto)
|
74
74
|
results.size.should == 1
|
@@ -76,7 +76,7 @@ describe Economic::CurrentInvoiceProxy do
|
|
76
76
|
end
|
77
77
|
|
78
78
|
it "should be able to return multiple invoices" do
|
79
|
-
savon.expects('CurrentInvoice_FindByDateInterval').with('first' => from.iso8601, 'last' => unto.iso8601
|
79
|
+
savon.expects('CurrentInvoice_FindByDateInterval').with('first' => from.iso8601, 'last' => unto.iso8601).returns(:many)
|
80
80
|
savon.expects('CurrentInvoice_GetDataArray').returns(:multiple)
|
81
81
|
results = subject.find_by_date_interval(from, unto)
|
82
82
|
results.size.should == 2
|
@@ -84,7 +84,7 @@ describe Economic::CurrentInvoiceProxy do
|
|
84
84
|
end
|
85
85
|
|
86
86
|
it "should be able to return nothing" do
|
87
|
-
savon.expects('CurrentInvoice_FindByDateInterval').with('first' => from.iso8601, 'last' => unto.iso8601
|
87
|
+
savon.expects('CurrentInvoice_FindByDateInterval').with('first' => from.iso8601, 'last' => unto.iso8601).returns(:none)
|
88
88
|
results = subject.find_by_date_interval(from, unto)
|
89
89
|
results.size.should == 0
|
90
90
|
end
|
@@ -115,8 +115,8 @@ describe Economic::CurrentInvoiceProxy do
|
|
115
115
|
|
116
116
|
current_invoices = subject.all
|
117
117
|
current_invoices.size.should == 2
|
118
|
-
current_invoices.
|
119
|
-
current_invoices.
|
118
|
+
current_invoices.first.should be_instance_of(Economic::CurrentInvoice)
|
119
|
+
current_invoices.last.should be_instance_of(Economic::CurrentInvoice)
|
120
120
|
end
|
121
121
|
|
122
122
|
end
|
@@ -52,4 +52,13 @@ describe Economic::DebtorContactProxy do
|
|
52
52
|
subject.find(42).should be_instance_of(Economic::DebtorContact)
|
53
53
|
end
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
|
+
describe "#find_by_name" do
|
57
|
+
it "uses the FindByName command" do
|
58
|
+
Economic::Proxies::Actions::FindByName.expects(:new).
|
59
|
+
with(subject, "Bob").
|
60
|
+
returns(lambda { "Result" })
|
61
|
+
subject.find_by_name("Bob").should == "Result"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -12,12 +12,12 @@ describe Economic::DebtorEntryProxy do
|
|
12
12
|
|
13
13
|
describe "#find_by_invoice_number" do
|
14
14
|
it 'should be able to find multiple debtor entries' do
|
15
|
-
savon.expects("DebtorEntry_FindByInvoiceNumber").with('from' => '123', 'to' => '456'
|
15
|
+
savon.expects("DebtorEntry_FindByInvoiceNumber").with('from' => '123', 'to' => '456').returns(:many)
|
16
16
|
subject.find_by_invoice_number('123', '456').should == [1, 2]
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'should be able to find debtor entries with one invoice id' do
|
20
|
-
savon.expects("DebtorEntry_FindByInvoiceNumber").with('from' => '123', 'to' => '123'
|
20
|
+
savon.expects("DebtorEntry_FindByInvoiceNumber").with('from' => '123', 'to' => '123').returns(:many)
|
21
21
|
subject.find_by_invoice_number('123').should == [1, 2]
|
22
22
|
end
|
23
23
|
|
@@ -45,7 +45,7 @@ describe Economic::InvoiceProxy do
|
|
45
45
|
let(:unto) { Time.now }
|
46
46
|
|
47
47
|
it "should be able to return a single current invoice" do
|
48
|
-
savon.expects('Invoice_FindByDateInterval').with('first' => from.iso8601, 'last' => unto.iso8601
|
48
|
+
savon.expects('Invoice_FindByDateInterval').with('first' => from.iso8601, 'last' => unto.iso8601).returns(:single)
|
49
49
|
savon.expects('Invoice_GetDataArray').returns(:single)
|
50
50
|
results = subject.find_by_date_interval(from, unto)
|
51
51
|
results.size.should == 1
|
@@ -53,7 +53,7 @@ describe Economic::InvoiceProxy do
|
|
53
53
|
end
|
54
54
|
|
55
55
|
it "should be able to return multiple invoices" do
|
56
|
-
savon.expects('Invoice_FindByDateInterval').with('first' => from.iso8601, 'last' => unto.iso8601
|
56
|
+
savon.expects('Invoice_FindByDateInterval').with('first' => from.iso8601, 'last' => unto.iso8601).returns(:many)
|
57
57
|
savon.expects('Invoice_GetDataArray').returns(:multiple)
|
58
58
|
results = subject.find_by_date_interval(from, unto)
|
59
59
|
results.size.should == 2
|
@@ -61,7 +61,7 @@ describe Economic::InvoiceProxy do
|
|
61
61
|
end
|
62
62
|
|
63
63
|
it "should be able to return nothing" do
|
64
|
-
savon.expects('Invoice_FindByDateInterval').with('first' => from.iso8601, 'last' => unto.iso8601
|
64
|
+
savon.expects('Invoice_FindByDateInterval').with('first' => from.iso8601, 'last' => unto.iso8601).returns(:none)
|
65
65
|
results = subject.find_by_date_interval(from, unto)
|
66
66
|
results.size.should == 0
|
67
67
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require './spec/spec_helper'
|
2
2
|
|
3
3
|
describe Economic::Session do
|
4
|
+
let(:client) { subject.send(:client) }
|
5
|
+
|
4
6
|
subject { Economic::Session.new(123456, 'api', 'passw0rd') }
|
5
7
|
|
6
8
|
describe "new" do
|
@@ -15,7 +17,7 @@ describe Economic::Session do
|
|
15
17
|
subject { Economic::Session.new(123456, 'api', 'passw0rd') }
|
16
18
|
|
17
19
|
it "returns a Savon::Client" do
|
18
|
-
|
20
|
+
client.should be_instance_of(::Savon::Client)
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
@@ -25,10 +27,30 @@ describe Economic::Session do
|
|
25
27
|
subject.connect
|
26
28
|
end
|
27
29
|
|
28
|
-
it "stores the cookie for later
|
30
|
+
it "stores the cookie for later requests" do
|
31
|
+
savon.expects('Connect').returns({:headers => {'Set-Cookie' => 'cookie'}})
|
32
|
+
subject.connect
|
33
|
+
client.stubs(:request).returns({})
|
34
|
+
subject.request(:foo) { }
|
35
|
+
client.http.headers['Cookie'].should == 'cookie'
|
36
|
+
end
|
37
|
+
|
38
|
+
it "updates the cookie for new sessions" do
|
29
39
|
savon.expects('Connect').returns({:headers => {'Set-Cookie' => 'cookie'}})
|
30
40
|
subject.connect
|
31
|
-
|
41
|
+
other_session = Economic::Session.new(123456, 'api', 'passw0rd')
|
42
|
+
savon.expects('Connect').returns({:headers => {'Set-Cookie' => 'other-cookie'}})
|
43
|
+
other_session.connect
|
44
|
+
|
45
|
+
client.stubs(:request).returns({})
|
46
|
+
subject.request(:foo) { }
|
47
|
+
client.http.headers['Cookie'].should == 'cookie'
|
48
|
+
end
|
49
|
+
|
50
|
+
it "removes existing cookie header before connecting" do
|
51
|
+
client.http.headers.expects(:delete).with('Cookie')
|
52
|
+
savon.stubs('Connect').returns({:headers => {'Set-Cookie' => 'cookie'}})
|
53
|
+
subject.connect
|
32
54
|
end
|
33
55
|
end
|
34
56
|
|
@@ -79,6 +101,25 @@ describe Economic::Session do
|
|
79
101
|
end
|
80
102
|
|
81
103
|
describe "request" do
|
104
|
+
it "sends a request to API" do
|
105
|
+
client.expects(:request).with(:economic, :foo).returns({})
|
106
|
+
subject.request(:foo, {})
|
107
|
+
end
|
108
|
+
|
109
|
+
it "sends data if given" do
|
110
|
+
savon.expects('CurrentInvoice_GetAll').with(:bar => :baz).returns(:none)
|
111
|
+
subject.request(:current_invoice_get_all, {:bar => :baz})
|
112
|
+
end
|
113
|
+
|
114
|
+
it "returns a hash with data" do
|
115
|
+
savon.stubs('CurrentInvoice_GetAll').returns(:single)
|
116
|
+
subject.request(:current_invoice_get_all).should == {:current_invoice_handle => {:id => "1"}}
|
117
|
+
end
|
118
|
+
|
119
|
+
it "returns an empty hash if no data returned" do
|
120
|
+
savon.stubs('CurrentInvoice_GetAll').returns(:none)
|
121
|
+
subject.request(:current_invoice_get_all).should be_empty
|
122
|
+
end
|
82
123
|
end
|
83
124
|
|
84
125
|
end
|