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
 
    
        data/lib/economic/session.rb
    CHANGED
    
    | 
         @@ -1,6 +1,9 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module Economic
         
     | 
| 
      
 2 
     | 
    
         
            +
              # The Economic::Session contains details and behaviors for a current
         
     | 
| 
      
 3 
     | 
    
         
            +
              # connection to the API endpoint.
         
     | 
| 
       2 
4 
     | 
    
         
             
              class Session
         
     | 
| 
       3 
5 
     | 
    
         
             
                attr_accessor :agreement_number, :user_name, :password
         
     | 
| 
      
 6 
     | 
    
         
            +
                attr_reader :authentication_token
         
     | 
| 
       4 
7 
     | 
    
         | 
| 
       5 
8 
     | 
    
         
             
                def initialize(agreement_number, user_name, password)
         
     | 
| 
       6 
9 
     | 
    
         
             
                  self.agreement_number = agreement_number
         
     | 
| 
         @@ -10,16 +13,12 @@ module Economic 
     | 
|
| 
       10 
13 
     | 
    
         | 
| 
       11 
14 
     | 
    
         
             
                # Authenticates with e-conomic
         
     | 
| 
       12 
15 
     | 
    
         
             
                def connect
         
     | 
| 
       13 
     | 
    
         
            -
                   
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
                     
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
                      :password => self.password
         
     | 
| 
       19 
     | 
    
         
            -
                    }
         
     | 
| 
      
 16 
     | 
    
         
            +
                  endpoint.call(
         
     | 
| 
      
 17 
     | 
    
         
            +
                    :connect,
         
     | 
| 
      
 18 
     | 
    
         
            +
                    authentication_details
         
     | 
| 
      
 19 
     | 
    
         
            +
                  ) do |response|
         
     | 
| 
      
 20 
     | 
    
         
            +
                    store_authentication_token(response)
         
     | 
| 
       20 
21 
     | 
    
         
             
                  end
         
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
                  @cookie = response.http.headers["Set-Cookie"]
         
     | 
| 
       23 
22 
     | 
    
         
             
                end
         
     | 
| 
       24 
23 
     | 
    
         | 
| 
       25 
24 
     | 
    
         
             
                # Provides access to the DebtorContacts
         
     | 
| 
         @@ -27,7 +26,8 @@ module Economic 
     | 
|
| 
       27 
26 
     | 
    
         
             
                  @contacts ||= DebtorContactProxy.new(self)
         
     | 
| 
       28 
27 
     | 
    
         
             
                end
         
     | 
| 
       29 
28 
     | 
    
         | 
| 
       30 
     | 
    
         
            -
                # Provides access to the current invoices - ie invoices that haven't yet 
     | 
| 
      
 29 
     | 
    
         
            +
                # Provides access to the current invoices - ie invoices that haven't yet
         
     | 
| 
      
 30 
     | 
    
         
            +
                # been booked
         
     | 
| 
       31 
31 
     | 
    
         
             
                def current_invoices
         
     | 
| 
       32 
32 
     | 
    
         
             
                  @current_invoices ||= CurrentInvoiceProxy.new(self)
         
     | 
| 
       33 
33 
     | 
    
         
             
                end
         
     | 
| 
         @@ -72,21 +72,8 @@ module Economic 
     | 
|
| 
       72 
72 
     | 
    
         
             
                end
         
     | 
| 
       73 
73 
     | 
    
         | 
| 
       74 
74 
     | 
    
         
             
                # Requests an action from the API endpoint
         
     | 
