rconomic 0.2.1 → 0.3

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.
Files changed (73) hide show
  1. data/.travis.yml +1 -0
  2. data/Gemfile +8 -1
  3. data/Gemfile.lock +8 -1
  4. data/Guardfile +6 -0
  5. data/README.md +39 -14
  6. data/lib/economic/account.rb +25 -0
  7. data/lib/economic/cash_book.rb +39 -0
  8. data/lib/economic/cash_book_entry.rb +111 -0
  9. data/lib/economic/current_invoice.rb +33 -2
  10. data/lib/economic/current_invoice_line.rb +1 -1
  11. data/lib/economic/debtor.rb +2 -1
  12. data/lib/economic/debtor_contact.rb +1 -1
  13. data/lib/economic/entity/handle.rb +66 -0
  14. data/lib/economic/entity.rb +39 -36
  15. data/lib/economic/invoice.rb +58 -0
  16. data/lib/economic/proxies/account_proxy.rb +22 -0
  17. data/lib/economic/proxies/cash_book_entry_proxy.rb +53 -0
  18. data/lib/economic/proxies/cash_book_proxy.rb +47 -0
  19. data/lib/economic/proxies/current_invoice_line_proxy.rb +7 -1
  20. data/lib/economic/proxies/current_invoice_proxy.rb +18 -1
  21. data/lib/economic/proxies/debtor_contact_proxy.rb +36 -10
  22. data/lib/economic/proxies/debtor_proxy.rb +32 -1
  23. data/lib/economic/proxies/entity_proxy.rb +30 -3
  24. data/lib/economic/proxies/invoice_proxy.rb +31 -0
  25. data/lib/economic/session.rb +18 -1
  26. data/lib/economic/support/string.rb +19 -0
  27. data/lib/rconomic/version.rb +1 -1
  28. data/lib/rconomic.rb +10 -2
  29. data/spec/economic/cash_book_entry_spec.rb +20 -0
  30. data/spec/economic/cash_book_spec.rb +34 -0
  31. data/spec/economic/current_invoice_spec.rb +44 -1
  32. data/spec/economic/debtor_contact_spec.rb +2 -2
  33. data/spec/economic/debtor_spec.rb +6 -0
  34. data/spec/economic/entity/handle_spec.rb +116 -0
  35. data/spec/economic/entity_spec.rb +26 -22
  36. data/spec/economic/invoice_spec.rb +68 -0
  37. data/spec/economic/proxies/cash_book_entry_proxy_spec.rb +62 -0
  38. data/spec/economic/proxies/cash_book_proxy_spec.rb +54 -0
  39. data/spec/economic/proxies/current_invoice_line_proxy_spec.rb +1 -1
  40. data/spec/economic/proxies/current_invoice_proxy_spec.rb +66 -2
  41. data/spec/economic/proxies/debtor_proxy_spec.rb +39 -1
  42. data/spec/economic/proxies/invoice_proxy_spec.rb +75 -0
  43. data/spec/economic/session_spec.rb +11 -1
  44. data/spec/fixtures/cash_book_book/success.xml +10 -0
  45. data/spec/fixtures/cash_book_entry_create_debtor_payment/success.xml +11 -0
  46. data/spec/fixtures/cash_book_entry_create_finance_voucher/success.xml +11 -0
  47. data/spec/fixtures/cash_book_entry_create_from_data/success.xml +11 -0
  48. data/spec/fixtures/cash_book_entry_get_data/success.xml +73 -0
  49. data/spec/fixtures/cash_book_get_all/multiple.xml +15 -0
  50. data/spec/fixtures/cash_book_get_entries/success.xml +17 -0
  51. data/spec/fixtures/cash_book_get_name/success.xml +8 -0
  52. data/spec/fixtures/current_invoice_book/success.xml +10 -0
  53. data/spec/fixtures/current_invoice_find_by_date_interval/many.xml +15 -0
  54. data/spec/fixtures/current_invoice_find_by_date_interval/none.xml +8 -0
  55. data/spec/fixtures/current_invoice_find_by_date_interval/single.xml +12 -0
  56. data/spec/fixtures/current_invoice_get_all/multiple.xml +15 -0
  57. data/spec/fixtures/current_invoice_get_all/none.xml +8 -0
  58. data/spec/fixtures/current_invoice_get_all/single.xml +12 -0
  59. data/spec/fixtures/current_invoice_get_data_array/multiple.xml +141 -0
  60. data/spec/fixtures/current_invoice_get_data_array/single.xml +75 -0
  61. data/spec/fixtures/debtor_find_by_number/found.xml +10 -0
  62. data/spec/fixtures/debtor_find_by_number/not_found.xml +7 -0
  63. data/spec/fixtures/debtor_get_all/multiple.xml +15 -0
  64. data/spec/fixtures/debtor_get_all/single.xml +12 -0
  65. data/spec/fixtures/debtor_get_data_array/multiple.xml +103 -0
  66. data/spec/fixtures/invoice_find_by_date_interval/many.xml +15 -0
  67. data/spec/fixtures/invoice_find_by_date_interval/none.xml +9 -0
  68. data/spec/fixtures/invoice_find_by_date_interval/single.xml +12 -0
  69. data/spec/fixtures/invoice_get_data/success.xml +74 -0
  70. data/spec/fixtures/invoice_get_pdf/success.xml +8 -0
  71. data/spec/fixtures/invoice_get_remainder/success.xml +8 -0
  72. data/spec/fixtures/spec_entity_delete/success.xml +6 -0
  73. metadata +54 -6
