rconomic 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/LICENSE +6 -4
- data/README.md +19 -8
- data/Rakefile +9 -1
- data/lib/economic/account.rb +6 -6
- data/lib/economic/cash_book.rb +6 -6
- data/lib/economic/creditor.rb +26 -27
- data/lib/economic/current_invoice.rb +26 -1
- data/lib/economic/current_invoice_line.rb +17 -21
- data/lib/economic/debtor.rb +16 -5
- data/lib/economic/economic.wsdl +28493 -23200
- data/lib/economic/endpoint.rb +8 -1
- data/lib/economic/entity/handle.rb +2 -1
- data/lib/economic/invoice.rb +1 -0
- data/lib/economic/order.rb +66 -0
- data/lib/economic/proxies/actions/find_by_number.rb +1 -1
- data/lib/economic/proxies/actions/find_by_telephone_and_fax_number.rb +18 -0
- data/lib/economic/proxies/debtor_proxy.rb +63 -0
- data/lib/economic/proxies/entity_proxy.rb +0 -1
- data/lib/economic/proxies/order_proxy.rb +18 -0
- data/lib/economic/session.rb +37 -12
- data/lib/rconomic.rb +2 -0
- data/lib/rconomic/version.rb +1 -1
- data/rconomic.gemspec +1 -1
- data/spec/economic/account_spec.rb +34 -0
- data/spec/economic/cash_book_spec.rb +28 -0
- data/spec/economic/creditor_spec.rb +19 -0
- data/spec/economic/current_invoice_line_spec.rb +21 -0
- data/spec/economic/debtor_spec.rb +33 -8
- data/spec/economic/endpoint_spec.rb +18 -0
- data/spec/economic/entity/handle_spec.rb +2 -2
- data/spec/economic/order_spec.rb +80 -0
- data/spec/economic/proxies/debtor_contact_proxy_spec.rb +1 -1
- data/spec/economic/proxies/debtor_proxy_spec.rb +69 -0
- data/spec/economic/proxies/order_proxy_spec.rb +67 -0
- data/spec/economic/session_spec.rb +99 -11
- data/spec/fixtures/cash_book_update_from_data/success.xml +14 -0
- data/spec/fixtures/connect_with_token/success.xml +8 -0
- data/spec/fixtures/creditor_create_from_data/success.xml +49 -0
- data/spec/fixtures/current_invoice_line_create_from_data/success.xml +42 -0
- data/spec/fixtures/debtor_find_by_telephone_and_fax_number/found.xml +12 -0
- data/spec/fixtures/debtor_find_by_telephone_and_fax_number/not_found.xml +7 -0
- data/spec/fixtures/debtor_get_debtor_contacts/multiple.xml +15 -0
- data/spec/fixtures/debtor_get_debtor_contacts/none.xml +9 -0
- data/spec/fixtures/debtor_get_invoices/success.xml +15 -0
- data/spec/fixtures/debtor_get_orders/success.xml +12 -0
- data/spec/fixtures/order_find_by_date_interval/many.xml +15 -0
- data/spec/fixtures/order_find_by_date_interval/none.xml +9 -0
- data/spec/fixtures/order_find_by_date_interval/single.xml +12 -0
- data/spec/fixtures/order_get_data/success.xml +75 -0
- data/spec/fixtures/order_get_data_array/multiple.xml +145 -0
- data/spec/fixtures/order_get_data_array/single.xml +77 -0
- data/spec/fixtures/order_get_pdf/success.xml +8 -0
- metadata +28 -4
@@ -45,4 +45,25 @@ describe Economic::CurrentInvoiceLine do
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
+
describe "#save" do
|
49
|
+
context "when successful" do
|
50
|
+
it "builds and sends data to API" do
|
51
|
+
mock_request(
|
52
|
+
"CurrentInvoiceLine_CreateFromData", {
|
53
|
+
"data" => {
|
54
|
+
"Number" => 0,
|
55
|
+
"DeliveryDate" => nil,
|
56
|
+
"DiscountAsPercent" => 0,
|
57
|
+
"UnitCostPrice" => 0,
|
58
|
+
"TotalNetAmount" => nil,
|
59
|
+
"TotalMargin" => 0,
|
60
|
+
"MarginAsPercent" => 0
|
61
|
+
}
|
62
|
+
},
|
63
|
+
:success
|
64
|
+
)
|
65
|
+
subject.save
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
48
69
|
end
|
@@ -56,18 +56,43 @@ describe Economic::Debtor do
|
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
-
describe ".
|
60
|
-
it "
|
61
|
-
expect(subject.
|
59
|
+
describe ".invoices" do
|
60
|
+
it "return nothing if no handle" do
|
61
|
+
expect(subject.invoices).to be_empty
|
62
|
+
end
|
63
|
+
it "returns invoices if there is a handle" do
|
64
|
+
mock_request('Debtor_GetInvoices', {"debtorHandle"=>{"Number"=>1}}, :success)
|
65
|
+
subject.handle = Economic::Entity::Handle.new({:number => "1"})
|
66
|
+
subject.invoices.each do |i|
|
67
|
+
expect(i).to be_instance_of(Economic::Invoice)
|
68
|
+
end
|
62
69
|
end
|
70
|
+
end
|
63
71
|
|
64
|
-
|
65
|
-
|
72
|
+
describe ".orders" do
|
73
|
+
it "return nothing if no handle" do
|
74
|
+
expect(subject.orders).to be_empty
|
75
|
+
end
|
76
|
+
it "returns invoices if there is a handle" do
|
77
|
+
mock_request('Debtor_GetOrders', {"debtorHandle"=>{"Number"=>1}}, :success)
|
78
|
+
subject.handle = Economic::Entity::Handle.new({:number => "1"})
|
79
|
+
subject.orders.each do |i|
|
80
|
+
expect(i).to be_instance_of(Economic::Order)
|
81
|
+
end
|
66
82
|
end
|
83
|
+
end
|
67
84
|
|
68
|
-
|
69
|
-
|
70
|
-
expect(subject.contacts
|
85
|
+
describe ".contacts" do
|
86
|
+
it "returns nothing if no handle" do
|
87
|
+
expect(subject.contacts).to be_empty
|
88
|
+
end
|
89
|
+
|
90
|
+
it "returns debtor contacts if there is a handle" do
|
91
|
+
mock_request('Debtor_GetDebtorContacts', {"debtorHandle"=>{"Number"=>1}}, :multiple)
|
92
|
+
subject.handle = Economic::Entity::Handle.new({:number => "1"})
|
93
|
+
subject.contacts.each do |contact|
|
94
|
+
expect(contact).to be_instance_of(Economic::DebtorContact)
|
95
|
+
end
|
71
96
|
end
|
72
97
|
end
|
73
98
|
|
@@ -68,4 +68,22 @@ describe Economic::Endpoint do
|
|
68
68
|
expect(subject.soap_action_name("FooBar", "Stuff")).to eq(:foo_bar_stuff)
|
69
69
|
end
|
70
70
|
end
|
71
|
+
|
72
|
+
describe "savon globals configuration" do
|
73
|
+
it "sets the log_level option of the endpoint" do
|
74
|
+
subject.client.globals.should_receive(:log_level).with(:fatal)
|
75
|
+
subject.log_level = :fatal
|
76
|
+
end
|
77
|
+
|
78
|
+
it "sets the log option of the endpoint" do
|
79
|
+
subject.client.globals.should_receive(:log).with(true)
|
80
|
+
subject.log = true
|
81
|
+
end
|
82
|
+
|
83
|
+
it "sets the logger option of the boolean" do
|
84
|
+
logger = double("MyLogger")
|
85
|
+
subject.client.globals.should_receive(:logger).with(logger)
|
86
|
+
subject.logger = logger
|
87
|
+
end
|
88
|
+
end
|
71
89
|
end
|
@@ -162,10 +162,10 @@ describe Economic::Entity::Handle do
|
|
162
162
|
end
|
163
163
|
|
164
164
|
describe ".to_hash" do
|
165
|
-
subject { Economic::Entity::Handle.new({:id => 42, :number => 37, :serial_number => 7, :code => "USD", :vat_code => 1}) }
|
165
|
+
subject { Economic::Entity::Handle.new({:id => 42, :number => 37, :serial_number => 7, :code => "USD", :name => "Bob", :vat_code => 1}) }
|
166
166
|
|
167
167
|
it "should return a handle for putting into the body of a SOAP request" do
|
168
|
-
expect(subject.to_hash).to eq({'Id' => 42, 'Number' => 37, 'SerialNumber' => 7, 'Code' => 'USD', 'VatCode' => 1})
|
168
|
+
expect(subject.to_hash).to eq({'Id' => 42, 'Number' => 37, 'SerialNumber' => 7, 'Code' => 'USD', 'Name' => 'Bob', 'VatCode' => 1})
|
169
169
|
end
|
170
170
|
|
171
171
|
it "includes only the named value in the hash" do
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require './spec/spec_helper'
|
2
|
+
|
3
|
+
describe Economic::Order do
|
4
|
+
let(:session) { make_session }
|
5
|
+
subject { Economic::Order.new(:session => session, :number => 512) }
|
6
|
+
|
7
|
+
it "inherits from Economic::Entity" do
|
8
|
+
expect(Economic::Order.ancestors).to include(Economic::Entity)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe ".proxy" do
|
12
|
+
it "should return a OrderProxy" do
|
13
|
+
expect(subject.proxy).to be_instance_of(Economic::OrderProxy)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should return a proxy owned by session" do
|
17
|
+
expect(subject.proxy.session).to eq(session)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe ".key" do
|
22
|
+
it "should == :invoice" do
|
23
|
+
expect(Economic::Order.key).to eq(:order)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#pdf" do
|
28
|
+
it "gets PDF data from API" do
|
29
|
+
mock_request('Order_GetPdf', {'orderHandle' => {'Number' => 512}}, :success)
|
30
|
+
subject.pdf
|
31
|
+
end
|
32
|
+
|
33
|
+
it "decodes the base64Binary encoded data" do
|
34
|
+
stub_request('Order_GetPdf', nil, :success)
|
35
|
+
expect(subject.pdf).to eq('This is not really PDF data')
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#attention" do
|
40
|
+
let(:contact) {
|
41
|
+
Economic::DebtorContact.new.tap do |c|
|
42
|
+
c.session = session
|
43
|
+
c.id = 5
|
44
|
+
end
|
45
|
+
}
|
46
|
+
|
47
|
+
it "should be set- and gettable" do
|
48
|
+
subject.attention = contact
|
49
|
+
expect(subject.attention).to eq(contact)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "updates the handle" do
|
53
|
+
handle = Economic::Entity::Handle.new(:number => 42)
|
54
|
+
contact.handle = handle
|
55
|
+
subject.attention = contact
|
56
|
+
expect(subject.attention_handle).to eq(handle)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "#debtor" do
|
61
|
+
let(:debtor) {
|
62
|
+
Economic::Debtor.new.tap do |c|
|
63
|
+
c.session = session
|
64
|
+
c.number = 5
|
65
|
+
end
|
66
|
+
}
|
67
|
+
|
68
|
+
it "should be set- and gettable" do
|
69
|
+
subject.debtor = debtor
|
70
|
+
expect(subject.debtor).to eq(debtor)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "updates the handle" do
|
74
|
+
handle = Economic::Entity::Handle.new(:number => 42)
|
75
|
+
debtor.handle = handle
|
76
|
+
subject.debtor = debtor
|
77
|
+
expect(subject.debtor_handle).to eq(handle)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -25,7 +25,7 @@ describe Economic::DebtorContactProxy do
|
|
25
25
|
|
26
26
|
context "when owner is a Debtor" do
|
27
27
|
let(:debtor) { make_debtor(:session => session) }
|
28
|
-
subject { debtor
|
28
|
+
subject { Economic::DebtorContactProxy.new(debtor) }
|
29
29
|
|
30
30
|
it "should use the Debtors session" do
|
31
31
|
expect(subject.build.session).to eq(debtor.session)
|
@@ -68,6 +68,23 @@ describe Economic::DebtorProxy do
|
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
|
+
describe "find_by_telephone_and_fax_number" do
|
72
|
+
it "can find a debtor" do
|
73
|
+
mock_request('Debtor_FindByTelephoneAndFaxNumber', {'telephoneAndFaxNumber' => '22334455'}, :found)
|
74
|
+
result = subject.find_by_telephone_and_fax_number('22334455')
|
75
|
+
expect(result).to be_instance_of(Economic::Debtor)
|
76
|
+
expect(result.number).to eq(1)
|
77
|
+
expect(result.partial).to be_true
|
78
|
+
expect(result.persisted).to be_true
|
79
|
+
end
|
80
|
+
|
81
|
+
it "returns nil when there is no debtor" do
|
82
|
+
mock_request('Debtor_FindByTelephoneAndFaxNumber', {'telephoneAndFaxNumber' => '22334455'}, :not_found)
|
83
|
+
result = subject.find_by_telephone_and_fax_number('22334455')
|
84
|
+
expect(result).to be_nil
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
71
88
|
describe "next_available_number" do
|
72
89
|
it "gets the next available debtor number from API" do
|
73
90
|
mock_request('Debtor_GetNextAvailableNumber', nil, :success)
|
@@ -112,4 +129,56 @@ describe Economic::DebtorProxy do
|
|
112
129
|
expect(all.first).to be_instance_of(Economic::Debtor)
|
113
130
|
end
|
114
131
|
end
|
132
|
+
|
133
|
+
describe ".get_debtor_contacts" do
|
134
|
+
let(:handle) { Economic::Entity::Handle.new({:number => 1}) }
|
135
|
+
it "gets debtor contact data from API" do
|
136
|
+
mock_request('Debtor_GetDebtorContacts', {"debtorHandle"=>{"Number"=>1}}, :multiple)
|
137
|
+
subject.get_debtor_contacts(handle)
|
138
|
+
end
|
139
|
+
|
140
|
+
it "returns DebtorContact objects" do
|
141
|
+
stub_request('Debtor_GetDebtorContacts', nil, :multiple)
|
142
|
+
subject.get_debtor_contacts(handle).each do |d|
|
143
|
+
expect(d).to be_instance_of(Economic::DebtorContact)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
describe ".get_invoices" do
|
149
|
+
let(:handle) { Economic::Entity::Handle.new({:number => 1}) }
|
150
|
+
it "gets invoice data from API" do
|
151
|
+
mock_request('Debtor_GetInvoices', {"debtorHandle"=>{"Number"=>1}}, :success)
|
152
|
+
subject.get_invoices(handle)
|
153
|
+
end
|
154
|
+
|
155
|
+
it "returns Invoice object" do
|
156
|
+
stub_request('Debtor_GetInvoices', nil, :success)
|
157
|
+
subject.get_invoices(handle).each do |i|
|
158
|
+
expect(i).to be_instance_of(Economic::Invoice)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
describe ".get_order" do
|
164
|
+
let(:handle) { Economic::Entity::Handle.new({:number => 1}) }
|
165
|
+
it "gets invoice data from API" do
|
166
|
+
mock_request('Debtor_GetOrders', {"debtorHandle"=>{"Number"=>1}}, :success)
|
167
|
+
subject.get_orders(handle)
|
168
|
+
end
|
169
|
+
|
170
|
+
it "returns Order object" do
|
171
|
+
stub_request('Debtor_GetOrders', nil, :success)
|
172
|
+
subject.get_orders(handle).each do |i|
|
173
|
+
expect(i).to be_instance_of(Economic::Order)
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
it "sets the number" do
|
178
|
+
stub_request('Debtor_GetOrders', nil, :success)
|
179
|
+
subject.get_orders(handle).each do |i|
|
180
|
+
expect(i.number).to eq(1)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
115
184
|
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require './spec/spec_helper'
|
2
|
+
|
3
|
+
describe Economic::OrderProxy do
|
4
|
+
|
5
|
+
let(:session) { make_session }
|
6
|
+
subject { Economic::OrderProxy.new(session) }
|
7
|
+
|
8
|
+
describe ".new" do
|
9
|
+
it "stores session" do
|
10
|
+
expect(subject.session).to equal(session)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe ".build" do
|
15
|
+
it "instantiates a new Order" do
|
16
|
+
expect(subject.build).to be_instance_of(Economic::Order)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "assigns the session to the Order" do
|
20
|
+
expect(subject.build.session).to equal(session)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should not build a partial Order" do
|
24
|
+
expect(subject.build).to_not be_partial
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe ".find" do
|
29
|
+
it "gets order data from API" do
|
30
|
+
mock_request('Order_GetData', {'entityHandle' => {'Id' => 42}}, :success)
|
31
|
+
subject.find(42)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "returns Order object" do
|
35
|
+
stub_request('Order_GetData', nil, :success)
|
36
|
+
expect(subject.find(42)).to be_instance_of(Economic::Order)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe ".find_by_date_interval" do
|
41
|
+
let(:from) { Time.now - 60 }
|
42
|
+
let(:unto) { Time.now }
|
43
|
+
|
44
|
+
it "should be able to return a single current order" do
|
45
|
+
mock_request('Order_FindByDateInterval', {'first' => from.iso8601, 'last' => unto.iso8601}, :single)
|
46
|
+
mock_request('Order_GetDataArray', :any, :single)
|
47
|
+
results = subject.find_by_date_interval(from, unto)
|
48
|
+
expect(results.size).to eq(1)
|
49
|
+
expect(results.first).to be_instance_of(Economic::Order)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should be able to return multiple orders" do
|
53
|
+
mock_request('Order_FindByDateInterval', {'first' => from.iso8601, 'last' => unto.iso8601}, :many)
|
54
|
+
mock_request('Order_GetDataArray', :any, :multiple)
|
55
|
+
results = subject.find_by_date_interval(from, unto)
|
56
|
+
expect(results.size).to eq(2)
|
57
|
+
expect(results.first).to be_instance_of(Economic::Order)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should be able to return nothing" do
|
61
|
+
mock_request('Order_FindByDateInterval', {'first' => from.iso8601, 'last' => unto.iso8601}, :none)
|
62
|
+
results = subject.find_by_date_interval(from, unto)
|
63
|
+
expect(results.size).to eq(0)
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
@@ -1,24 +1,42 @@
|
|
1
1
|
require './spec/spec_helper'
|
2
2
|
|
3
3
|
describe Economic::Session do
|
4
|
-
|
4
|
+
let(:credentials) { [123456, 'api', 'passw0rd'] }
|
5
|
+
subject { Economic::Session.new }
|
5
6
|
|
6
7
|
let(:endpoint) { subject.endpoint }
|
7
8
|
|
8
9
|
describe "new" do
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
describe "legacy connect" do
|
11
|
+
subject { Economic::Session.new *credentials }
|
12
|
+
it "should store authentication details" do
|
13
|
+
expect(subject.agreement_number).to eq(123456)
|
14
|
+
expect(subject.user_name).to eq('api')
|
15
|
+
expect(subject.password).to eq('passw0rd')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it "yields the endpoint if a block is given" do
|
20
|
+
endpoint_mock = double("Endpoint")
|
21
|
+
Economic::Endpoint.stub(:new).and_return(endpoint_mock)
|
22
|
+
expect{|b|
|
23
|
+
Economic::Session.new(123456, 'api', 'passw0rd', &b)
|
24
|
+
}.to yield_with_args(endpoint_mock)
|
13
25
|
end
|
14
26
|
end
|
15
27
|
|
16
28
|
describe "connect" do
|
17
29
|
let(:authentication_details) { {:agreementNumber => 123456, :userName => 'api', :password => 'passw0rd'} }
|
18
30
|
|
31
|
+
it "can connect old-style" do
|
32
|
+
mock_request(:connect, authentication_details, :success)
|
33
|
+
e = Economic::Session.new(*credentials)
|
34
|
+
e.connect
|
35
|
+
end
|
36
|
+
|
19
37
|
it "connects to e-conomic with authentication details" do
|
20
38
|
mock_request(:connect, authentication_details, :success)
|
21
|
-
subject.
|
39
|
+
subject.connect_with_credentials(*credentials)
|
22
40
|
end
|
23
41
|
|
24
42
|
it "stores the authentication token for later requests" do
|
@@ -28,7 +46,7 @@ describe Economic::Session do
|
|
28
46
|
}
|
29
47
|
stub_request('Connect', authentication_details, response)
|
30
48
|
|
31
|
-
subject.
|
49
|
+
subject.connect_with_credentials(*credentials)
|
32
50
|
|
33
51
|
expect(subject.authentication_token.collect { |cookie|
|
34
52
|
cookie.name_and_value.split("=").last
|
@@ -37,11 +55,11 @@ describe Economic::Session do
|
|
37
55
|
|
38
56
|
it "updates the authentication token for new sessions" do
|
39
57
|
stub_request("Connect", nil, {:headers => {"Set-Cookie" => "authentication token"}})
|
40
|
-
subject.
|
58
|
+
subject.connect_with_credentials(*credentials)
|
41
59
|
|
42
60
|
stub_request('Connect', nil, {:headers => {"Set-Cookie" => "another token"}})
|
43
|
-
other_session = Economic::Session.new
|
44
|
-
other_session.
|
61
|
+
other_session = Economic::Session.new
|
62
|
+
other_session.connect_with_credentials(123456, 'api', 'passw0rd')
|
45
63
|
|
46
64
|
expect(subject.authentication_token.collect { |cookie|
|
47
65
|
cookie.name_and_value.split("=").last
|
@@ -53,7 +71,54 @@ describe Economic::Session do
|
|
53
71
|
|
54
72
|
it "doesn't use existing authentication details when connecting" do
|
55
73
|
expect(endpoint).to receive(:call).with(:connect, instance_of(Hash))
|
56
|
-
subject.
|
74
|
+
subject.connect_with_credentials(*credentials)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "connecting with access ID" do
|
79
|
+
# As per http://www.e-conomic.com/developer/tutorials
|
80
|
+
let(:authentication_details) { {:appToken => 'the_private_app_id', :token => 'the_access_id_you_got_from_the_grant'} }
|
81
|
+
let(:private_app_id) { authentication_details[:appToken] }
|
82
|
+
let(:access_id) { authentication_details[:token] }
|
83
|
+
subject { Economic::Session.new }
|
84
|
+
it "connects to e-conomic with tokens details" do
|
85
|
+
mock_request(:connect_with_token, authentication_details, :success)
|
86
|
+
subject.connect_with_token private_app_id, access_id
|
87
|
+
end
|
88
|
+
|
89
|
+
it "stores the authentication token for later requests" do
|
90
|
+
response = {
|
91
|
+
:headers => {'Set-Cookie' => 'cookie value from e-conomic'},
|
92
|
+
:body => fixture(:connect_with_token, :success)
|
93
|
+
}
|
94
|
+
stub_request('ConnectWithToken', authentication_details, response)
|
95
|
+
|
96
|
+
subject.connect_with_token private_app_id, access_id
|
97
|
+
|
98
|
+
expect(subject.authentication_token.collect { |cookie|
|
99
|
+
cookie.name_and_value.split("=").last
|
100
|
+
}).to eq(["cookie value from e-conomic"])
|
101
|
+
end
|
102
|
+
|
103
|
+
it "updates the authentication token for new sessions" do
|
104
|
+
stub_request("ConnectWithToken", nil, {:headers => {"Set-Cookie" => "authentication token"}})
|
105
|
+
subject.connect_with_token private_app_id, access_id
|
106
|
+
|
107
|
+
stub_request('Connect', nil, {:headers => {"Set-Cookie" => "another token"}})
|
108
|
+
other_session = Economic::Session.new
|
109
|
+
other_session.connect_with_credentials(123456, 'api', 'passw0rd')
|
110
|
+
|
111
|
+
expect(subject.authentication_token.collect { |cookie|
|
112
|
+
cookie.name_and_value.split("=").last
|
113
|
+
}).to eq(["authentication token"])
|
114
|
+
expect(other_session.authentication_token.collect { |cookie|
|
115
|
+
cookie.name_and_value.split("=").last
|
116
|
+
}).to eq(["another token"])
|
117
|
+
end
|
118
|
+
|
119
|
+
it "doesn't use existing authentication details when connecting" do
|
120
|
+
expect(endpoint).to receive(:call).with(:connect_with_token, instance_of(Hash))
|
121
|
+
subject.connect_with_token private_app_id, access_id
|
57
122
|
end
|
58
123
|
end
|
59
124
|
|
@@ -135,4 +200,27 @@ describe Economic::Session do
|
|
135
200
|
end
|
136
201
|
end
|
137
202
|
|
203
|
+
describe "savon configuration" do
|
204
|
+
let(:endpoint) { double("Endpoint") }
|
205
|
+
|
206
|
+
before :each do
|
207
|
+
Economic::Endpoint.stub(:new).and_return(endpoint)
|
208
|
+
end
|
209
|
+
|
210
|
+
it "sets the log_level option of the endpoint" do
|
211
|
+
endpoint.should_receive(:log_level=).with(:info)
|
212
|
+
subject.log_level = :info
|
213
|
+
end
|
214
|
+
|
215
|
+
it "sets the log option of the endpoint" do
|
216
|
+
endpoint.should_receive(:log=).with(true)
|
217
|
+
subject.log = true
|
218
|
+
end
|
219
|
+
|
220
|
+
it "sets the logger option of the boolean" do
|
221
|
+
logger = double("MyLogger")
|
222
|
+
endpoint.should_receive(:logger=).with(logger)
|
223
|
+
subject.logger = logger
|
224
|
+
end
|
225
|
+
end
|
138
226
|
end
|