| 
       75 
     | 
    
         
            -
                def request( 
     | 
| 
       76 
     | 
    
         
            -
                   
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
       78 
     | 
    
         
            -
                  response = client.request(:economic, action) do
         
     | 
| 
       79 
     | 
    
         
            -
                    soap.body = data if data
         
     | 
| 
       80 
     | 
    
         
            -
                  end
         
     | 
| 
       81 
     | 
    
         
            -
                  response_hash = response.to_hash
         
     | 
| 
       82 
     | 
    
         
            -
             
     | 
| 
       83 
     | 
    
         
            -
                  response_key = "#{action}_response".intern
         
     | 
| 
       84 
     | 
    
         
            -
                  result_key = "#{action}_result".intern
         
     | 
| 
       85 
     | 
    
         
            -
                  if response_hash[response_key] && response_hash[response_key][result_key]
         
     | 
| 
       86 
     | 
    
         
            -
                    response_hash[response_key][result_key]
         
     | 
| 
       87 
     | 
    
         
            -
                  else
         
     | 
| 
       88 
     | 
    
         
            -
                    {}
         
     | 
| 
       89 
     | 
    
         
            -
                  end
         
     | 
| 
      
 75 
     | 
    
         
            +
                def request(soap_action, data = nil)
         
     | 
| 
      
 76 
     | 
    
         
            +
                  endpoint.call(soap_action, data, authentication_token)
         
     | 
| 
       90 
77 
     | 
    
         
             
                end
         
     | 
| 
       91 
78 
     | 
    
         | 
| 
       92 
79 
     | 
    
         
             
                # Returns self - used by proxies to access the session of their owner
         
     | 
| 
         @@ -94,14 +81,23 @@ module Economic 
     | 
|
| 
       94 
81 
     | 
    
         
             
                  self
         
     | 
| 
       95 
82 
     | 
    
         
             
                end
         
     | 
| 
       96 
83 
     | 
    
         | 
| 
      
 84 
     | 
    
         
            +
                # Returns the SOAP endpoint to connect to
         
     | 
| 
      
 85 
     | 
    
         
            +
                def endpoint
         
     | 
| 
      
 86 
     | 
    
         
            +
                  @endpoint ||= Economic::Endpoint.new
         
     | 
| 
      
 87 
     | 
    
         
            +
                end
         
     | 
| 
      
 88 
     | 
    
         
            +
             
     | 
| 
       97 
89 
     | 
    
         
             
                private
         
     | 
| 
       98 
90 
     | 
    
         | 
| 
       99 
     | 
    
         
            -
                 
     | 
| 
       100 
     | 
    
         
            -
             
     | 
| 
       101 
     | 
    
         
            -
             
     | 
| 
       102 
     | 
    
         
            -
             
     | 
| 
       103 
     | 
    
         
            -
                     
     | 
| 
       104 
     | 
    
         
            -
                   
     | 
| 
      
 91 
     | 
    
         
            +
                def authentication_details
         
     | 
| 
      
 92 
     | 
    
         
            +
                  {
         
     | 
| 
      
 93 
     | 
    
         
            +
                    :agreementNumber => self.agreement_number,
         
     | 
| 
      
 94 
     | 
    
         
            +
                    :userName => self.user_name,
         
     | 
| 
      
 95 
     | 
    
         
            +
                    :password => self.password
         
     | 
| 
      
 96 
     | 
    
         
            +
                  }
         
     | 
| 
      
 97 
     | 
    
         
            +
                end
         
     | 
| 
      
 98 
     | 
    
         
            +
             
     | 
| 
      
 99 
     | 
    
         
            +
                def store_authentication_token(response)
         
     | 
| 
      
 100 
     | 
    
         
            +
                  @authentication_token = response.http.cookies
         
     | 
| 
       105 
101 
     | 
    
         
             
                end
         
     | 
| 
       106 
102 
     | 
    
         
             
              end
         
     | 
| 
       107 
103 
     | 
    
         
             
            end
         
     | 
    
        data/lib/rconomic/version.rb
    CHANGED
    
    
    
        data/rconomic.gemspec
    CHANGED
    
    | 
         @@ -17,11 +17,7 @@ Gem::Specification.new do |s| 
     | 
|
| 
       17 
17 
     | 
    
         
             
              s.version     = Rconomic::VERSION
         
     | 
| 
       18 
18 
     | 
    
         
             
              s.platform    = Gem::Platform::RUBY
         
     | 
| 
       19 
19 
     | 
    
         | 
| 
       20 
     | 
    
         
            -
               
     | 
| 
       21 
     | 
    
         
            -
              # of gyoku as 0.4.5 is not backwards compatible. If we update Savon,
         
     | 
| 
       22 
     | 
    
         
            -
              # we should remove the gyoku constraint.
         
     | 
| 
       23 
     | 
    
         
            -
              s.add_runtime_dependency "savon", "0.9.5"
         
     | 
| 
       24 
     | 
    
         
            -
              s.add_runtime_dependency "gyoku", "0.4.4"
         
     | 
| 
      
 20 
     | 
    
         
            +
              s.add_runtime_dependency "savon", "~> 2.2"
         
     | 
| 
       25 
21 
     | 
    
         | 
| 
       26 
22 
     | 
    
         
             
              s.files         = `git ls-files`.split("\n").reject { |filename| ['.gitignore'].include?(filename) }
         
     | 
| 
       27 
23 
     | 
    
         
             
              s.test_files    = `git ls-files -- {spec}/*`.split("\n")
         
     | 
| 
         @@ -5,24 +5,46 @@ describe Economic::CashBookEntry do 
     | 
|
| 
       5 
5 
     | 
    
         
             
              subject { Economic::CashBookEntry.new(:session => session) }
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
7 
     | 
    
         
             
              it "inherits from Economic::Entity" do
         
     | 
| 
       8 
     | 
    
         
            -
                Economic::CashBookEntry.ancestors. 
     | 
| 
      
 8 
     | 
    
         
            +
                expect(Economic::CashBookEntry.ancestors).to include(Economic::Entity)
         
     | 
| 
       9 
9 
     | 
    
         
             
              end
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
11 
     | 
    
         
             
              describe ".proxy" do
         
     | 
| 
       12 
12 
     | 
    
         
             
                it "should return a CashBookEntryProxy" do
         
     | 
| 
       13 
     | 
    
         
            -
                  subject.proxy. 
     | 
| 
      
 13 
     | 
    
         
            +
                  expect(subject.proxy).to be_instance_of(Economic::CashBookEntryProxy)
         
     | 
| 
       14 
14 
     | 
    
         
             
                end
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
16 
     | 
    
         
             
                it "should return a proxy owned by session" do
         
     | 
| 
       17 
     | 
    
         
            -
                  subject.proxy.session. 
     | 
| 
      
 17 
     | 
    
         
            +
                  expect(subject.proxy.session).to eq(session)
         
     | 
| 
       18 
18 
     | 
    
         
             
                end
         
     | 
| 
       19 
19 
     | 
    
         
             
              end
         
     | 
| 
       20 
20 
     | 
    
         | 
| 
       21 
21 
     | 
    
         
             
              describe "#save" do
         
     | 
| 
       22 
22 
     | 
    
         
             
                it 'should save it' do
         
     | 
| 
       23 
     | 
    
         
            -
                   
     | 
| 
      
 23 
     | 
    
         
            +
                  stub_request('CashBookEntry_CreateFromData', nil, :success)
         
     | 
| 
       24 
24 
     | 
    
         
             
                  subject.save
         
     | 
| 
       25 
25 
     | 
    
         
             
                end
         
     | 
| 
       26 
     | 
    
         
            -
              end
         
     | 
| 
       27 
26 
     | 
    
         | 
| 
      
 27 
     | 
    
         
            +
                it "builds and sends data to API" do
         
     | 
| 
      
 28 
     | 
    
         
            +
                  time = Time.now
         
     | 
| 
      
 29 
     | 
    
         
            +
                  subject.date = subject.start_date = time
         
     | 
| 
      
 30 
     | 
    
         
            +
                  subject.account_handle = Economic::Entity::Handle.new(:number => 12)
         
     | 
| 
      
 31 
     | 
    
         
            +
                  mock_request(
         
     | 
| 
      
 32 
     | 
    
         
            +
                    :cash_book_entry_create_from_data, {
         
     | 
| 
      
 33 
     | 
    
         
            +
                      "data" => {
         
     | 
| 
      
 34 
     | 
    
         
            +
                        "AccountHandle" => {"Number" => 12},
         
     | 
| 
      
 35 
     | 
    
         
            +
                        "Date" => time,
         
     | 
| 
      
 36 
     | 
    
         
            +
                        "VoucherNumber" => 0,
         
     | 
| 
      
 37 
     | 
    
         
            +
                        "Text" => "",
         
     | 
| 
      
 38 
     | 
    
         
            +
                        "AmountDefaultCurrency" => 0,
         
     | 
| 
      
 39 
     | 
    
         
            +
                        "Amount" => 0,
         
     | 
| 
      
 40 
     | 
    
         
            +
                        "DueDate" => nil,
         
     | 
| 
      
 41 
     | 
    
         
            +
                        "StartDate" => time,
         
     | 
| 
      
 42 
     | 
    
         
            +
                        "EndDate" => nil
         
     | 
| 
      
 43 
     | 
    
         
            +
                      }
         
     | 
| 
      
 44 
     | 
    
         
            +
                    },
         
     | 
| 
      
 45 
     | 
    
         
            +
                    :success
         
     | 
| 
      
 46 
     | 
    
         
            +
                  )
         
     | 
| 
      
 47 
     | 
    
         
            +
                  subject.save
         
     | 
| 
      
 48 
     | 
    
         
            +
                end
         
     | 
| 
      
 49 
     | 
    
         
            +
              end
         
     | 
| 
       28 
50 
     | 
    
         
             
            end
         
     | 
| 
         @@ -5,7 +5,7 @@ describe Economic::CashBook do 
     | 
|
| 
       5 
5 
     | 
    
         
             
              subject { (i = Economic::CashBook.new( :id => 512, :number => 32 )).tap { i.session = session } }
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
7 
     | 
    
         
             
              it "inherits from Economic::Entity" do
         
     | 
| 
       8 
     | 
    
         
            -
                Economic::CashBook.superclass. 
     | 
| 
      
 8 
     | 
    
         
            +
                expect(Economic::CashBook.superclass).to eq(Economic::Entity)
         
     | 
| 
       9 
9 
     | 
    
         
             
              end
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
11 
     | 
    
         
             
              describe "class methods" do
         
     | 
| 
         @@ -13,22 +13,22 @@ describe Economic::CashBook do 
     | 
|
| 
       13 
13 
     | 
    
         | 
| 
       14 
14 
     | 
    
         
             
                describe ".proxy" do
         
     | 
| 
       15 
15 
     | 
    
         
             
                  it "should return CashBookProxy" do
         
     | 
| 
       16 
     | 
    
         
            -
                    subject.proxy. 
     | 
| 
      
 16 
     | 
    
         
            +
                    expect(subject.proxy).to eq(Economic::CashBookProxy)
         
     | 
| 
       17 
17 
     | 
    
         
             
                  end
         
     | 
| 
       18 
18 
     | 
    
         
             
                end
         
     | 
| 
       19 
19 
     | 
    
         
             
              end
         
     | 
| 
       20 
20 
     | 
    
         | 
| 
       21 
21 
     | 
    
         
             
              describe "#entries" do
         
     | 
| 
       22 
22 
     | 
    
         
             
                it 'should return a cash book entry proxy' do
         
     | 
| 
       23 
     | 
    
         
            -
                  subject.entries. 
     | 
| 
       24 
     | 
    
         
            -
                  subject.entries.owner. 
     | 
| 
      
 23 
     | 
    
         
            +
                  expect(subject.entries).to be_a(Economic::CashBookEntryProxy)
         
     | 
| 
      
 24 
     | 
    
         
            +
                  expect(subject.entries.owner).to eq(subject)
         
     | 
| 
       25 
25 
     | 
    
         
             
                end
         
     | 
| 
       26 
26 
     | 
    
         
             
              end
         
     | 
| 
       27 
27 
     | 
    
         | 
| 
       28 
28 
     | 
    
         
             
              describe "#book" do
         
     | 
| 
       29 
29 
     | 
    
         
             
                it 'should book the cash book and return an invoice number' do
         
     | 
| 
       30 
     | 
    
         
            -
                   
     | 
| 
       31 
     | 
    
         
            -
                  subject.book. 
     | 
| 
      
 30 
     | 
    
         
            +
                  mock_request("CashBook_Book", {'cashBookHandle' => { 'Number' => 32 }}, :success)
         
     | 
| 
      
 31 
     | 
    
         
            +
                  expect(subject.book).to eq(832)
         
     | 
| 
       32 
32 
     | 
    
         
             
                end
         
     | 
| 
       33 
33 
     | 
    
         
             
              end
         
     | 
| 
       34 
34 
     | 
    
         
             
            end
         
     | 
| 
         @@ -5,7 +5,7 @@ describe Economic::CreditorContact do 
     | 
|
| 
       5 
5 
     | 
    
         
             
              subject { Economic::CreditorContact.new(:session => session) }
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
7 
     | 
    
         
             
              it "inherits from Economic::Entity" do
         
     | 
| 
       8 
     | 
    
         
            -
                Economic::CreditorContact.ancestors. 
     | 
| 
      
 8 
     | 
    
         
            +
                expect(Economic::CreditorContact.ancestors).to include(Economic::Entity)
         
     | 
| 
       9 
9 
     | 
    
         
             
              end
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
11 
     | 
    
         
             
              context "when saving" do
         
     | 
| 
         @@ -18,17 +18,26 @@ describe Economic::CreditorContact do 
     | 
|
| 
       18 
18 
     | 
    
         
             
                    end
         
     | 
| 
       19 
19 
     | 
    
         | 
| 
       20 
20 
     | 
    
         
             
                    it "should send request and let e-conomic return an error" do
         
     | 
| 
       21 
     | 
    
         
            -
                      session. 
     | 
| 
      
 21 
     | 
    
         
            +
                      expect(session).to receive(:request)
         
     | 
| 
       22 
22 
     | 
    
         
             
                      subject.save
         
     | 
| 
       23 
23 
     | 
    
         
             
                    end
         
     | 
| 
       24 
24 
     | 
    
         
             
                  end
         
     | 
| 
       25 
25 
     | 
    
         
             
                end
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                it "builds and sends data to API" do
         
     | 
| 
      
 28 
     | 
    
         
            +
                  mock_request(
         
     | 
| 
      
 29 
     | 
    
         
            +
                    :creditor_contact_create_from_data,
         
     | 
| 
      
 30 
     | 
    
         
            +
                    {"data" => {"Handle" => {}, "Number" => nil}},
         
     | 
| 
      
 31 
     | 
    
         
            +
                    :success
         
     | 
| 
      
 32 
     | 
    
         
            +
                  )
         
     | 
| 
      
 33 
     | 
    
         
            +
                  subject.save
         
     | 
| 
      
 34 
     | 
    
         
            +
                end
         
     | 
| 
       26 
35 
     | 
    
         
             
              end
         
     | 
| 
       27 
36 
     | 
    
         | 
| 
       28 
37 
     | 
    
         
             
              describe ".creditor" do
         
     | 
| 
       29 
38 
     | 
    
         
             
                context "when creditor_handle is not set" do
         
     | 
| 
       30 
39 
     | 
    
         
             
                  it "returns nil" do
         
     | 
| 
       31 
     | 
    
         
            -
                    subject.creditor. 
     | 
| 
      
 40 
     | 
    
         
            +
                    expect(subject.creditor).to be_nil
         
     | 
| 
       32 
41 
     | 
    
         
             
                  end
         
     | 
| 
       33 
42 
     | 
    
         
             
                end
         
     | 
| 
       34 
43 
     | 
    
         | 
| 
         @@ -40,13 +49,13 @@ describe Economic::CreditorContact do 
     | 
|
| 
       40 
49 
     | 
    
         
             
                  end
         
     | 
| 
       41 
50 
     | 
    
         | 
| 
       42 
51 
     | 
    
         
             
                  it "returns a Creditor" do
         
     | 
| 
       43 
     | 
    
         
            -
                    session.creditors. 
     | 
| 
       44 
     | 
    
         
            -
                    subject.creditor. 
     | 
| 
      
 52 
     | 
    
         
            +
                    expect(session.creditors).to receive(:find).with(42).and_return(Economic::Creditor.new)
         
     | 
| 
      
 53 
     | 
    
         
            +
                    expect(subject.creditor).to be_instance_of(Economic::Creditor)
         
     | 
| 
       45 
54 
     | 
    
         
             
                  end
         
     | 
| 
       46 
55 
     | 
    
         | 
| 
       47 
56 
     | 
    
         
             
                  it "only looks up the creditor the first time" do
         
     | 
| 
       48 
     | 
    
         
            -
                    session.creditors. 
     | 
| 
       49 
     | 
    
         
            -
                    subject.creditor. 
     | 
| 
      
 57 
     | 
    
         
            +
                    expect(session.creditors).to receive(:find).with(42).and_return(Economic::Creditor.new)
         
     | 
| 
      
 58 
     | 
    
         
            +
                    expect(subject.creditor).to equal(subject.creditor)
         
     | 
| 
       50 
59 
     | 
    
         
             
                  end
         
     | 
| 
       51 
60 
     | 
    
         
             
                end
         
     | 
| 
       52 
61 
     | 
    
         
             
              end
         
     | 
| 
         @@ -55,7 +64,7 @@ describe Economic::CreditorContact do 
     | 
|
| 
       55 
64 
     | 
    
         
             
                let(:creditor) { make_creditor }
         
     | 
| 
       56 
65 
     | 
    
         
             
                it "should set creditor_handle" do
         
     | 
| 
       57 
66 
     | 
    
         
             
                  subject.creditor = creditor
         
     | 
| 
       58 
     | 
    
         
            -
                  subject.creditor_handle. 
     | 
| 
      
 67 
     | 
    
         
            +
                  expect(subject.creditor_handle).to eq(creditor.handle)
         
     | 
| 
       59 
68 
     | 
    
         
             
                end
         
     | 
| 
       60 
69 
     | 
    
         
             
              end
         
     | 
| 
       61 
70 
     | 
    
         | 
| 
         @@ -65,7 +74,7 @@ describe Economic::CreditorContact do 
     | 
|
| 
       65 
74 
     | 
    
         | 
| 
       66 
75 
     | 
    
         
             
                it "should set creditor_handle" do
         
     | 
| 
       67 
76 
     | 
    
         
             
                  subject.creditor_handle = handle
         
     | 
| 
       68 
     | 
    
         
            -
                  subject.creditor_handle. 
     | 
| 
      
 77 
     | 
    
         
            +
                  expect(subject.creditor_handle).to eq(handle)
         
     | 
| 
       69 
78 
     | 
    
         
             
                end
         
     | 
| 
       70 
79 
     | 
    
         | 
| 
       71 
80 
     | 
    
         
             
                context "when creditor handle is for a different Creditor" do
         
     | 
| 
         @@ -74,9 +83,9 @@ describe Economic::CreditorContact do 
     | 
|
| 
       74 
83 
     | 
    
         
             
                  end
         
     | 
| 
       75 
84 
     | 
    
         | 
| 
       76 
85 
     | 
    
         
             
                  it "should clear cached creditor and fetch the new creditor from API" do
         
     | 
| 
       77 
     | 
    
         
            -
                     
     | 
| 
      
 86 
     | 
    
         
            +
                    stub_request('Creditor_GetData', nil, :success)
         
     | 
| 
       78 
87 
     | 
    
         
             
                    subject.creditor_handle = Economic::Creditor::Handle.new({:number => 1234})
         
     | 
| 
       79 
     | 
    
         
            -
                    subject.creditor. 
     | 
| 
      
 88 
     | 
    
         
            +
                    expect(subject.creditor).to be_instance_of(Economic::Creditor)
         
     | 
| 
       80 
89 
     | 
    
         
             
                  end
         
     | 
| 
       81 
90 
     | 
    
         
             
                end
         
     | 
| 
       82 
91 
     | 
    
         | 
| 
         @@ -86,20 +95,20 @@ describe Economic::CreditorContact do 
     | 
|
| 
       86 
95 
     | 
    
         
             
                  end
         
     | 
| 
       87 
96 
     | 
    
         | 
| 
       88 
97 
     | 
    
         
             
                  it "should not clear cached creditor nor fetch the creditor from API" do
         
     | 
| 
       89 
     | 
    
         
            -
                     
     | 
| 
      
 98 
     | 
    
         
            +
                    expect(session).to receive(:request).never
         
     | 
| 
       90 
99 
     | 
    
         
             
                    subject.creditor_handle = handle
         
     | 
| 
       91 
     | 
    
         
            -
                    subject.creditor. 
     | 
| 
      
 100 
     | 
    
         
            +
                    expect(subject.creditor).to be_instance_of(Economic::Creditor)
         
     | 
| 
       92 
101 
     | 
    
         
             
                  end
         
     | 
| 
       93 
102 
     | 
    
         
             
                end
         
     | 
| 
       94 
103 
     | 
    
         
             
              end
         
     | 
| 
       95 
104 
     | 
    
         | 
| 
       96 
105 
     | 
    
         
             
              describe ".proxy" do
         
     | 
| 
       97 
106 
     | 
    
         
             
                it "should return a CreditorContactProxy" do
         
     | 
| 
       98 
     | 
    
         
            -
                  subject.proxy. 
     | 
| 
      
 107 
     | 
    
         
            +
                  expect(subject.proxy).to be_instance_of(Economic::CreditorContactProxy)
         
     | 
| 
       99 
108 
     | 
    
         
             
                end
         
     | 
| 
       100 
109 
     | 
    
         | 
| 
       101 
110 
     | 
    
         
             
                it "should return a proxy owned by session" do
         
     | 
| 
       102 
     | 
    
         
            -
                  subject.proxy.session. 
     | 
| 
      
 111 
     | 
    
         
            +
                  expect(subject.proxy.session).to eq(session)
         
     | 
| 
       103 
112 
     | 
    
         
             
                end
         
     | 
| 
       104 
113 
     | 
    
         
             
              end
         
     | 
| 
       105 
114 
     | 
    
         | 
| 
         @@ -5,7 +5,7 @@ describe Economic::Creditor do 
     | 
|
| 
       5 
5 
     | 
    
         
             
              subject { Economic::Creditor.new(:session => session) }
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
7 
     | 
    
         
             
              it "inherits from Economic::Entity" do
         
     | 
| 
       8 
     | 
    
         
            -
                Economic::Creditor.ancestors. 
     | 
| 
      
 8 
     | 
    
         
            +
                expect(Economic::Creditor.ancestors).to include(Economic::Entity)
         
     | 
| 
       9 
9 
     | 
    
         
             
              end
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
11 
     | 
    
         
             
              describe "class methods" do
         
     | 
| 
         @@ -13,39 +13,39 @@ describe Economic::Creditor do 
     | 
|
| 
       13 
13 
     | 
    
         | 
| 
       14 
14 
     | 
    
         
             
                describe ".proxy" do
         
     | 
| 
       15 
15 
     | 
    
         
             
                  it "should return CreditorProxy" do
         
     | 
| 
       16 
     | 
    
         
            -
                    subject.proxy. 
     | 
| 
      
 16 
     | 
    
         
            +
                    expect(subject.proxy).to eq(Economic::CreditorProxy)
         
     | 
| 
       17 
17 
     | 
    
         
             
                  end
         
     | 
| 
       18 
18 
     | 
    
         
             
                end
         
     | 
| 
       19 
19 
     | 
    
         | 
| 
       20 
20 
     | 
    
         
             
                describe ".key" do
         
     | 
| 
       21 
21 
     | 
    
         
             
                  it "should == :creditor" do
         
     | 
| 
       22 
     | 
    
         
            -
                    Economic::Creditor.key. 
     | 
| 
      
 22 
     | 
    
         
            +
                    expect(Economic::Creditor.key).to eq(:creditor)
         
     | 
| 
       23 
23 
     | 
    
         
             
                  end
         
     | 
| 
       24 
24 
     | 
    
         
             
                end
         
     | 
| 
       25 
25 
     | 
    
         
             
              end
         
     | 
| 
       26 
26 
     | 
    
         | 
| 
       27 
27 
     | 
    
         
             
              describe ".contacts" do
         
     | 
| 
       28 
28 
     | 
    
         
             
                it "returns a CreditorContactProxy" do
         
     | 
| 
       29 
     | 
    
         
            -
                  subject.contacts. 
     | 
| 
      
 29 
     | 
    
         
            +
                  expect(subject.contacts).to be_instance_of(Economic::CreditorContactProxy)
         
     | 
| 
       30 
30 
     | 
    
         
             
                end
         
     | 
| 
       31 
31 
     | 
    
         | 
| 
       32 
32 
     | 
    
         
             
                it "memoizes the proxy" do
         
     | 
| 
       33 
     | 
    
         
            -
                  subject.contacts. 
     | 
| 
      
 33 
     | 
    
         
            +
                  expect(subject.contacts).to equal(subject.contacts)
         
     | 
| 
       34 
34 
     | 
    
         
             
                end
         
     | 
| 
       35 
35 
     | 
    
         | 
| 
       36 
36 
     | 
    
         
             
                it "should store the session" do
         
     | 
| 
       37 
     | 
    
         
            -
                  subject.session. 
     | 
| 
       38 
     | 
    
         
            -
                  subject.contacts.session. 
     | 
| 
      
 37 
     | 
    
         
            +
                  expect(subject.session).to_not be_nil
         
     | 
| 
      
 38 
     | 
    
         
            +
                  expect(subject.contacts.session).to eq(subject.session)
         
     | 
| 
       39 
39 
     | 
    
         
             
                end
         
     | 
| 
       40 
40 
     | 
    
         
             
              end
         
     | 
| 
       41 
41 
     | 
    
         | 
| 
       42 
42 
     | 
    
         
             
              describe ".proxy" do
         
     | 
| 
       43 
43 
     | 
    
         
             
                it "should return a CreditorProxy" do
         
     | 
| 
       44 
     | 
    
         
            -
                  subject.proxy. 
     | 
| 
      
 44 
     | 
    
         
            +
                  expect(subject.proxy).to be_instance_of(Economic::CreditorProxy)
         
     | 
| 
       45 
45 
     | 
    
         
             
                end
         
     | 
| 
       46 
46 
     | 
    
         | 
| 
       47 
47 
     | 
    
         
             
                it "should return a proxy owned by session" do
         
     | 
| 
       48 
     | 
    
         
            -
                  subject.proxy.session. 
     | 
| 
      
 48 
     | 
    
         
            +
                  expect(subject.proxy.session).to eq(session)
         
     | 
| 
       49 
49 
     | 
    
         
             
                end
         
     | 
| 
       50 
50 
     | 
    
         
             
              end
         
     | 
| 
       51 
51 
     | 
    
         | 
| 
         @@ -5,7 +5,7 @@ describe Economic::CurrentInvoiceLine do 
     | 
|
| 
       5 
5 
     | 
    
         
             
              subject { (l = Economic::CurrentInvoiceLine.new).tap { l.session = session } }
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
7 
     | 
    
         
             
              it "inherits from Economic::Entity" do
         
     | 
| 
       8 
     | 
    
         
            -
                Economic::CurrentInvoiceLine.ancestors. 
     | 
| 
      
 8 
     | 
    
         
            +
                expect(Economic::CurrentInvoiceLine.ancestors).to include(Economic::Entity)
         
     | 
| 
       9 
9 
     | 
    
         
             
              end
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
11 
     | 
    
         
             
              describe "equality" do
         
     | 
| 
         @@ -13,14 +13,14 @@ describe Economic::CurrentInvoiceLine do 
     | 
|
| 
       13 
13 
     | 
    
         
             
                  line1 = Economic::CurrentInvoiceLine.new({})
         
     | 
| 
       14 
14 
     | 
    
         
             
                  line2 = Economic::CurrentInvoiceLine.new({})
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
     | 
    
         
            -
                  line1. 
     | 
| 
      
 16 
     | 
    
         
            +
                  expect(line1).not_to eq(line2)
         
     | 
| 
       17 
17 
     | 
    
         
             
                end
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
       19 
19 
     | 
    
         
             
                it "should not be equal when numbers are different" do
         
     | 
| 
       20 
20 
     | 
    
         
             
                  line1 = Economic::CurrentInvoiceLine.new({:number => 1})
         
     | 
| 
       21 
21 
     | 
    
         
             
                  line2 = Economic::CurrentInvoiceLine.new({:number => 2})
         
     | 
| 
       22 
22 
     | 
    
         | 
| 
       23 
     | 
    
         
            -
                  line1. 
     | 
| 
      
 23 
     | 
    
         
            +
                  expect(line1).not_to eq(line2)
         
     | 
| 
       24 
24 
     | 
    
         
             
                end
         
     | 
| 
       25 
25 
     | 
    
         
             
              end
         
     | 
| 
       26 
26 
     | 
    
         | 
| 
         @@ -30,18 +30,18 @@ describe Economic::CurrentInvoiceLine do 
     | 
|
| 
       30 
30 
     | 
    
         | 
| 
       31 
31 
     | 
    
         
             
                  subject.invoice = invoice
         
     | 
| 
       32 
32 
     | 
    
         | 
| 
       33 
     | 
    
         
            -
                  subject.invoice. 
     | 
| 
       34 
     | 
    
         
            -
                  subject.invoice_handle. 
     | 
| 
      
 33 
     | 
    
         
            +
                  expect(subject.invoice).to eq(invoice)
         
     | 
| 
      
 34 
     | 
    
         
            +
                  expect(subject.invoice_handle).to eq(invoice.handle)
         
     | 
| 
       35 
35 
     | 
    
         
             
                end
         
     | 
| 
       36 
36 
     | 
    
         
             
              end
         
     | 
| 
       37 
37 
     | 
    
         | 
| 
       38 
38 
     | 
    
         
             
              describe ".proxy" do
         
     | 
| 
       39 
39 
     | 
    
         
             
                it "should return a CurrentInvoiceLineProxy" do
         
     | 
| 
       40 
     | 
    
         
            -
                  subject.proxy. 
     | 
| 
      
 40 
     | 
    
         
            +
                  expect(subject.proxy).to be_instance_of(Economic::CurrentInvoiceLineProxy)
         
     | 
| 
       41 
41 
     | 
    
         
             
                end
         
     | 
| 
       42 
42 
     | 
    
         | 
| 
       43 
43 
     | 
    
         
             
                it "should return a proxy owned by session" do
         
     | 
| 
       44 
     | 
    
         
            -
                  subject.proxy.session. 
     | 
| 
      
 44 
     | 
    
         
            +
                  expect(subject.proxy.session).to eq(session)
         
     | 
| 
       45 
45 
     | 
    
         
             
                end
         
     | 
| 
       46 
46 
     | 
    
         
             
              end
         
     | 
| 
       47 
47 
     | 
    
         | 
| 
         @@ -5,67 +5,102 @@ describe Economic::CurrentInvoice do 
     | 
|
| 
       5 
5 
     | 
    
         
             
              subject { (i = Economic::CurrentInvoice.new( :id => 512 )).tap { i.session = session } }
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
7 
     | 
    
         
             
              it "inherits from Economic::Entity" do
         
     | 
| 
       8 
     | 
    
         
            -
                Economic::CurrentInvoice.ancestors. 
     | 
| 
      
 8 
     | 
    
         
            +
                expect(Economic::CurrentInvoice.ancestors).to include(Economic::Entity)
         
     | 
| 
       9 
9 
     | 
    
         
             
              end
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
11 
     | 
    
         
             
              describe "new" do
         
     | 
| 
       12 
12 
     | 
    
         
             
                it "initializes lines as an empty proxy" do
         
     | 
| 
       13 
     | 
    
         
            -
                  subject.lines. 
     | 
| 
       14 
     | 
    
         
            -
                  subject.lines. 
     | 
| 
      
 13 
     | 
    
         
            +
                  expect(subject.lines).to be_instance_of(Economic::CurrentInvoiceLineProxy)
         
     | 
| 
      
 14 
     | 
    
         
            +
                  expect(subject.lines).to be_empty
         
     | 
| 
       15 
15 
     | 
    
         
             
                end
         
     | 
| 
       16 
16 
     | 
    
         
             
              end
         
     | 
| 
       17 
17 
     | 
    
         | 
| 
       18 
18 
     | 
    
         
             
              describe ".key" do
         
     | 
| 
       19 
19 
     | 
    
         
             
                it "should == :current_invoice" do
         
     | 
| 
       20 
     | 
    
         
            -
                  Economic::CurrentInvoice.key. 
     | 
| 
      
 20 
     | 
    
         
            +
                  expect(Economic::CurrentInvoice.key).to eq(:current_invoice)
         
     | 
| 
       21 
21 
     | 
    
         
             
                end
         
     | 
| 
       22 
22 
     | 
    
         
             
              end
         
     | 
| 
       23 
23 
     | 
    
         | 
| 
       24 
24 
     | 
    
         
             
              describe ".proxy" do
         
     | 
| 
       25 
25 
     | 
    
         
             
                it "should return a CurrentInvoiceProxy" do
         
     | 
| 
       26 
     | 
    
         
            -
                  subject.proxy. 
     | 
| 
      
 26 
     | 
    
         
            +
                  expect(subject.proxy).to be_instance_of(Economic::CurrentInvoiceProxy)
         
     | 
| 
       27 
27 
     | 
    
         
             
                end
         
     | 
| 
       28 
28 
     | 
    
         | 
| 
       29 
29 
     | 
    
         
             
                it "should return a proxy owned by session" do
         
     | 
| 
       30 
     | 
    
         
            -
                  subject.proxy.session. 
     | 
| 
      
 30 
     | 
    
         
            +
                  expect(subject.proxy.session).to eq(session)
         
     | 
| 
       31 
31 
     | 
    
         
             
                end
         
     | 
| 
       32 
32 
     | 
    
         
             
              end
         
     | 
| 
       33 
33 
     | 
    
         | 
| 
       34 
34 
     | 
    
         
             
              describe "save" do
         
     | 
| 
       35 
35 
     | 
    
         
             
                context "when successful" do
         
     | 
| 
       36 
     | 
    
         
            -
                   
     | 
| 
       37 
     | 
    
         
            -
                     
     | 
| 
      
 36 
     | 
    
         
            +
                  it "builds and sends data to API" do
         
     | 
| 
      
 37 
     | 
    
         
            +
                    time = Time.now
         
     | 
| 
      
 38 
     | 
    
         
            +
                    subject.date = time
         
     | 
| 
      
 39 
     | 
    
         
            +
                    subject.attention_handle = Economic::Entity::Handle.new(:id => 42)
         
     | 
| 
      
 40 
     | 
    
         
            +
                    subject.term_of_payment_handle = Economic::Entity::Handle.new(:id => 37)
         
     | 
| 
      
 41 
     | 
    
         
            +
                    subject.currency_handle = Economic::Entity::Handle.new({:code => "BTC"})
         
     | 
| 
      
 42 
     | 
    
         
            +
                    subject.layout_handle = Economic::Entity::Handle.new(:id => 314)
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                    mock_request(
         
     | 
| 
      
 45 
     | 
    
         
            +
                      "CurrentInvoice_CreateFromData", {
         
     | 
| 
      
 46 
     | 
    
         
            +
                        "data" => {
         
     | 
| 
      
 47 
     | 
    
         
            +
                          "Id" => 512,
         
     | 
| 
      
 48 
     | 
    
         
            +
                          "DebtorName" => nil,
         
     | 
| 
      
 49 
     | 
    
         
            +
                          "AttentionHandle" => {"Id" => 42},
         
     | 
| 
      
 50 
     | 
    
         
            +
                          "Date" => time.iso8601,
         
     | 
| 
      
 51 
     | 
    
         
            +
                          "TermOfPaymentHandle" => {"Id" => 37},
         
     | 
| 
      
 52 
     | 
    
         
            +
                          "DueDate" => nil,
         
     | 
| 
      
 53 
     | 
    
         
            +
                          "CurrencyHandle" => {"Code" => "BTC"},
         
     | 
| 
      
 54 
     | 
    
         
            +
                          "ExchangeRate" => 100,
         
     | 
| 
      
 55 
     | 
    
         
            +
                          "IsVatIncluded" => nil,
         
     | 
| 
      
 56 
     | 
    
         
            +
                          "LayoutHandle" => {"Id" => 314},
         
     | 
| 
      
 57 
     | 
    
         
            +
                          "DeliveryDate" => nil,
         
     | 
| 
      
 58 
     | 
    
         
            +
                          "NetAmount" => 0,
         
     | 
| 
      
 59 
     | 
    
         
            +
                          "VatAmount" => 0,
         
     | 
| 
      
 60 
     | 
    
         
            +
                          "GrossAmount" => 0,
         
     | 
| 
      
 61 
     | 
    
         
            +
                          "Margin" => 0,
         
     | 
| 
      
 62 
     | 
    
         
            +
                          "MarginAsPercent" => 0
         
     | 
| 
      
 63 
     | 
    
         
            +
                        }
         
     | 
| 
      
 64 
     | 
    
         
            +
                      },
         
     | 
| 
      
 65 
     | 
    
         
            +
                      :success
         
     | 
| 
      
 66 
     | 
    
         
            +
                    )
         
     | 
| 
      
 67 
     | 
    
         
            +
                    subject.save
         
     | 
| 
       38 
68 
     | 
    
         
             
                  end
         
     | 
| 
       39 
69 
     | 
    
         | 
| 
       40 
70 
     | 
    
         
             
                  it "updates id with the created id" do
         
     | 
| 
      
 71 
     | 
    
         
            +
                    stub_request('CurrentInvoice_CreateFromData', nil, :success)
         
     | 
| 
       41 
72 
     | 
    
         
             
                    subject.save
         
     | 
| 
       42 
     | 
    
         
            -
                    subject.id. 
     | 
| 
      
 73 
     | 
    
         
            +
                    expect(subject.id).to eq(42)
         
     | 
| 
       43 
74 
     | 
    
         
             
                  end
         
     | 
| 
       44 
75 
     | 
    
         | 
| 
       45 
76 
     | 
    
         
             
                  it "updates handle with the created id" do
         
     | 
| 
      
 77 
     | 
    
         
            +
                    stub_request('CurrentInvoice_CreateFromData', nil, :success)
         
     | 
| 
      
 78 
     | 
    
         
            +
             
     | 
| 
       46 
79 
     | 
    
         
             
                    invoice = Economic::CurrentInvoice.new({})
         
     | 
| 
       47 
80 
     | 
    
         
             
                    invoice.session = session
         
     | 
| 
       48 
81 
     | 
    
         | 
| 
       49 
82 
     | 
    
         
             
                    # This line memoizes the handle with the wrong/old id (0). This is what
         
     | 
| 
       50 
83 
     | 
    
         
             
                    # we're testing changes
         
     | 
| 
       51 
     | 
    
         
            -
                    invoice.handle.id. 
     | 
| 
      
 84 
     | 
    
         
            +
                    expect(invoice.handle.id).to eq(0)
         
     | 
| 
       52 
85 
     | 
    
         | 
| 
       53 
86 
     | 
    
         
             
                    invoice.save
         
     | 
| 
       54 
     | 
    
         
            -
                    invoice.handle. 
     | 
| 
      
 87 
     | 
    
         
            +
                    expect(invoice.handle).to eq(Economic::Entity::Handle.new(:id => 42))
         
     | 
| 
       55 
88 
     | 
    
         
             
                  end
         
     | 
| 
       56 
89 
     | 
    
         | 
| 
       57 
90 
     | 
    
         
             
                  context "when invoice has lines" do
         
     | 
| 
       58 
91 
     | 
    
         
             
                    before :each do
         
     | 
| 
      
 92 
     | 
    
         
            +
                      stub_request('CurrentInvoice_CreateFromData', nil, :success)
         
     | 
| 
      
 93 
     | 
    
         
            +
             
     | 
| 
       59 
94 
     | 
    
         
             
                      2.times do
         
     | 
| 
       60 
95 
     | 
    
         
             
                        line = Economic::CurrentInvoiceLine.new
         
     | 
| 
       61 
     | 
    
         
            -
                        line. 
     | 
| 
      
 96 
     | 
    
         
            +
                        allow(line).to receive(:save)
         
     | 
| 
       62 
97 
     | 
    
         
             
                        subject.lines << line
         
     | 
| 
       63 
98 
     | 
    
         
             
                      end
         
     | 
| 
       64 
99 
     | 
    
         
             
                    end
         
     | 
| 
       65 
100 
     | 
    
         | 
| 
       66 
101 
     | 
    
         
             
                    it "adds the lines to the invoice" do
         
     | 
| 
       67 
102 
     | 
    
         
             
                      subject.lines.each do |line|
         
     | 
| 
       68 
     | 
    
         
            -
                        line. 
     | 
| 
      
 103 
     | 
    
         
            +
                        expect(line).to receive(:invoice=).with(subject)
         
     | 
| 
       69 
104 
     | 
    
         
             
                      end
         
     | 
| 
       70 
105 
     | 
    
         | 
| 
       71 
106 
     | 
    
         
             
                      subject.save
         
     | 
| 
         @@ -73,7 +108,7 @@ describe Economic::CurrentInvoice do 
     | 
|
| 
       73 
108 
     | 
    
         | 
| 
       74 
109 
     | 
    
         
             
                    it "assigns the invoice session to each line" do
         
     | 
| 
       75 
110 
     | 
    
         
             
                      subject.lines.each do |line|
         
     | 
| 
       76 
     | 
    
         
            -
                        line. 
     | 
| 
      
 111 
     | 
    
         
            +
                        expect(line).to receive(:session=).with(subject.session)
         
     | 
| 
       77 
112 
     | 
    
         
             
                      end
         
     | 
| 
       78 
113 
     | 
    
         | 
| 
       79 
114 
     | 
    
         
             
                      subject.save
         
     | 
| 
         @@ -81,7 +116,7 @@ describe Economic::CurrentInvoice do 
     | 
|
| 
       81 
116 
     | 
    
         | 
| 
       82 
117 
     | 
    
         
             
                    it "saves each line" do
         
     | 
| 
       83 
118 
     | 
    
         
             
                      subject.lines.each do |line|
         
     | 
| 
       84 
     | 
    
         
            -
                        line. 
     | 
| 
      
 119 
     | 
    
         
            +
                        expect(line).to receive(:save)
         
     | 
| 
       85 
120 
     | 
    
         
             
                      end
         
     | 
| 
       86 
121 
     | 
    
         | 
| 
       87 
122 
     | 
    
         
             
                      subject.save
         
     | 
| 
         @@ -91,32 +126,29 @@ describe Economic::CurrentInvoice do 
     | 
|
| 
       91 
126 
     | 
    
         
             
              end
         
     | 
| 
       92 
127 
     | 
    
         | 
| 
       93 
128 
     | 
    
         
             
              describe "#book" do
         
     | 
| 
       94 
     | 
    
         
            -
                before :each do
         
     | 
| 
       95 
     | 
    
         
            -
                  savon.stubs('CurrentInvoice_Book').returns(:success)
         
     | 
| 
       96 
     | 
    
         
            -
                  savon.stubs('Invoice_GetData').returns(:success)
         
     | 
| 
       97 
     | 
    
         
            -
                end
         
     | 
| 
       98 
     | 
    
         
            -
             
     | 
| 
       99 
129 
     | 
    
         
             
                it 'should book the current invoice and return the created invoice object' do
         
     | 
| 
       100 
     | 
    
         
            -
                   
     | 
| 
       101 
     | 
    
         
            -
                   
     | 
| 
      
 130 
     | 
    
         
            +
                  stub_request('CurrentInvoice_Book', nil, :success)
         
     | 
| 
      
 131 
     | 
    
         
            +
                  mock_request("Invoice_GetData", {'entityHandle' => { 'Number' => 328 }}, :success)
         
     | 
| 
      
 132 
     | 
    
         
            +
                  expect(subject.book).to be_instance_of(Economic::Invoice)
         
     | 
| 
       102 
133 
     | 
    
         
             
                end
         
     | 
| 
       103 
134 
     | 
    
         | 
| 
       104 
135 
     | 
    
         
             
                it 'should request with the right key for handle' do
         
     | 
| 
       105 
     | 
    
         
            -
                   
     | 
| 
      
 136 
     | 
    
         
            +
                  mock_request("CurrentInvoice_Book", {'currentInvoiceHandle' => { 'Id' => 512 }}, :success)
         
     | 
| 
      
 137 
     | 
    
         
            +
                  stub_request('Invoice_GetData', nil, :success)
         
     | 
| 
       106 
138 
     | 
    
         
             
                  subject.book
         
     | 
| 
       107 
139 
     | 
    
         
             
                end
         
     | 
| 
       108 
140 
     | 
    
         
             
              end
         
     | 
| 
       109 
141 
     | 
    
         | 
| 
       110 
142 
     | 
    
         
             
              describe "#book_with_number" do
         
     | 
| 
       111 
143 
     | 
    
         
             
                it 'should book the current invoice with the given number and return the created invoice object' do
         
     | 
| 
       112 
     | 
    
         
            -
                   
     | 
| 
       113 
     | 
    
         
            -
                   
     | 
| 
       114 
     | 
    
         
            -
                  subject.book_with_number(123). 
     | 
| 
      
 144 
     | 
    
         
            +
                  stub_request('CurrentInvoice_BookWithNumber', nil, :success)
         
     | 
| 
      
 145 
     | 
    
         
            +
                  mock_request("Invoice_GetData", {'entityHandle' => { 'Number' => 123 }}, :success)
         
     | 
| 
      
 146 
     | 
    
         
            +
                  expect(subject.book_with_number(123)).to be_instance_of(Economic::Invoice)
         
     | 
| 
       115 
147 
     | 
    
         
             
                end
         
     | 
| 
       116 
148 
     | 
    
         | 
| 
       117 
149 
     | 
    
         
             
                it 'should request with the right key for handle' do
         
     | 
| 
       118 
     | 
    
         
            -
                   
     | 
| 
       119 
     | 
    
         
            -
                   
     | 
| 
      
 150 
     | 
    
         
            +
                  mock_request("CurrentInvoice_BookWithNumber", {'currentInvoiceHandle' => { 'Id' => 512 }, 'number' => 123}, :success)
         
     | 
| 
      
 151 
     | 
    
         
            +
                  stub_request('Invoice_GetData', nil, :success)
         
     | 
| 
       120 
152 
     | 
    
         
             
                  subject.book_with_number(123)
         
     | 
| 
       121 
153 
     | 
    
         
             
                end
         
     | 
| 
       122 
154 
     | 
    
         
             
              end
         
     | 
| 
         @@ -132,18 +164,35 @@ describe Economic::CurrentInvoice do 
     | 
|
| 
       132 
164 
     | 
    
         | 
| 
       133 
165 
     | 
    
         
             
                it "should be set- and gettable" do
         
     | 
| 
       134 
166 
     | 
    
         
             
                  subject.attention = contact
         
     | 
| 
       135 
     | 
    
         
            -
                  subject. 
     | 
| 
       136 
     | 
    
         
            -
             
     | 
| 
      
 167 
     | 
    
         
            +
                  expect(subject.attention).to eq(contact)
         
     | 
| 
      
 168 
     | 
    
         
            +
                end
         
     | 
| 
      
 169 
     | 
    
         
            +
             
     | 
| 
      
 170 
     | 
    
         
            +
                it "updates the handle" do
         
     | 
| 
      
 171 
     | 
    
         
            +
                  handle = Economic::Entity::Handle.new(:number => 42)
         
     | 
| 
      
 172 
     | 
    
         
            +
                  contact.handle = handle
         
     | 
| 
      
 173 
     | 
    
         
            +
                  subject.attention = contact
         
     | 
| 
      
 174 
     | 
    
         
            +
                  expect(subject.attention_handle).to eq(handle)
         
     | 
| 
       137 
175 
     | 
    
         
             
                end
         
     | 
| 
       138 
176 
     | 
    
         
             
              end
         
     | 
| 
       139 
177 
     | 
    
         | 
| 
       140 
178 
     | 
    
         
             
              describe "#debtor" do
         
     | 
| 
       141 
     | 
    
         
            -
                let(:debtor) { 
     | 
| 
      
 179 
     | 
    
         
            +
                let(:debtor) {
         
     | 
| 
      
 180 
     | 
    
         
            +
                  Economic::Debtor.new.tap do |c|
         
     | 
| 
      
 181 
     | 
    
         
            +
                    c.session = session
         
     | 
| 
      
 182 
     | 
    
         
            +
                    c.number = 5
         
     | 
| 
      
 183 
     | 
    
         
            +
                  end
         
     | 
| 
      
 184 
     | 
    
         
            +
                }
         
     | 
| 
       142 
185 
     | 
    
         | 
| 
       143 
186 
     | 
    
         
             
                it "should be set- and gettable" do
         
     | 
| 
       144 
187 
     | 
    
         
             
                  subject.debtor = debtor
         
     | 
| 
       145 
     | 
    
         
            -
                  subject. 
     | 
| 
       146 
     | 
    
         
            -
             
     | 
| 
      
 188 
     | 
    
         
            +
                  expect(subject.debtor).to eq(debtor)
         
     | 
| 
      
 189 
     | 
    
         
            +
                end
         
     | 
| 
      
 190 
     | 
    
         
            +
             
     | 
| 
      
 191 
     | 
    
         
            +
                it "updates the handle" do
         
     | 
| 
      
 192 
     | 
    
         
            +
                  handle = Economic::Entity::Handle.new(:number => 42)
         
     | 
| 
      
 193 
     | 
    
         
            +
                  debtor.handle = handle
         
     | 
| 
      
 194 
     | 
    
         
            +
                  subject.debtor = debtor
         
     | 
| 
      
 195 
     | 
    
         
            +
                  expect(subject.debtor_handle).to eq(handle)
         
     | 
| 
       147 
196 
     | 
    
         
             
                end
         
     | 
| 
       148 
197 
     | 
    
         
             
              end
         
     | 
| 
       149 
198 
     | 
    
         
             
            end
         
     |