@@ -0,0 +1,22 @@
1
+ require 'economic/proxies/entity_proxy'
2
+
3
+ module Economic
4
+ class AccountProxy < EntityProxy
5
+ def find_by_name(name)
6
+ response = session.request entity_class.soap_action('FindByName') do
7
+ soap.body = {
8
+ 'name' => name
9
+ }
10
+ end
11
+
12
+ handle = response[:account_handle]
13
+
14
+ entity = build(response)
15
+ entity.name = name
16
+ entity.number = handle[:number]
17
+ entity.persisted = true
18
+ entity
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,53 @@
1
+ require 'economic/proxies/entity_proxy'
2
+
3
+ module Economic
4
+ class CashBookEntryProxy < EntityProxy
5
+ def all
6
+ entity_hash = session.request(CashBookProxy.entity_class.soap_action(:get_entries)) do
7
+ soap.body = { "cashBookHandle" => owner.handle.to_hash }
8
+ end
9
+ if entity_hash != {}
10
+ [ entity_hash.values.first ].flatten.each do |id_hash|
11
+ find(id_hash)
12
+ end
13
+ end
14
+ self
15
+ end
16
+
17
+ # Creates a finance voucher and returns the cash book entry.
18
+ # Example:
19
+ # cash_book.entries.create_finance_voucher(
20
+ # :account_handle => { :number => 1010 },
21
+ # :contra_account_handle => { :number => 1011 }
22
+ # )
23
+ def create_finance_voucher(handles)
24
+ response = session.request(entity_class.soap_action('CreateFinanceVoucher')) do
25
+ soap.body = {
26
+ 'cashBookHandle' => { 'Number' => owner.handle[:number] },
27
+ 'accountHandle' => { 'Number' => handles[:account_handle][:number] },
28
+ 'contraAccountHandle' => { 'Number' => handles[:contra_account_handle][:number] }
29
+ }
30
+ end
31
+
32
+ find(response)
33
+ end
34
+
35
+ # Creates a debtor payment and returns the cash book entry.
36
+ # Example:
37
+ # cash_book.entries.create_debtor_payment(
38
+ # :debtor_handle => { :number => 1 },
39
+ # :contra_account_handle => { :number => 1510 }
40
+ # )
41
+ def create_debtor_payment(handles)
42
+ response = session.request(entity_class.soap_action('CreateDebtorPayment')) do
43
+ soap.body = {
44
+ "cashBookHandle" => { 'Number' => owner.handle[:number] },
45
+ "debtorHandle" => { 'Number' => handles[:debtor_handle][:number] },
46
+ "contraAccountHandle" => { 'Number' => handles[:contra_account_handle][:number] }
47
+ }
48
+ end
49
+
50
+ find(response)
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,47 @@
1
+ require 'economic/proxies/entity_proxy'
2
+
3
+ module Economic
4
+ class CashBookProxy < EntityProxy
5
+ def find_by_name(name)
6
+ response = session.request entity_class.soap_action('FindByName') do
7
+ soap.body = {
8
+ 'name' => name
9
+ }
10
+ end
11
+
12
+ cash_book = build
13
+ cash_book.partial = true
14
+ cash_book.persisted = true
15
+ cash_book.number = response[:number]
16
+ cash_book
17
+
18
+ end
19
+
20
+ def all
21
+ response = session.request entity_class.soap_action('GetAll')
22
+
23
+ handles = [response[:cash_book_handle]].flatten.reject(&:blank?)
24
+ cash_books = []
25
+ handles.each do |handle|
26
+ cash_books << get_name(handle[:number])
27
+ end
28
+
29
+ cash_books
30
+ end
31
+
32
+ def get_name(id)
33
+ response = session.request entity_class.soap_action("GetName") do
34
+ soap.body = {
35
+ 'cashBookHandle' => {
36
+ 'Number' => id
37
+ }
38
+ }
39
+ end
40
+
41
+ cash_book = build
42
+ cash_book.number = id
43
+ cash_book.name = response
44
+ cash_book
45
+ end
46
+ end
47
+ end
@@ -9,6 +9,12 @@ module Economic
9
9
  invoice_line
