Skip to content
Browse files

Merge remote-tracking branch 'barsoom/master' into barsoom

  • Loading branch information...
2 parents 78224c5 + 37443ab commit f000f6dc51e63f858b20abdb527dadae3bd55b91 @koppen koppen committed
View
2 lib/economic/cash_book_entry.rb
@@ -75,7 +75,7 @@ def handle
def build_soap_data
data = ActiveSupport::OrderedHash.new
- data['Handle'] = handle.to_hash
+ data['Handle'] = handle.to_hash unless handle.to_hash.empty?
data['Id1'] = id1 unless id1.blank?
data['Id2'] = id2 unless id2.blank?
data['Type'] = type unless type.blank?
View
40 lib/economic/proxies/entry_proxy.rb
@@ -6,14 +6,32 @@ def find_by_date_interval(from_date, to_date)
response = session.request(entity_class.soap_action('FindByDateInterval')) do
soap.body = {
'fromDate' => from_date,
- 'toDate' => to_date
+ 'toDate' => to_date
}
end
- (response[:entry_handle] || []).map do |entry_handle|
- # Kinda ugly, but we get an array instead of a hash when there's only one result. :)
- Hash[*entry_handle.to_a.flatten][:serial_number].to_i
+ build_array(response)
+ end
+
+ # Undocumented tip: if you only care about the min_number, pass in the maximum
+ # possible value as max_number so you don't have to call `get_last_used_serial_number`:
+ #
+ # max_number = 2**31 - 1 # Maximum int32.
+ #
+ def find_by_serial_number_interval(min_number, max_number)
+ response = session.request(entity_class.soap_action('FindBySerialNumberInterval')) do
+ soap.body = {
+ 'minNumber' => min_number,
+ 'maxNumber' => max_number
+ }
end
+
+ build_array(response)
+ end
+
+ def get_last_used_serial_number
+ response = session.request(entity_class.soap_action('GetLastUsedSerialNumber'))
+ response.to_i
end
def find(serial_number)
@@ -27,5 +45,19 @@ def find(serial_number)
build(response)
end
+
+ private
+
+ def build_array(response)
+ # The response[:entry_handle] format may be any of
+ # [{:serial_number=>"1"}, {:serial_number=>"2"}] # Many results.
+ # {:serial_number=>"1"} # One result.
+ # nil # No results.
+ entry_handles = [ response[:entry_handle] ].flatten.compact
+
+ entry_handles.map do |entry_handle|
+ entry_handle[:serial_number].to_i
+ end
+ end
end
end
View
34 spec/economic/proxies/entry_proxy_spec.rb
@@ -10,11 +10,13 @@
end
end
- describe "#find_by_invoice_number" do
+ describe "#find_by_date_interval" do
it 'should be able to find multiple entries' do
from_date = Date.new
to_date = Date.new
- savon.expects("Entry_FindByDateInterval").with('fromDate' => from_date, 'toDate' => to_date).returns(:many)
+ savon.expects("Entry_FindByDateInterval").
+ with('fromDate' => from_date, 'toDate' => to_date).
+ returns(:many)
subject.find_by_date_interval(from_date, to_date).should == [1, 2]
end
@@ -23,12 +25,38 @@
subject.find_by_date_interval(Date.new, Date.new).should == [1]
end
- it 'should handle a single serial number in the response' do
+ it 'should handle an empty response' do
savon.stubs("Entry_FindByDateInterval").returns(:none)
subject.find_by_date_interval(Date.new, Date.new).should == []
end
end
+ describe "#find_by_serial_number_interval" do
+ it 'should be able to find multiple entries' do
+ savon.expects("Entry_FindBySerialNumberInterval").
+ with('minNumber' => 123, 'maxNumber' => 456).
+ returns(:many)
+ subject.find_by_serial_number_interval(123, 456).should == [1, 2]
+ end
+
+ it 'should handle a single serial number in the response' do
+ savon.stubs("Entry_FindBySerialNumberInterval").returns(:single)
+ subject.find_by_serial_number_interval(123, 456).should == [1]
+ end
+
+ it 'should handle an empty response' do
+ savon.stubs("Entry_FindBySerialNumberInterval").returns(:none)
+ subject.find_by_serial_number_interval(123, 456).should == []
+ end
+ end
+
+ describe "#get_last_used_serial_number" do
+ it 'returns the number' do
+ savon.expects("Entry_GetLastUsedSerialNumber").returns(:success)
+ subject.get_last_used_serial_number.should == 123
+ end
+ end
+
describe "#find" do
it 'should get a entry by serial number' do
savon.expects("Entry_GetData").with('entityHandle' => { 'SerialNumber' => '123' }).returns(:success)
View
15 spec/fixtures/entry_find_by_serial_number_interval/many.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
+ <soap:Body>
+ <Entry_FindBySerialNumberIntervalResponse xmlns="http://e-conomic.com">
+ <Entry_FindBySerialNumberIntervalResult>
+ <EntryHandle>
+ <SerialNumber>1</SerialNumber>
+ </EntryHandle>
+ <EntryHandle>
+ <SerialNumber>2</SerialNumber>
+ </EntryHandle>
+ </Entry_FindBySerialNumberIntervalResult>
+ </Entry_FindBySerialNumberIntervalResponse>
+ </soap:Body>
+</soap:Envelope>
View
9 spec/fixtures/entry_find_by_serial_number_interval/none.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
+ <soap:Body>
+ <Entry_FindBySerialNumberIntervalResponse xmlns="http://e-conomic.com">
+ <Entry_FindBySerialNumberIntervalResult>
+ </Entry_FindBySerialNumberIntervalResult>
+ </Entry_FindBySerialNumberIntervalResponse>
+ </soap:Body>
+</soap:Envelope>
View
12 spec/fixtures/entry_find_by_serial_number_interval/single.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
+ <soap:Body>
+ <Entry_FindBySerialNumberIntervalResponse xmlns="http://e-conomic.com">
+ <Entry_FindBySerialNumberIntervalResult>
+ <EntryHandle>
+ <SerialNumber>1</SerialNumber>
+ </EntryHandle>
+ </Entry_FindBySerialNumberIntervalResult>
+ </Entry_FindBySerialNumberIntervalResponse>
+ </soap:Body>
+</soap:Envelope>
View
8 spec/fixtures/entry_get_last_used_serial_number/success.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
+ <soap:Body>
+ <Entry_GetLastUsedSerialNumberResponse xmlns="http://e-conomic.com">
+ <Entry_GetLastUsedSerialNumberResult>123</Entry_GetLastUsedSerialNumberResult>
+ </Entry_GetLastUsedSerialNumberResponse>
+ </soap:Body>
+</soap:Envelope>

0 comments on commit f000f6d

Please sign in to comment.
Something went wrong with that request. Please try again.