rconomic 0.5.2 → 0.6.0

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 (118) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +40 -0
  3. data/.ruby-version +1 -0
  4. data/.travis.yml +14 -3
  5. data/CHANGELOG.md +28 -0
  6. data/Gemfile +5 -4
  7. data/Guardfile +9 -4
  8. data/README.md +23 -4
  9. data/Rakefile +5 -5
  10. data/gemfiles/Gemfile.ruby-2.0 +14 -0
  11. data/lib/economic/account.rb +3 -3
  12. data/lib/economic/cash_book.rb +4 -7
  13. data/lib/economic/cash_book_entry.rb +4 -24
  14. data/lib/economic/company.rb +61 -0
  15. data/lib/economic/creditor.rb +4 -5
  16. data/lib/economic/creditor_contact.rb +5 -6
  17. data/lib/economic/creditor_entry.rb +1 -3
  18. data/lib/economic/current_invoice.rb +14 -21
  19. data/lib/economic/current_invoice_line.rb +4 -13
  20. data/lib/economic/debtor.rb +10 -11
  21. data/lib/economic/debtor_contact.rb +7 -8
  22. data/lib/economic/debtor_entry.rb +1 -3
  23. data/lib/economic/endpoint.rb +36 -6
  24. data/lib/economic/entity/handle.rb +54 -29
  25. data/lib/economic/entity/mapper.rb +1 -1
  26. data/lib/economic/entity.rb +26 -29
  27. data/lib/economic/entry.rb +1 -2
  28. data/lib/economic/invoice.rb +15 -8
  29. data/lib/economic/order.rb +2 -4
  30. data/lib/economic/product.rb +73 -0
  31. data/lib/economic/proxies/account_proxy.rb +2 -4
  32. data/lib/economic/proxies/actions/debtor_contact/all.rb +63 -0
  33. data/lib/economic/proxies/actions/find_by_ci_number.rb +1 -3
  34. data/lib/economic/proxies/actions/find_by_date_interval.rb +3 -6
  35. data/lib/economic/proxies/actions/find_by_handle_with_number.rb +1 -1
  36. data/lib/economic/proxies/actions/find_by_name.rb +1 -1
  37. data/lib/economic/proxies/actions/find_by_number.rb +2 -4
  38. data/lib/economic/proxies/actions/find_by_telephone_and_fax_number.rb +1 -3
  39. data/lib/economic/proxies/cash_book_entry_proxy.rb +19 -22
  40. data/lib/economic/proxies/cash_book_proxy.rb +5 -10
  41. data/lib/economic/proxies/company_proxy.rb +9 -0
  42. data/lib/economic/proxies/creditor_contact_proxy.rb +2 -2
  43. data/lib/economic/proxies/creditor_entry_proxy.rb +8 -14
  44. data/lib/economic/proxies/creditor_proxy.rb +8 -11
  45. data/lib/economic/proxies/current_invoice_line_proxy.rb +2 -2
  46. data/lib/economic/proxies/current_invoice_proxy.rb +3 -3
  47. data/lib/economic/proxies/debtor_contact_proxy.rb +6 -2
  48. data/lib/economic/proxies/debtor_entry_proxy.rb +6 -10
  49. data/lib/economic/proxies/debtor_proxy.rb +40 -55
  50. data/lib/economic/proxies/entity_proxy.rb +15 -15
  51. data/lib/economic/proxies/entry_proxy.rb +10 -16
  52. data/lib/economic/proxies/invoice_proxy.rb +3 -3
  53. data/lib/economic/proxies/order_proxy.rb +3 -3
  54. data/lib/economic/proxies/product_proxy.rb +11 -0
  55. data/lib/economic/session.rb +48 -21
  56. data/lib/economic/support/string.rb +5 -5
  57. data/lib/rconomic/version.rb +1 -1
  58. data/lib/rconomic.rb +39 -34
  59. data/lib/savon_ext/request.rb +17 -0
  60. data/rconomic.gemspec +8 -7
  61. data/spec/economic/account_spec.rb +3 -3
  62. data/spec/economic/cash_book_entry_spec.rb +26 -3
  63. data/spec/economic/cash_book_spec.rb +7 -7
  64. data/spec/economic/company_spec.rb +20 -0
  65. data/spec/economic/creditor_contact_spec.rb +4 -5
  66. data/spec/economic/creditor_entry_spec.rb +20 -0
  67. data/spec/economic/creditor_spec.rb +3 -3
  68. data/spec/economic/current_invoice_line_spec.rb +3 -3
  69. data/spec/economic/current_invoice_spec.rb +19 -19
  70. data/spec/economic/debtor_contact_spec.rb +4 -5
  71. data/spec/economic/debtor_entry_spec.rb +1 -1
  72. data/spec/economic/debtor_spec.rb +13 -13
  73. data/spec/economic/endpoint_spec.rb +27 -11
  74. data/spec/economic/entity/handle_spec.rb +10 -23
  75. data/spec/economic/entity/mapper_spec.rb +26 -30
  76. data/spec/economic/entity_spec.rb +36 -31
  77. data/spec/economic/entry_spec.rb +1 -1
  78. data/spec/economic/invoice_spec.rb +49 -7
  79. data/spec/economic/order_spec.rb +4 -4
  80. data/spec/economic/product_spec.rb +72 -0
  81. data/spec/economic/proxies/account_proxy_spec.rb +74 -0
  82. data/spec/economic/proxies/actions/debtor_contact/all_spec.rb +26 -0
  83. data/spec/economic/proxies/actions/find_by_name_spec.rb +6 -7
  84. data/spec/economic/proxies/cash_book_entry_proxy_spec.rb +27 -29
  85. data/spec/economic/proxies/cash_book_proxy_spec.rb +14 -22
  86. data/spec/economic/proxies/company_proxy_spec.rb +47 -0
  87. data/spec/economic/proxies/creditor_contact_proxy_spec.rb +11 -5
  88. data/spec/economic/proxies/creditor_entry_proxy_spec.rb +12 -12
  89. data/spec/economic/proxies/creditor_proxy_spec.rb +15 -15
  90. data/spec/economic/proxies/current_invoice_line_proxy_spec.rb +10 -4
  91. data/spec/economic/proxies/current_invoice_proxy_spec.rb +37 -19
  92. data/spec/economic/proxies/debtor_contact_proxy_spec.rb +8 -4
  93. data/spec/economic/proxies/debtor_entry_proxy_spec.rb +21 -11
  94. data/spec/economic/proxies/debtor_proxy_spec.rb +81 -40
  95. data/spec/economic/proxies/entry_proxy_spec.rb +17 -14
  96. data/spec/economic/proxies/invoice_proxy_spec.rb +24 -10
  97. data/spec/economic/proxies/order_proxy_spec.rb +20 -10
  98. data/spec/economic/proxies/product_proxy_spec.rb +86 -0
  99. data/spec/economic/session_spec.rb +74 -35
  100. data/spec/fixtures/account_get_all/multiple.xml +15 -0
  101. data/spec/fixtures/account_get_all/none.xml +8 -0
  102. data/spec/fixtures/account_get_all/single.xml +12 -0
  103. data/spec/fixtures/account_get_data_array/multiple.xml +69 -0
  104. data/spec/fixtures/company_get/success.xml +10 -0
  105. data/spec/fixtures/company_get_data/success.xml +32 -0
  106. data/spec/fixtures/current_invoice_line_create_from_data/success.xml +6 -37
  107. data/spec/fixtures/debtor_create_from_data/success.xml +5 -52
  108. data/spec/fixtures/debtor_get_orders/none.xml +9 -0
  109. data/spec/fixtures/product_create_from_data/success.xml +37 -0
  110. data/spec/fixtures/product_find_by_number/found.xml +10 -0
  111. data/spec/fixtures/product_find_by_number/not_found.xml +6 -0
  112. data/spec/fixtures/product_get_all/multiple.xml +15 -0
  113. data/spec/fixtures/product_get_all/single.xml +12 -0
  114. data/spec/fixtures/product_get_data/success.xml +37 -0
  115. data/spec/fixtures/product_get_data_array/multiple.xml +69 -0
  116. data/spec/spec_helper.rb +6 -9
  117. data/spec/support/factories.rb +14 -14
  118. metadata +54 -9