10
10
  end
11
11
 
12
+ # Gets data for CurrentInvoiceLine from the API
13
+ def find(handle)
14
+ handle = Entity::Handle.new(:number => handle) unless handle.is_a?(Entity::Handle)
15
+ super(handle)
16
+ end
17
+
12
18
  private
13
19
 
14
20
  # Initialize properties in invoice_line with values from owner
@@ -18,4 +24,4 @@ module Economic
18
24
  end
19
25
 
20
26
  end
21
- end
27
+ end
@@ -2,6 +2,7 @@ require 'economic/proxies/entity_proxy'
2
2
 
3
3
  module Economic
4
4
  class CurrentInvoiceProxy < EntityProxy
5
+
5
6
  # Returns a new, unpersisted Economic::CurrentInvoice
6
7
  def build(properties = {})
7
8
  invoice = super
@@ -9,6 +10,22 @@ module Economic
9
10
  invoice
10
11
  end
11
12
 
13
+ # Returns Economic::CurrentInvoice object for a given interval of days.
14
+ def find_by_date_interval(from, unto)
15
+ response = session.request entity_class.soap_action("FindByDateInterval") do
16
+ soap.body = {
17
+ 'first' => from.iso8601,
18
+ 'last' => unto.iso8601
19
+ }
20
+ end
21
+
22
+ handles = [ response[:current_invoice_handle] ].flatten.reject(&:blank?)
23
+
24
+ handles.collect do |handle|
25
+ find(handle[:id])
26
+ end
27
+ end
28
+
12
29
  private
13
30
 
14
31
  # Initialize properties in invoice with values from owner
@@ -28,4 +45,4 @@ module Economic
28
45
  end
29
46
 
30
47
  end
31
- end
48
+ end
@@ -11,21 +11,47 @@ module Economic
11
11
  end
12
12
 
13
13
  # Gets data for DebtorContact from the API
14
- def find(id)
15
- # This is basically EntityProxy::find duplicated so we can pass id to the API instead of
16
- # Number...
17
- entity_hash = session.request entity_class.soap_action(:get_data) do
14
+ def find(handle)
15
+ handle = Entity::Handle.new(:id => handle) unless handle.is_a?(Entity::Handle)
16
+ super(handle)
17
+ end
18
+
19
+ # Returns DebtorContact that have the given name. The objects will only be partially loaded
20
+ def find_by_name(name)
21
+ # Get a list of DebtorContactHandles from e-conomic
22
+ response = session.request entity_class.soap_action('FindByName') do
18
23
  soap.body = {
19
- 'entityHandle' => {
20
- 'Id' => id
21
- }
24
+ 'name' => name
22
25
  }
23
26
  end
24
- entity = build(entity_hash)
25
- entity.persisted = true
26
- entity
27
+
28
+ # Make sure we always have an array of handles even if the result only contains one
29
+ handles = [response[:debtor_contact_handle]].flatten.reject(&:blank?)
30
+
31
+ # Create partial DebtorContact entities
32
+ contacts = handles.collect do |handle|
33
+ debtor_contact = build
34
+ debtor_contact.partial = true
35
+ debtor_contact.persisted = true
36
+ debtor_contact.handle = handle
37
+ debtor_contact.id = handle[:id]
38
+ debtor_contact.number = handle[:number]
39
+ debtor_contact
40
+ end
41
+
42
+ if owner.is_a?(Debtor)
43
+ # Scope to the owner
44
+ contacts.select do |debtor_contact|
45
+ debtor_contact.get_data
46
+ debtor_contact.debtor.handle == owner.handle
47
+ end
48
+ else
49
+ contacts
50
+ end
51
+
27
52
  end
28
53
 
54
+
29
55
  private
30
56
 
31
57
  # Initialize properties in contact with values from owner. Returns contact.
@@ -2,6 +2,17 @@ require 'economic/proxies/entity_proxy'
2
2
 
3
3
  module Economic
4
4
  class DebtorProxy < EntityProxy
5
+
6
+ # Fetches Debtor from API
7
+ def find(handle)
8
+ handle = if handle.respond_to?(:to_i)
9
+ Entity::Handle.new(:number => handle.to_i)
10
+ else
11
+ Entity::Handle.new(handle)
12
+ end
13
+ super(handle)
14
+ end
15
+
5
16
  # Returns Debtors that have the given ci_number. The Debtor objects will only be partially loaded
6
17
  def find_by_ci_number(ci_number)
7
18
  # Get a list of DebtorHandles from e-conomic
@@ -25,9 +36,29 @@ module Economic
25
36
  end
26
37
  end
27
38
 
39
+ # Returns handle with a given number.
40
+ def find_by_number(number)
41
+ response = session.request entity_class.soap_action('FindByNumber') do
42
+ soap.body = {
43
+ 'number' => number
44
+ }
45
+ end
46
+
47
+ if response == {}
48
+ nil
49
+ else
50
+ debtor = build
51
+ debtor.partial = true
52
+ debtor.persisted = true
53
+ debtor.handle = response
54
+ debtor.number = response[:number].to_i
55
+ debtor
56
+ end
57
+ end
58
+
28
59
  # Returns the next available debtor number
29
60
  def next_available_number
30
61
  session.request Debtor.soap_action(:get_next_available_number)
31
62
  end
32
63
  end
33
- end
64
+ end
@@ -22,6 +22,32 @@ module Economic
22
22
  owner.session
23
23
  end
24
24
 
25
+ # Fetches all entities from the API.
26
+ def all
27
+ response = session.request(entity_class.soap_action(:get_all))
28
+ handles = response.values.flatten.collect { |handle| Entity::Handle.new(handle) }
29
+
30
+ if handles.size == 1
31
+ # Fetch data for single entity
32
+ find(handles.first)
33
+ elsif handles.size > 1
34
+ entity_class_name = entity_class.name.split('::').last
35
+
36
+ # Fetch all data for all the entities
37
+ entity_data = session.request(entity_class.soap_action(:get_data_array)) do
38
+ soap.body = {'entityHandles' => {"#{entity_class_name}Handle" => handles.collect(&:to_hash)}}
39
+ end
40
+
41
+ # Build Entity objects and add them to the proxy
42
+ entity_data["#{entity_class.key}_data".intern].each do |data|
43
+ entity = build(data)
44
+ entity.persisted = true
45
+ end
46
+ end
47
+
48
+ self
49
+ end
50
+
25
51
  # Returns a new, unpersisted Economic::Entity