@@ -1,8 +1,8 @@
1
- require './spec/spec_helper'
1
+ require "./spec/spec_helper"
2
2
 
3
3
  describe Economic::CurrentInvoice do
4
4
  let(:session) { make_session }
5
- subject { (i = Economic::CurrentInvoice.new( :id => 512 )).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
  expect(Economic::CurrentInvoice.ancestors).to include(Economic::Entity)
@@ -38,7 +38,7 @@ describe Economic::CurrentInvoice do
38
38
  subject.date = time
39
39
  subject.attention_handle = Economic::Entity::Handle.new(:id => 42)
40
40
  subject.term_of_payment_handle = Economic::Entity::Handle.new(:id => 37)
41
- subject.currency_handle = Economic::Entity::Handle.new({:code => "BTC"})
41
+ subject.currency_handle = Economic::Entity::Handle.new(:code => "BTC")
42
42
  subject.layout_handle = Economic::Entity::Handle.new(:id => 314)
43
43
 
44
44
  mock_request(
@@ -68,13 +68,13 @@ describe Economic::CurrentInvoice do
68
68
  end
69
69
 
70
70
  it "updates id with the created id" do
71
- stub_request('CurrentInvoice_CreateFromData', nil, :success)
71
+ stub_request("CurrentInvoice_CreateFromData", nil, :success)
72
72
  subject.save
73
73
  expect(subject.id).to eq(42)
74
74
  end
75
75
 
76
76
  it "updates handle with the created id" do
77
- stub_request('CurrentInvoice_CreateFromData', nil, :success)
77
+ stub_request("CurrentInvoice_CreateFromData", nil, :success)
78
78
 
79
79
  invoice = Economic::CurrentInvoice.new({})
80
80
  invoice.session = session
@@ -89,7 +89,7 @@ describe Economic::CurrentInvoice do
89
89
 
90
90
  context "when invoice has lines" do
91
91
  before :each do
92
- stub_request('CurrentInvoice_CreateFromData', nil, :success)
92
+ stub_request("CurrentInvoice_CreateFromData", nil, :success)
93
93
 
94
94
  2.times do
95
95
  line = Economic::CurrentInvoiceLine.new
@@ -126,29 +126,29 @@ describe Economic::CurrentInvoice do
126
126
  end
127
127
 
128
128
  describe "#book" do
129
- it 'should book the current invoice and return the created invoice object' do
130
- stub_request('CurrentInvoice_Book', nil, :success)
131
- mock_request("Invoice_GetData", {'entityHandle' => { 'Number' => 328 }}, :success)
129
+ it "should book the current invoice and return the created invoice object" do
130
+ stub_request("CurrentInvoice_Book", nil, :success)
131
+ mock_request("Invoice_GetData", {"entityHandle" => {"Number" => "328"}}, :success)
132
132
  expect(subject.book).to be_instance_of(Economic::Invoice)
133
133
  end
134
134
 
135
- it 'should request with the right key for handle' do
136
- mock_request("CurrentInvoice_Book", {'currentInvoiceHandle' => { 'Id' => 512 }}, :success)
137
- stub_request('Invoice_GetData', nil, :success)
135
+ it "should request with the right key for handle" do
136
+ mock_request("CurrentInvoice_Book", {"currentInvoiceHandle" => {"Id" => 512}}, :success)
137
+ stub_request("Invoice_GetData", nil, :success)
138
138
  subject.book
139
139
  end
140
140
  end
141
141
 
142
142
  describe "#book_with_number" do
143
- it 'should book the current invoice with the given number and return the created invoice object' do
144
- stub_request('CurrentInvoice_BookWithNumber', nil, :success)
145
- mock_request("Invoice_GetData", {'entityHandle' => { 'Number' => 123 }}, :success)
143
+ it "should book the current invoice with the given number and return the created invoice object" do
144
+ stub_request("CurrentInvoice_BookWithNumber", nil, :success)
145
+ mock_request("Invoice_GetData", {"entityHandle" => {"Number" => "123"}}, :success)
146
146
  expect(subject.book_with_number(123)).to be_instance_of(Economic::Invoice)
147
147
  end
148
148
 
149
- it 'should request with the right key for handle' do
150
- mock_request("CurrentInvoice_BookWithNumber", {'currentInvoiceHandle' => { 'Id' => 512 }, 'number' => 123}, :success)
151
- stub_request('Invoice_GetData', nil, :success)
149
+ it "should request with the right key for handle" do
150
+ mock_request("CurrentInvoice_BookWithNumber", {"currentInvoiceHandle" => {"Id" => 512}, "number" => 123}, :success)
151
+ stub_request("Invoice_GetData", nil, :success)
152
152
  subject.book_with_number(123)
153
153
  end
154
154
  end
@@ -156,7 +156,7 @@ describe Economic::CurrentInvoice do
156
156
  describe "#attention" do
157
157
  let(:contact) {
158
158
  c = Economic::DebtorContact.new(
159
- :handle => Economic::Entity::Handle.new({:id => 12, :number => 34})
159
+ :handle => Economic::Entity::Handle.new(:id => 12, :number => 34)
160
160
  )
161
161
  c.session = session
162
162
  c
@@ -1,4 +1,4 @@
1
- require './spec/spec_helper'
1
+ require "./spec/spec_helper"
2
2
 
3
3
  describe Economic::DebtorContact do
4
4
  let(:session) { make_session }
@@ -43,7 +43,7 @@ describe Economic::DebtorContact do
43
43
  end
44
44
 
45
45
  context "when debtor_handle is set" do
46
- let(:handle) { Economic::DebtorContact::Handle.new({:number => 42}) }
46
+ let(:handle) { Economic::DebtorContact::Handle.new(:number => 42) }
47
47
 
48
48
  before :each do
49
49
  subject.debtor_handle = handle
@@ -84,8 +84,8 @@ describe Economic::DebtorContact do
84
84
  end
85
85
 
86
86
  it "should clear cached debtor and fetch the new debtor from API" do
87
- stub_request('Debtor_GetData', nil, :success)
88
- subject.debtor_handle = Economic::Debtor::Handle.new({:number => 1234})
87
+ stub_request("Debtor_GetData", nil, :success)
88
+ subject.debtor_handle = Economic::Debtor::Handle.new(:number => 1234)
89
89
  expect(subject.debtor).to be_instance_of(Economic::Debtor)
90
90
  end
91
91
  end
@@ -112,5 +112,4 @@ describe Economic::DebtorContact do
112
112
  expect(subject.proxy.session).to eq(session)
113
113
  end
114
114
  end
115
-
116
115
  end
@@ -1,4 +1,4 @@
1
- require './spec/spec_helper'
1
+ require "./spec/spec_helper"
2
2
 
3
3
  describe Economic::DebtorEntry do
4
4
  let(:session) { make_session }
@@ -1,4 +1,4 @@
1
- require './spec/spec_helper'
1
+ require "./spec/spec_helper"
2
2
 
3
3
  describe Economic::Debtor do
4
4
  let(:session) { make_session }
@@ -61,8 +61,8 @@ describe Economic::Debtor do
61
61
  expect(subject.invoices).to be_empty
62
62
  end
63
63
  it "returns invoices if there is a handle" do
64
- mock_request('Debtor_GetInvoices', {"debtorHandle"=>{"Number"=>1}}, :success)
65
- subject.handle = Economic::Entity::Handle.new({:number => "1"})
64
+ mock_request("Debtor_GetInvoices", {"debtorHandle" => {"Number" => "1"}}, :success)
65
+ subject.handle = Economic::Entity::Handle.new(:number => "1")
66
66
  subject.invoices.each do |i|
67
67
  expect(i).to be_instance_of(Economic::Invoice)
68
68
  end
@@ -74,8 +74,8 @@ describe Economic::Debtor do
74
74
  expect(subject.orders).to be_empty
75
75
  end
76
76
  it "returns invoices if there is a handle" do
77
- mock_request('Debtor_GetOrders', {"debtorHandle"=>{"Number"=>1}}, :success)
78
- subject.handle = Economic::Entity::Handle.new({:number => "1"})
77
+ mock_request("Debtor_GetOrders", {"debtorHandle" => {"Number" => "1"}}, :success)
78
+ subject.handle = Economic::Entity::Handle.new(:number => "1")
79
79
  subject.orders.each do |i|
80
80
  expect(i).to be_instance_of(Economic::Order)
81
81
  end
@@ -88,8 +88,8 @@ describe Economic::Debtor do
88
88
  end
89
89
 
90
90
  it "returns debtor contacts if there is a handle" do
91
- mock_request('Debtor_GetDebtorContacts', {"debtorHandle"=>{"Number"=>1}}, :multiple)
92
- subject.handle = Economic::Entity::Handle.new({:number => "1"})
91
+ mock_request("Debtor_GetDebtorContacts", {"debtorHandle" => {"Number" => "1"}}, :multiple)
92
+ subject.handle = Economic::Entity::Handle.new(:number => "1")
93
93
  subject.contacts.each do |contact|
94
94
  expect(contact).to be_instance_of(Economic::DebtorContact)
95
95
  end
@@ -119,8 +119,8 @@ describe Economic::Debtor do
119
119
  end
120
120
 
121
121
  describe "#save" do
122
- it 'should save it' do
123
- stub_request('Debtor_CreateFromData', nil, :success)
122
+ it "should save it" do
123
+ stub_request("Debtor_CreateFromData", nil, :success)
124
124
  subject.save
125
125
  end
126
126
 
@@ -143,10 +143,10 @@ describe Economic::Debtor do
143
143
  :success
144
144
  )
145
145
 
146
- subject.debtor_group_handle = Economic::Entity::Handle.new({:number => 42})
147
- subject.currency_handle = Economic::Entity::Handle.new({:code => 'BTC'})
148
- subject.price_group_handle = Economic::Entity::Handle.new({:number => 37})
149
- subject.term_of_payment_handle = Economic::Entity::Handle.new({:id => 314})
146
+ subject.debtor_group_handle = Economic::Entity::Handle.new(:number => 42)
147
+ subject.currency_handle = Economic::Entity::Handle.new(:code => "BTC")
148
+ subject.price_group_handle = Economic::Entity::Handle.new(:number => 37)
149
+ subject.term_of_payment_handle = Economic::Entity::Handle.new(:id => 314)
150
150
  subject.layout_handle = Economic::Entity::Handle.new({:id => 21})
151
151
 
152
152
  subject.save
@@ -1,4 +1,4 @@
1
- require './spec/spec_helper'
1
+ require "./spec/spec_helper"
2
2
 
3
3
  describe Economic::Endpoint do
4
4
  subject { Economic::Endpoint.new }
@@ -11,28 +11,28 @@ describe Economic::Endpoint do
11
11
  it "uses the SOAP client to invoke a SOAP action on the API" do
12
12
  expect(client).to receive(:call).with(
13
13
  :foo_bar,
14
- :message => {:baz => 'qux'}
14
+ :message => {:baz => "qux"}
15
15
  ).and_return({})
16
- subject.call(:foo_bar, {:baz => 'qux'})
16
+ subject.call(:foo_bar, :baz => "qux")
17
17
  end
18
18
 
19
19
  it "sends an actual request" do
20
- mock_request('Connect', nil, :success)
20
+ mock_request("Connect", nil, :success)
21
21
  subject.call(:connect)
22
22
  end
23
23
 
24
24
  it "returns a hash with data" do
25
- stub_request('CurrentInvoice_GetAll', nil, :single)
26
- expect(subject.call(:current_invoice_get_all)).to eq({:current_invoice_handle => {:id => "1"}})
25
+ stub_request("CurrentInvoice_GetAll", nil, :single)
26
+ expect(subject.call(:current_invoice_get_all)).to eq(:current_invoice_handle => {:id => "1"})
27
27
  end
28
28
 
29
29
  it "returns an empty hash if no data returned" do
30
- stub_request('CurrentInvoice_GetAll', nil, :none)
30
+ stub_request("CurrentInvoice_GetAll", nil, :none)
31
31
  expect(subject.call(:current_invoice_get_all)).to be_empty
32
32
  end
33
33
 
34
34
  it "yields a Savon response" do
35
- stub_request('CurrentInvoice_GetAll', nil, :single)
35
+ stub_request("CurrentInvoice_GetAll", nil, :single)
36
36
  @yielded_value = nil
37
37
  subject.call(:current_invoice_get_all) do |response|
38
38
  @yielded_value = response
@@ -71,19 +71,35 @@ describe Economic::Endpoint do
71
71
 
72
72
  describe "savon globals configuration" do
73
73
  it "sets the log_level option of the endpoint" do
74
- subject.client.globals.should_receive(:log_level).with(:fatal)
74
+ expect(subject.client.globals).to receive(:log_level).with(:fatal)
75
75
  subject.log_level = :fatal
76
76
  end
77
77
 
78
78
  it "sets the log option of the endpoint" do
79
- subject.client.globals.should_receive(:log).with(true)
79
+ expect(subject.client.globals).to receive(:log).with(true)
80
80
  subject.log = true
81
81
  end
82
82
 
83
83
  it "sets the logger option of the boolean" do
84
84
  logger = double("MyLogger")
85
- subject.client.globals.should_receive(:logger).with(logger)
85
+ expect(subject.client.globals).to receive(:logger).with(logger)
86
86
  subject.logger = logger
87
87
  end
88
88
  end
89
+
90
+ describe "app identifier configuration" do
91
+ let(:app_id) { "my awesome app v.4.0.9-beta-rc1" }
92
+
93
+ subject {
94
+ described_class.new(app_id)
95
+ }
96
+
97
+ it "adds the app identifier HTTP headers" do
98
+ client = subject.client(:force_new_instance => true)
99
+ globals = client.globals
100
+ expect(
101
+ globals[:headers]["X-EconomicAppIdentifier"]
102
+ ).to eq(app_id)
103
+ end
104
+ end
89
105
  end
@@ -1,4 +1,4 @@
1
- require './spec/spec_helper'
1
+ require "./spec/spec_helper"
2
2
 
3
3
  describe Economic::Entity::Handle do
4
4
  describe "equality" do
@@ -56,17 +56,6 @@ describe Economic::Entity::Handle do
56
56
  end).to raise_error(ArgumentError)
57
57
  end
58
58
 
59
- it "should assume :id if argument is numeric" do
60
- handle = Economic::Entity::Handle.new(12)
61
- expect(handle.id).to eq(12)
62
- expect(handle.number).to be_nil
63
- end
64
-
65
- it "should use to_i on numeric argument" do
66
- handle = Economic::Entity::Handle.new("42")
67
- expect(handle.id).to eq(42)
68
- end
69
-
70
59
  it "should raise error if argument is nil" do
71
60
  expect(lambda do
72
61
  Economic::Entity::Handle.new(nil)
@@ -95,7 +84,7 @@ describe Economic::Entity::Handle do
95
84
  expect(handle.number).to eq(42)
96
85
  end
97
86
 
98
- it 'should set id1 and id2' do
87
+ it "should set id1 and id2" do
99
88
  handle = Economic::Entity::Handle.new(:id1 => 37, :id2 => 42)
100
89
  expect(handle.id1).to eq(37)
101
90
  expect(handle.id2).to eq(42)
@@ -104,7 +93,6 @@ describe Economic::Entity::Handle do
104
93
  it "should to_i values" do
105
94
  handle = Economic::Entity::Handle.new(:id => "37", :number => "42")
106
95
  expect(handle.id).to eq(37)
107
- expect(handle.number).to eq(42)
108
96
  end
109
97
 
110
98
  it "should not to_i nil values" do
@@ -114,7 +102,7 @@ describe Economic::Entity::Handle do
114
102
  end
115
103
 
116
104
  it "should accept a Hash with capitalized keys" do
117
- handle = Economic::Entity::Handle.new({"Id" => 37, "Number" => 42})
105
+ handle = Economic::Entity::Handle.new("Id" => 37, "Number" => 42)
118
106
  expect(handle.id).to eq(37)
119
107
  expect(handle.number).to eq(42)
120
108
  end
@@ -138,11 +126,11 @@ describe Economic::Entity::Handle do
138
126
  end
139
127
 
140
128
  it "returns nil when hash has no values" do
141
- expect(Economic::Entity::Handle.build({:id => nil, :number => nil})).to be_empty
129
+ expect(Economic::Entity::Handle.build(:id => nil, :number => nil)).to be_empty
142
130
  end
143
131
 
144
132
  it "returns handle when hash has values" do
145
- expect(Economic::Entity::Handle.build({:id2 => 42})).to eq(Economic::Entity::Handle.new({:id2 => 42}))
133
+ expect(Economic::Entity::Handle.build(:id2 => 42)).to eq(Economic::Entity::Handle.new(:id2 => 42))
146
134
  end
147
135
 
148
136
  it "returns a given handle" do
@@ -157,24 +145,23 @@ describe Economic::Entity::Handle do
157
145
  end
158
146
 
159
147
  it "returns false when handle has a value" do
160
- expect(Economic::Entity::Handle.new({:serial_number => 12})).to_not be_empty
148
+ expect(Economic::Entity::Handle.new(:serial_number => 12)).to_not be_empty
161
149
  end
162
150
  end
163
151
 
164
152
  describe ".to_hash" do
165
- subject { Economic::Entity::Handle.new({:id => 42, :number => 37, :serial_number => 7, :code => "USD", :name => "Bob", :vat_code => 1}) }
153
+ subject { Economic::Entity::Handle.new(:id => 42, :number => 37, :serial_number => 7, :code => "USD", :name => "Bob", :vat_code => 1) }
166
154
 
167
155
  it "should return a handle for putting into the body of a SOAP request" do
168
- expect(subject.to_hash).to eq({'Id' => 42, 'Number' => 37, 'SerialNumber' => 7, 'Code' => 'USD', 'Name' => 'Bob', 'VatCode' => 1})
156
+ expect(subject.to_hash).to eq("Id" => 42, "Number" => 37, "SerialNumber" => 7, "Code" => "USD", "Name" => "Bob", "VatCode" => 1)
169
157
  end
170
158
 
171
159
  it "includes only the named value in the hash" do
172
- expect(subject.to_hash(:id)).to eq({'Id' => 42})
160
+ expect(subject.to_hash(:id)).to eq("Id" => 42)
173
161
  end
174
162
 
175
163
  it "includes only the named values in the hash" do
176
- expect(subject.to_hash([:id, :serial_number])).to eq({'Id' => 42, 'SerialNumber' => 7})
164
+ expect(subject.to_hash([:id, :serial_number])).to eq("Id" => 42, "SerialNumber" => 7)
177
165
  end
178
166
  end
179
167
  end
180
-
@@ -1,20 +1,20 @@
1
- require './spec/spec_helper'
1
+ require "./spec/spec_helper"
2
2
 
3
3
  describe Economic::Entity::Mapper do
4
- let(:entity) { double("Entity", {
5
- :handle => Economic::Entity::Handle.new(:id => 42),
6
- :creditor_handle => Economic::Entity::Handle.new(:number => 37),
7
- :name => "David Brent",
8
- :is_to_receive_email_copy_of_order => true
9
- }) }
4
+ let(:entity) {
5
+ double("Entity", :handle => Economic::Entity::Handle.new(:id => 42),
6
+ :creditor_handle => Economic::Entity::Handle.new(:number => 37),
7
+ :name => "David Brent",
8
+ :is_to_receive_email_copy_of_order => true)
9
+ }
10
10
 
11
11
  let(:fields) {
12
12
  [
13
- ["Handle", :handle, Proc.new { |v| v.to_hash }, :required],
14
- ["CreditorHandle", :creditor_handle, Proc.new { |v| {"Number" => v[:number] }}],
15
- ["Id", :handle, Proc.new { |v| v.id }, :required],
13
+ ["Handle", :handle, proc { |v| v.to_hash }, :required],
14
+ ["CreditorHandle", :creditor_handle, proc { |v| {"Number" => v[:number]} }],
15
+ ["Id", :handle, proc { |v| v.id }, :required],
16
16
  ["Name", :name],
17
- ["IsToReceiveEmailCopyOfOrder", :is_to_receive_email_copy_of_order, Proc.new { |v| v || false }, :required],
17
+ ["IsToReceiveEmailCopyOfOrder", :is_to_receive_email_copy_of_order, proc { |v| v || false }, :required]
18
18
  ]
19
19
  }
20
20
 
@@ -22,33 +22,29 @@ describe Economic::Entity::Mapper do
22
22
 
23
23
  describe "#to_hash" do
24
24
  it "returns a Hash with fields as per the field descriptions" do
25
- subject.to_hash.should == {
26
- "Handle" => {"Id" => 42},
27
- "CreditorHandle" => {"Number" => 37},
28
- "Id" => 42,
29
- "Name" => "David Brent",
30
- "IsToReceiveEmailCopyOfOrder" => true
31
- }
25
+ expect(subject.to_hash).to eq("Handle" => {"Id" => 42},
26
+ "CreditorHandle" => {"Number" => 37},
27
+ "Id" => 42,
28
+ "Name" => "David Brent",
29
+ "IsToReceiveEmailCopyOfOrder" => true)
32
30
  end
33
31
  end
34
32
 
35
33
  describe "when entity has no values" do
36
- let(:entity) { double("Entity", {
37
- :handle => Economic::Entity::Handle.new({}),
38
- :creditor_handle => nil,
39
- :name => nil,
40
- :number => nil,
41
- :is_to_receive_email_copy_of_order => nil
42
- }) }
34
+ let(:entity) {
35
+ double("Entity", :handle => Economic::Entity::Handle.new({}),
36
+ :creditor_handle => nil,
37
+ :name => nil,
38
+ :number => nil,
39
+ :is_to_receive_email_copy_of_order => nil)
40
+ }
43
41
 
44
42
  subject { Economic::Entity::Mapper.new(entity, fields) }
45
43
 
46
44
  it "returns the minimal set of required fields" do
47
- subject.to_hash.should == {
48
- "Handle" => {},
49
- "Id" => nil,
50
- "IsToReceiveEmailCopyOfOrder" => false
51
- }
45
+ expect(subject.to_hash).to eq("Handle" => {},
46
+ "Id" => nil,
47
+ "IsToReceiveEmailCopyOfOrder" => false)
52
48
  end
53
49
  end
54
50
  end
@@ -1,12 +1,17 @@
1
- require './spec/spec_helper'
1
+ require "./spec/spec_helper"
2
2
 
3
3
  class Account < Economic::Entity
4
4
  has_properties :id, :foo, :baz, :bar_handle
5
5
 
6
- def build_soap_data; {:foo => "bar"}; end
6
+ def build_soap_data
7
+ {:foo => "bar"}
8
+ end
9
+
7
10
  def existing_method; end
8
11
 
9
- def proxy; Economic::AccountProxy.new(session); end
12
+ def proxy
13
+ Economic::AccountProxy.new(session)
14
+ end
10
15
  end
11
16
 
12
17
  class Economic::AccountProxy < Economic::EntityProxy; end
@@ -33,9 +38,9 @@ describe Economic::Entity do
33
38
  end
34
39
 
35
40
  it "initializes the entity with values from the given hash" do
36
- entity = Account.new(:foo => 'bar', :baz => 'qux')
37
- expect(entity.foo).to eq('bar')
38
- expect(entity.baz).to eq('qux')
41
+ entity = Account.new(:foo => "bar", :baz => "qux")
42
+ expect(entity.foo).to eq("bar")
43
+ expect(entity.baz).to eq("qux")
39
44
  end
40
45
  end
41
46
 
@@ -47,8 +52,8 @@ describe Economic::Entity do
47
52
 
48
53
  describe "has_properties" do
49
54
  it "creates getter for all properties" do
50
- expect(subject).to receive(:define_method).with('name')
51
- expect(subject).to receive(:define_method).with('age')
55
+ expect(subject).to receive(:define_method).with("name")
56
+ expect(subject).to receive(:define_method).with("age")
52
57
  subject.has_properties :name, :age
53
58
  end
54
59
 
@@ -73,14 +78,14 @@ describe Economic::Entity do
73
78
  end
74
79
 
75
80
  it "does not create setter or getter for id'ish properties" do
76
- expect(subject).to receive(:define_method).with('id').never
77
- expect(subject).to receive(:define_method).with('number').never
78
- expect(subject).to receive(:define_method).with('handle').never
81
+ expect(subject).to receive(:define_method).with("id").never
82
+ expect(subject).to receive(:define_method).with("number").never
83
+ expect(subject).to receive(:define_method).with("handle").never
79
84
  subject.has_properties :id, :number, :handle
80
85
  end
81
86
 
82
87
  it "does clobber existing methods" do
83
- expect(subject).to receive(:define_method).with('existing_method')
88
+ expect(subject).to receive(:define_method).with("existing_method")
84
89
  subject.has_properties :existing_method
85
90
  end
86
91
 
@@ -90,20 +95,20 @@ describe Economic::Entity do
90
95
  end
91
96
 
92
97
  describe "get_data" do
93
- subject { (e = Account.new).tap { |e| e.session = session } }
98
+ subject { Account.new.tap { |e| e.session = session } }
94
99
 
95
100
  before :each do
96
101
  end
97
102
 
98
103
  it "fetches data from API" do
99
- subject.instance_variable_set('@number', 42)
100
- mock_request(:account_get_data, {'entityHandle' => {'Number' => 42}}, :success)
104
+ subject.instance_variable_set("@number", 42)
105
+ mock_request(:account_get_data, {"entityHandle" => {"Number" => 42}}, :success)
101
106
  subject.get_data
102
107
  end
103
108
 
104
109
  it "updates the entity with the response" do
105
110
  stub_request(:account_get_data, nil, :success)
106
- expect(subject).to receive(:update_properties).with({:foo => 'bar', :baz => 'qux'})
111
+ expect(subject).to receive(:update_properties).with(:foo => "bar", :baz => "qux")
107
112
  subject.get_data
108
113
  end
109
114
 
@@ -121,7 +126,7 @@ describe Economic::Entity do
121
126
  end
122
127
 
123
128
  describe "save" do
124
- subject { (e = Account.new).tap { |e| e.session = session } }
129
+ subject { Account.new.tap { |e| e.session = session } }
125
130
 
126
131
  context "entity has not been persisted" do
127
132
  before :each do
@@ -147,7 +152,7 @@ describe Economic::Entity do
147
152
  end
148
153
 
149
154
  describe "create" do
150
- subject { (e = Account.new).tap { |e| e.persisted = false; e.session = session } }
155
+ subject { Account.new.tap { |e| e.persisted = false; e.session = session } }
151
156
 
152
157
  it "sends data to the API" do
153
158
  mock_request(:account_create_from_data, {"data" => {:foo => "bar"}}, :success)
@@ -157,12 +162,12 @@ describe Economic::Entity do
157
162
  it "updates handle with the number returned from API" do
158
163
  stub_request(:account_create_from_data, :any, :success)
159
164
  subject.save
160
- expect(subject.number).to eq('42')
165
+ expect(subject.number).to eq("42")
161
166
  end
162
167
  end
163
168
 
164
169
  describe ".proxy" do
165
- subject { (e = Account.new).tap { |e| e.session = session } }
170
+ subject { Account.new.tap { |e| e.session = session } }
166
171
 
167
172
  it "should return AccountProxy" do
168
173
  expect(subject.proxy).to be_instance_of(Economic::AccountProxy)
@@ -170,7 +175,7 @@ describe Economic::Entity do
170
175
  end
171
176
 
172
177
  describe "update" do
173
- subject { (e = Account.new).tap { |e| e.persisted = true; e.session = session } }
178
+ subject { Account.new.tap { |e| e.persisted = true; e.session = session } }
174
179
 
175
180
  it "sends data to the API" do
176
181
  mock_request(:account_update_from_data, {"data" => {:foo => "bar"}}, :success)
@@ -179,7 +184,7 @@ describe Economic::Entity do
179
184
  end
180
185
 
181
186
  describe "destroy" do
182
- subject { (e = Account.new).tap { |e| e.id = 42; e.persisted = true; e.partial = false; e.session = session } }
187
+ subject { Account.new.tap { |e| e.id = 42; e.persisted = true; e.partial = false; e.session = session } }
183
188
 
184
189
  it "sends data to the API" do
185
190
  mock_request(:account_delete, :any, :success)
@@ -187,7 +192,7 @@ describe Economic::Entity do
187
192
  end
188
193
 
189
194
  it "should request with the correct model and id" do
190
- mock_request(:account_delete, {'accountHandle' => {'Id' => 42}}, :success)
195
+ mock_request(:account_delete, {"accountHandle" => {"Id" => 42}}, :success)
191
196
  subject.destroy
192
197
  end
193
198
 
@@ -199,8 +204,8 @@ describe Economic::Entity do
199
204
  end
200
205
 
201
206
  it "should return the response" do
202
- expect(session).to receive(:request).and_return({ :response => true })
203
- expect(subject.destroy).to eq({ :response => true })
207
+ expect(session).to receive(:request).and_return(:response => true)
208
+ expect(subject.destroy).to eq(:response => true)
204
209
  end
205
210
  end
206
211
 
@@ -209,15 +214,15 @@ describe Economic::Entity do
209
214
 
210
215
  it "sets the properties to the given values" do
211
216
  subject.class.has_properties :foo, :baz
212
- expect(subject).to receive(:foo=).with('bar')
213
- expect(subject).to receive(:baz=).with('qux')
214
- subject.update_properties(:foo => 'bar', 'baz' => 'qux')
217
+ expect(subject).to receive(:foo=).with("bar")
218
+ expect(subject).to receive(:baz=).with("qux")
219
+ subject.update_properties(:foo => "bar", "baz" => "qux")
215
220
  end
216
221
 
217
222
  it "only sets known properties" do
218
223
  subject.class.has_properties :foo, :bar
219
- expect(subject).to receive(:foo=).with('bar')
220
- subject.update_properties(:foo => 'bar', 'baz' => 'qux')
224
+ expect(subject).to receive(:foo=).with("bar")
225
+ subject.update_properties(:foo => "bar", "baz" => "qux")
221
226
  end
222
227
  end
223
228
 
@@ -226,7 +231,7 @@ describe Economic::Entity do
226
231
  let(:other) { Account.new }
227
232
 
228
233
  context "when other is nil do" do
229
- it { should_not == nil }
234
+ it { is_expected.not_to eq(nil) }
230
235
  end
231
236
 
232
237
  context "when both handles are empty" do
@@ -1,4 +1,4 @@
1
- require './spec/spec_helper'
1
+ require "./spec/spec_helper"
2
2
 
3
3
  describe Economic::Entry do
4
4
  let(:session) { make_session }