26
52
  def build(properties = {})
27
53
  entity = self.class.entity_class.new(:session => session)
@@ -41,7 +67,7 @@ module Economic
41
67
 
42
68
  # Fetches Entity data from API and returns an Entity initialized with that data
43
69
  def find(handle)
44
- handle = Entity::Handle.new(:number => handle) unless handle.is_a?(Entity::Handle)
70
+ handle = Entity::Handle.new(handle) unless handle.is_a?(Entity::Handle)
45
71
  entity_hash = get_data(handle)
46
72
  entity = build(entity_hash)
47
73
  entity.persisted = true
@@ -50,7 +76,8 @@ module Economic
50
76
 
51
77
  # Gets data for Entity from the API. Returns Hash with the response data
52
78
  def get_data(handle)
53
- handle = Entity::Handle.new(:number => handle) unless handle.is_a?(Entity::Handle)
79
+ handle = Entity::Handle.new(handle) unless handle.is_a?(Entity::Handle)
80
+
54
81
  entity_hash = session.request(entity_class.soap_action(:get_data)) do
55
82
  soap.body = {
56
83
  'entityHandle' => handle.to_hash
@@ -79,4 +106,4 @@ module Economic
79
106
  end
80
107
 
81
108
  end
82
- end
109
+ end
@@ -0,0 +1,31 @@
1
+ require 'economic/proxies/entity_proxy'
2
+
3
+ module Economic
4
+ class InvoiceProxy < EntityProxy
5
+ # Gets data for Invoice from the API
6
+ def find(handle)
7
+ handle = if handle.respond_to?(:to_i)
8
+ Entity::Handle.new(:number => handle.to_i)
9
+ else
10
+ Entity::Handle.new(handle)
11
+ end
12
+ super(handle)
13
+ end
14
+
15
+ # Returns Economic::Invoice objects for invoices in a given interval of days.
16
+ def find_by_date_interval(from, unto)
17
+ response = session.request entity_class.soap_action("FindByDateInterval") do
18
+ soap.body = {
19
+ 'first' => from.iso8601,
20
+ 'last' => unto.iso8601
21
+ }
22
+ end
23
+
24
+ handles = [ response[:invoice_handle] ].flatten.reject(&:blank?)
25
+
26
+ handles.collect do |handle|
27
+ find(handle[:number])
28
+ end
29
+ end
30
+ end
31
+ end
@@ -37,11 +37,28 @@ module Economic
37
37
  def current_invoices
38
38
  @current_invoices ||= CurrentInvoiceProxy.new(self)
39
39
  end
40
+
41
+ # Provides access to the invoices
42
+ def invoices
43
+ @invoices ||= InvoiceProxy.new(self)
44
+ end
40
45
 
41
46
  # Provides access to the debtors
42
47
  def debtors
43
48
  @debtors ||= DebtorProxy.new(self)
44
49
  end
50
+
51
+ def cash_books
52
+ @cash_books ||= CashBookProxy.new(self)
53
+ end
54
+
55
+ def cash_book_entries
56
+ @cash_book_entries ||= CashBookEntryProxy.new(self)
57
+ end
58
+
59
+ def accounts
60
+ @accounts ||= AccountProxy.new(self)
61
+ end
45
62
 
46
63
  def request(action, &block)
47
64
  response = client.request :economic, action, &block
@@ -61,4 +78,4 @@ module Economic
61
78
  self
62
79
  end
63
80
  end
64
- end
81
+ end
@@ -0,0 +1,19 @@
1
+ module Economic
2
+ module Support
3
+ module String
4
+ def self.demodulize(class_name_in_module)
5
+ class_name_in_module.to_s.gsub(/^.*::/, '')
6
+ end
7
+
8
+ def self.underscore(camel_cased_word)
9
+ word = camel_cased_word.to_s.dup
10
+ word.gsub!(/::/, '/')
11
+ word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
12
+ word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
13
+ word.tr!("-", "_")
14
+ word.downcase!
15
+ word
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,3 +1,3 @@
1
1
  module Rconomic
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3"
3
3
  end
data/lib/rconomic.rb CHANGED
@@ -3,25 +3,33 @@ require 'time'
3
3
  require 'savon'
4
4
  require 'active_support/ordered_hash'
5
5
 
6
+ require 'economic/support/string'
6
7
  require 'economic/session'
8
+
7
9
  require 'economic/debtor'
8
10
  require 'economic/debtor_contact'
9
11
  require 'economic/current_invoice'
10
12
  require 'economic/current_invoice_line'
13
+ require 'economic/invoice'
14
+ require 'economic/cash_book'
15
+ require 'economic/cash_book_entry'
16
+ require 'economic/account'
11
17
 
12
18
  require 'economic/proxies/current_invoice_proxy'
13
19
  require 'economic/proxies/current_invoice_line_proxy'
14
20
  require 'economic/proxies/debtor_proxy'
15
21
  require 'economic/proxies/debtor_contact_proxy'
22
+ require 'economic/proxies/invoice_proxy'
23
+ require 'economic/proxies/cash_book_proxy'
24
+ require 'economic/proxies/cash_book_entry_proxy'
25
+ require 'economic/proxies/account_proxy'
16
26
 
17
27
  # http://www.e-conomic.com/apidocs/Documentation/index.html
18
28
  # https://www.e-conomic.com/secure/api1/EconomicWebService.asmx
19
29
  #
20
30
  # TODO
21
31
  #
22
- # * Memoization via ActiveSupport?
23
32
  # * Basic validations; ie check for nil values before submitting to API
24
- # * Better Handle handling
25
33
 
26
34
  module Economic
27
35
  end
@@ -0,0 +1,20 @@
1
+ require './spec/spec_helper'
2
+
3
+ describe Economic::CashBookEntry do
4
+ let(:session) { make_session }
5
+ subject { Economic::CashBookEntry.new(:session => session) }
6
+
7
+ it "inherits from Economic::Entity" do
8
+ Economic::CashBookEntry.ancestors.should include(Economic::Entity)
9
+ end
10
+
11
+ describe ".proxy" do
12
+ it "should return a CashBookEntryProxy" do
13
+ subject.proxy.should be_instance_of(Economic::CashBookEntryProxy)
14
+ end
15
+
16
+ it "should return a proxy owned by session" do
17
+ subject.proxy.session.should == session
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,34 @@
1
+ require './spec/spec_helper'
2
+
3
+ describe Economic::CashBook do
4
+ let(:session) { make_session }
5
+ subject { (i = Economic::CashBook.new( :id => 512, :number => 32 )).tap { i.session = session } }
6
+
7
+ it "inherits from Economic::Entity" do
8
+ Economic::CashBook.superclass.should == Economic::Entity
9
+ end
10
+
11
+ describe "class methods" do
12
+ subject { Economic::CashBook }
13
+
14
+ describe ".proxy" do
15
+ it "should return CashBookProxy" do
16
+ subject.proxy.should == Economic::CashBookProxy
17
+ end
18
+ end
19
+ end
20
+
21
+ describe "#entries" do
22
+ it 'should return a cash book entry proxy' do
23
+ subject.entries.should be_a(Economic::CashBookEntryProxy)
24
+ subject.entries.owner.should == subject
25
+ end
26
+ end
27
+
28
+ describe "#book" do
29
+ it 'should book the cash book and return an invoice number' do
30
+ savon.expects("CashBook_Book").with('cashBookHandle' => { 'Number' => 32 }).returns(:success)
31
+ subject.book.should == 832
32
+ end
33
+ end
34
+ end
@@ -2,7 +2,7 @@ require './spec/spec_helper'
2
2
 
3
3
  describe Economic::CurrentInvoice do
4
4
  let(:session) { make_session }
5
- subject { (i = Economic::CurrentInvoice.new).tap { i.session = session } }
5
+ subject { (i = Economic::CurrentInvoice.new( :id => 512 )).tap { i.session = session } }
6
6
 
7
7
  it "inherits from Economic::Entity" do
8
8
  Economic::CurrentInvoice.ancestors.should include(Economic::Entity)
@@ -15,6 +15,12 @@ describe Economic::CurrentInvoice do
15
15
  end
16
16
  end
17
17
 
18
+ describe ".key" do
19
+ it "should == :current_invoice" do
20
+ Economic::CurrentInvoice.key.should == :current_invoice
21
+ end
22
+ end
23
+
18
24
  describe ".proxy" do
19
25
  it "should return a CurrentInvoiceProxy" do
20
26
  subject.proxy.should be_instance_of(Economic::CurrentInvoiceProxy)
@@ -66,4 +72,41 @@ describe Economic::CurrentInvoice do
66
72
  end
67
73
  end
68
74
  end
75
+
76
+ describe "#book" do
77
+ before :each do
78
+ savon.stubs('CurrentInvoice_Book').returns(:success)
79
+ savon.stubs('Invoice_GetData').returns(:success)
80
+ end
81
+
82
+ it 'should book the current invoice and return the created invoice object' do
83
+ savon.expects("Invoice_GetData").with('entityHandle' => { 'Number' => 328 }).returns(:success)
84
+ subject.book.should be_instance_of(Economic::Invoice)
85
+ end
86
+
87
+ it 'should request with the right key for handle' do
88
+ savon.expects("CurrentInvoice_Book").with('currentInvoiceHandle' => { 'Id' => 512 }).returns(:success)
89
+ subject.book
90
+ end
91
+ end
92
+
93
+ describe "#attention" do
94
+ let(:contact) { (c = Economic::DebtorContact.new).tap { c.session = session }}
95
+
96
+ it "should be set- and gettable" do
97
+ subject.attention = contact
98
+ subject.attention_handle.should == contact.handle
99
+ subject.attention.should == contact
100
+ end
101
+ end
102
+
103
+ describe "#debtor" do
104
+ let(:debtor) { (c = Economic::Debtor.new).tap { c.session = session }}
105
+
106
+ it "should be set- and gettable" do
107
+ subject.debtor = debtor
108
+ subject.debtor_handle.should == debtor.handle
109
+ subject.debtor.should == debtor
110
+ end
111
+ end
69
112
  end
@@ -40,12 +40,12 @@ describe Economic::DebtorContact do
40
40
  end
41
41
 
42
42
  it "returns a Debtor" do
43
- session.debtors.expects(:find).with(handle).returns(Economic::Debtor.new)
43
+ session.debtors.expects(:find).with(42).returns(Economic::Debtor.new)
44
44
  subject.debtor.should be_instance_of(Economic::Debtor)
45
45
  end
46
46
 
47
47
  it "only looks up the debtor the first time" do
48
- session.debtors.expects(:find).with(handle).returns(Economic::Debtor.new)
48
+ session.debtors.expects(:find).with(42).returns(Economic::Debtor.new)
49
49
  subject.debtor.should === subject.debtor
50
50
  end
51
51
  end
@@ -16,6 +16,12 @@ describe Economic::Debtor do
16
16
  subject.proxy.should == Economic::DebtorProxy
17
17
  end
18
18
  end
19
+
20
+ describe ".key" do
21
+ it "should == :debtor" do
22
+ Economic::Debtor.key.should == :debtor
23
+ end
24
+ end
19
25
  end
20
26
 
21
27
  context "when saving" do