netsuite 0.2.6 → 0.3.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 (152) hide show
  1. data/.travis.yml +3 -0
  2. data/Gemfile +2 -0
  3. data/README.md +132 -54
  4. data/lib/netsuite.rb +123 -76
  5. data/lib/netsuite/actions/add.rb +1 -0
  6. data/lib/netsuite/actions/delete.rb +1 -0
  7. data/lib/netsuite/actions/get.rb +1 -0
  8. data/lib/netsuite/actions/get_all.rb +67 -0
  9. data/lib/netsuite/actions/get_list.rb +2 -1
  10. data/lib/netsuite/actions/get_select_value.rb +1 -0
  11. data/lib/netsuite/actions/initialize.rb +1 -0
  12. data/lib/netsuite/actions/login.rb +2 -0
  13. data/lib/netsuite/actions/search.rb +3 -2
  14. data/lib/netsuite/actions/update.rb +18 -0
  15. data/lib/netsuite/actions/upsert.rb +1 -0
  16. data/lib/netsuite/actions/upsert_list.rb +114 -0
  17. data/lib/netsuite/configuration.rb +5 -0
  18. data/lib/netsuite/namespaces/file_cabinet.rb +11 -0
  19. data/lib/netsuite/namespaces/list_emp.rb +12 -0
  20. data/lib/netsuite/namespaces/list_mkt.rb +12 -0
  21. data/lib/netsuite/namespaces/list_website.rb +11 -0
  22. data/lib/netsuite/namespaces/tran_invt.rb +11 -0
  23. data/lib/netsuite/records/accounting_period.rb +1 -1
  24. data/lib/netsuite/records/assembly_item.rb +10 -4
  25. data/lib/netsuite/records/billing_schedule.rb +33 -0
  26. data/lib/netsuite/records/billing_schedule_milestone.rb +28 -0
  27. data/lib/netsuite/records/billing_schedule_milestone_list.rb +33 -0
  28. data/lib/netsuite/records/billing_schedule_recurrence.rb +28 -0
  29. data/lib/netsuite/records/billing_schedule_recurrence_list.rb +33 -0
  30. data/lib/netsuite/records/bin.rb +22 -0
  31. data/lib/netsuite/records/campaign.rb +28 -0
  32. data/lib/netsuite/records/cash_refund.rb +1 -1
  33. data/lib/netsuite/records/classification.rb +1 -1
  34. data/lib/netsuite/records/contact.rb +1 -1
  35. data/lib/netsuite/records/contact_access_roles.rb +14 -0
  36. data/lib/netsuite/records/contact_access_roles_list.rb +9 -0
  37. data/lib/netsuite/records/custom_field.rb +2 -1
  38. data/lib/netsuite/records/custom_field_list.rb +23 -4
  39. data/lib/netsuite/records/custom_list.rb +27 -0
  40. data/lib/netsuite/records/custom_list_custom_value.rb +14 -0
  41. data/lib/netsuite/records/custom_list_custom_value_list.rb +13 -0
  42. data/lib/netsuite/records/custom_record.rb +1 -1
  43. data/lib/netsuite/records/custom_record_type.rb +1 -1
  44. data/lib/netsuite/records/customer.rb +4 -4
  45. data/lib/netsuite/records/customer_addressbook.rb +8 -5
  46. data/lib/netsuite/records/customer_addressbook_list.rb +13 -1
  47. data/lib/netsuite/records/customer_deposit.rb +3 -2
  48. data/lib/netsuite/records/customer_payment.rb +1 -1
  49. data/lib/netsuite/records/customer_refund.rb +1 -1
  50. data/lib/netsuite/records/department.rb +4 -2
  51. data/lib/netsuite/records/deposit.rb +1 -1
  52. data/lib/netsuite/records/deposit_cash_back.rb +2 -2
  53. data/lib/netsuite/records/deposit_other.rb +2 -2
  54. data/lib/netsuite/records/discount_item.rb +32 -0
  55. data/lib/netsuite/records/employee.rb +20 -0
  56. data/lib/netsuite/records/file.rb +28 -0
  57. data/lib/netsuite/records/inventory_assignment.rb +24 -0
  58. data/lib/netsuite/records/inventory_assignment_list.rb +32 -0
  59. data/lib/netsuite/records/inventory_detail.rb +18 -0
  60. data/lib/netsuite/records/inventory_transfer.rb +29 -0
  61. data/lib/netsuite/records/inventory_transfer_inventory.rb +21 -0
  62. data/lib/netsuite/records/inventory_transfer_inventory_list.rb +33 -0
  63. data/lib/netsuite/records/item_fulfillment.rb +1 -1
  64. data/lib/netsuite/records/item_fulfillment_item_list.rb +3 -21
  65. data/lib/netsuite/records/item_member.rb +21 -0
  66. data/lib/netsuite/records/journal_entry.rb +1 -1
  67. data/lib/netsuite/records/kit_item.rb +1 -1
  68. data/lib/netsuite/records/location.rb +3 -1
  69. data/lib/netsuite/records/member_list.rb +32 -0
  70. data/lib/netsuite/records/non_inventory_sale_item.rb +4 -1
  71. data/lib/netsuite/records/partner.rb +21 -0
  72. data/lib/netsuite/records/promotion_code.rb +38 -0
  73. data/lib/netsuite/records/record_ref_list.rb +40 -0
  74. data/lib/netsuite/records/role_list.rb +25 -0
  75. data/lib/netsuite/records/sales_order.rb +6 -2
  76. data/lib/netsuite/records/sales_tax_item.rb +32 -0
  77. data/lib/netsuite/records/site_category.rb +33 -0
  78. data/lib/netsuite/records/subsidiary.rb +38 -0
  79. data/lib/netsuite/records/tax_type.rb +22 -0
  80. data/lib/netsuite/records/term.rb +1 -1
  81. data/lib/netsuite/records/units_type.rb +25 -0
  82. data/lib/netsuite/records/units_type_uom.rb +20 -0
  83. data/lib/netsuite/records/units_type_uom_list.rb +33 -0
  84. data/lib/netsuite/records/work_order.rb +38 -0
  85. data/lib/netsuite/records/work_order_item.rb +31 -0
  86. data/lib/netsuite/records/work_order_item_list.rb +31 -0
  87. data/lib/netsuite/support/actions.rb +4 -0
  88. data/lib/netsuite/support/base.rb +21 -0
  89. data/lib/netsuite/support/country.rb +273 -0
  90. data/lib/netsuite/support/search_result.rb +4 -0
  91. data/lib/netsuite/support/sublist.rb +54 -0
  92. data/lib/netsuite/version.rb +1 -1
  93. data/spec/netsuite/actions/search_spec.rb +1 -1
  94. data/spec/netsuite/actions/update_spec.rb +62 -31
  95. data/spec/netsuite/actions/upsert_list_spec.rb +112 -0
  96. data/spec/netsuite/records/account_spec.rb +4 -4
  97. data/spec/netsuite/records/accounting_period_spec.rb +4 -4
  98. data/spec/netsuite/records/assembly_item_spec.rb +38 -0
  99. data/spec/netsuite/records/billing_schedule_milestone_list_spec.rb +24 -0
  100. data/spec/netsuite/records/billing_schedule_milestone_spec.rb +51 -0
  101. data/spec/netsuite/records/billing_schedule_recurrence_list_spec.rb +24 -0
  102. data/spec/netsuite/records/billing_schedule_recurrence_spec.rb +49 -0
  103. data/spec/netsuite/records/billing_schedule_spec.rb +164 -0
  104. data/spec/netsuite/records/campaign_spec.rb +43 -0
  105. data/spec/netsuite/records/cash_refund_spec.rb +1 -1
  106. data/spec/netsuite/records/classification_spec.rb +2 -2
  107. data/spec/netsuite/records/credit_memo_spec.rb +4 -4
  108. data/spec/netsuite/records/custom_field_list_spec.rb +10 -0
  109. data/spec/netsuite/records/custom_list_spec.rb +21 -0
  110. data/spec/netsuite/records/custom_record_spec.rb +5 -5
  111. data/spec/netsuite/records/custom_record_type_spec.rb +5 -5
  112. data/spec/netsuite/records/customer_addressbook_list_spec.rb +19 -1
  113. data/spec/netsuite/records/customer_addressbook_spec.rb +42 -13
  114. data/spec/netsuite/records/customer_payment_spec.rb +4 -4
  115. data/spec/netsuite/records/customer_refund_spec.rb +4 -4
  116. data/spec/netsuite/records/customer_spec.rb +80 -6
  117. data/spec/netsuite/records/department_spec.rb +4 -4
  118. data/spec/netsuite/records/deposit_spec.rb +22 -4
  119. data/spec/netsuite/records/discount_item_spec.rb +124 -0
  120. data/spec/netsuite/records/inventory_item_spec.rb +4 -4
  121. data/spec/netsuite/records/inventory_transfer_spec.rb +58 -0
  122. data/spec/netsuite/records/invoice_spec.rb +4 -4
  123. data/spec/netsuite/records/job_spec.rb +7 -7
  124. data/spec/netsuite/records/journal_entry_spec.rb +5 -5
  125. data/spec/netsuite/records/non_inventory_sale_item_spec.rb +4 -4
  126. data/spec/netsuite/records/payment_method_spec.rb +1 -1
  127. data/spec/netsuite/records/pomo_code_spec.rb +40 -0
  128. data/spec/netsuite/records/sales_order_spec.rb +18 -18
  129. data/spec/netsuite/records/sales_tax_item_spec.rb +30 -0
  130. data/spec/netsuite/records/service_sale_item_spec.rb +4 -4
  131. data/spec/netsuite/records/site_category_spec.rb +51 -0
  132. data/spec/netsuite/records/subsidiary_spec.rb +25 -0
  133. data/spec/netsuite/records/support_case_spec.rb +8 -8
  134. data/spec/netsuite/records/tax_type_spec.rb +11 -0
  135. data/spec/netsuite/records/term_spec.rb +4 -4
  136. data/spec/netsuite/records/units_type_spec.rb +33 -0
  137. data/spec/netsuite/records/units_type_uom_list_spec.rb +23 -0
  138. data/spec/netsuite/records/units_type_uom_spec.rb +14 -0
  139. data/spec/netsuite/records/work_order_item_list_spec.rb +26 -0
  140. data/spec/netsuite/records/work_order_item_spec.rb +45 -0
  141. data/spec/netsuite/records/work_order_spec.rb +92 -0
  142. data/spec/netsuite/support/record_refs_spec.rb +1 -1
  143. data/spec/netsuite/support/sublist_spec.rb +36 -0
  144. data/spec/spec_helper.rb +1 -0
  145. data/spec/support/fixtures/update/update_customer_error.xml +21 -0
  146. data/spec/support/fixtures/update/update_customer_multiple_errors.xml +25 -0
  147. data/spec/support/fixtures/upsert_list/upsert_list_customers.xml +21 -0
  148. data/spec/support/fixtures/upsert_list/upsert_list_one_customer.xml +17 -0
  149. data/spec/support/fixtures/upsert_list/upsert_list_with_errors.xml +32 -0
  150. data/spec/support/read_only_field_matcher.rb +1 -1
  151. metadata +115 -5
  152. checksums.yaml +0 -15
@@ -10,10 +10,28 @@ describe NetSuite::Records::CustomerAddressbookList do
10
10
  describe '#to_record' do
11
11
  it 'can represent itself as a SOAP record' do
12
12
  record = {
13
- 'listRel:addressbook' => []
13
+ 'listRel:addressbook' => [],
14
+ 'listRel:replaceAll' => true
14
15
  }
15
16
  list.to_record.should eql(record)
16
17
  end
17
18
  end
18
19
 
20
+ describe "#replace_all" do
21
+ it "returns true by default" do
22
+ list.replace_all.should eql(true)
23
+ end
24
+
25
+ it "can be changed via accessor" do
26
+ list.replace_all = false
27
+
28
+ list.replace_all.should eql(false)
29
+ end
30
+
31
+ it "coerces to a boolean" do
32
+ list.replace_all = "goober"
33
+ list.replace_all.should eql(true)
34
+ end
35
+ end
36
+
19
37
  end
@@ -24,24 +24,32 @@ describe NetSuite::Records::CustomerAddressbook do
24
24
  it 'has all the right fields' do
25
25
  [
26
26
  :default_shipping, :default_billing, :is_residential, :label, :attention, :addressee,
27
- :phone, :addr1, :addr2, :addr3, :city, :zip, :country, :addr_text, :override, :state
27
+ :phone, :addr1, :addr2, :addr3, :city, :zip, :addr_text, :override, :state
28
28
  ].each do |field|
29
29
  list.should have_field(field)
30
30
  end
31
31
  end
32
32
 
33
+ it 'has all the right read_only_fields' do
34
+ [
35
+ :addr_text
36
+ ].each do |field|
37
+ NetSuite::Records::CustomerAddressbook.should have_read_only_field(field)
38
+ end
39
+ end
40
+
33
41
  describe '#initialize' do
34
42
  context 'when taking in a hash of attributes' do
35
43
  it 'sets the attributes for the object given the attributes hash' do
36
44
  list.addr1.should eql('123 Happy Lane')
37
45
  list.addr_text.should eql("123 Happy Lane\nLos Angeles CA 90007")
38
46
  list.city.should eql('Los Angeles')
39
- list.country.should eql('_unitedStates')
40
- list.default_billing.should be_true
41
- list.default_shipping.should be_true
42
- list.is_residential.should be_false
47
+ list.country.to_record.should eql('_unitedStates')
48
+ list.default_billing.should be_truthy
49
+ list.default_shipping.should be_truthy
50
+ list.is_residential.should be_falsey
43
51
  list.label.should eql('123 Happy Lane')
44
- list.override.should be_false
52
+ list.override.should be_falsey
45
53
  list.state.should eql('CA')
46
54
  list.zip.should eql('90007')
47
55
  list.internal_id.should eql('567')
@@ -55,12 +63,12 @@ describe NetSuite::Records::CustomerAddressbook do
55
63
  list.addr1.should eql('123 Happy Lane')
56
64
  list.addr_text.should eql("123 Happy Lane\nLos Angeles CA 90007")
57
65
  list.city.should eql('Los Angeles')
58
- list.country.should eql('_unitedStates')
59
- list.default_billing.should be_true
60
- list.default_shipping.should be_true
61
- list.is_residential.should be_false
66
+ list.country.to_record.should eql('_unitedStates')
67
+ list.default_billing.should be_truthy
68
+ list.default_shipping.should be_truthy
69
+ list.is_residential.should be_falsey
62
70
  list.label.should eql('123 Happy Lane')
63
- list.override.should be_false
71
+ list.override.should be_falsey
64
72
  list.state.should eql('CA')
65
73
  list.zip.should eql('90007')
66
74
  list.internal_id.should eql('567')
@@ -72,7 +80,6 @@ describe NetSuite::Records::CustomerAddressbook do
72
80
  it 'can represent itself as a SOAP record' do
73
81
  record = {
74
82
  'listRel:addr1' => '123 Happy Lane',
75
- 'listRel:addrText' => "123 Happy Lane\nLos Angeles CA 90007",
76
83
  'listRel:city' => 'Los Angeles',
77
84
  'listRel:country' => '_unitedStates',
78
85
  'listRel:defaultBilling' => true,
@@ -81,12 +88,34 @@ describe NetSuite::Records::CustomerAddressbook do
81
88
  'listRel:label' => '123 Happy Lane',
82
89
  'listRel:override' => false,
83
90
  'listRel:state' => 'CA',
84
- 'listRel:zip' => '90007'
91
+ 'listRel:zip' => '90007',
92
+ "listRel:internalId" => "567"
85
93
  }
86
94
  list.to_record.should eql(record)
87
95
  end
88
96
  end
89
97
 
98
+ describe "#country" do
99
+ context "when it's specified as a 2 character ISO code" do
100
+ it "is converted to the appropriate NetSuite enum value" do
101
+ addressbook = NetSuite::Records::CustomerAddressbook.new country: "US"
102
+ addressbook.to_record["listRel:country"].should eql "_unitedStates"
103
+ end
104
+ end
105
+
106
+ context "when the country code is a YAML reserved word (NO)" do
107
+ it "is converted to the appropriate NetSuite enum value" do
108
+ addressbook = NetSuite::Records::CustomerAddressbook.new country: "NO"
109
+ addressbook.to_record["listRel:country"].should eql "_norway"
110
+ end
111
+ end
112
+
113
+ it "can be specified as the NetSuite enum value" do
114
+ addressbook = NetSuite::Records::CustomerAddressbook.new country: "_unitedStates"
115
+ addressbook.to_record["listRel:country"].should eql "_unitedStates"
116
+ end
117
+ end
118
+
90
119
  describe '#record_type' do
91
120
  it 'returns a string of the record SOAP type' do
92
121
  list.record_type.should eql('listRel:CustomerAddressbook')
@@ -109,7 +109,7 @@ describe NetSuite::Records::CustomerPayment do
109
109
  NetSuite::Actions::Add.should_receive(:call).
110
110
  with([payment], {}).
111
111
  and_return(response)
112
- payment.add.should be_true
112
+ payment.add.should be_truthy
113
113
  end
114
114
  end
115
115
 
@@ -121,7 +121,7 @@ describe NetSuite::Records::CustomerPayment do
121
121
  NetSuite::Actions::Add.should_receive(:call).
122
122
  with([payment], {}).
123
123
  and_return(response)
124
- payment.add.should be_false
124
+ payment.add.should be_falsey
125
125
  end
126
126
  end
127
127
  end
@@ -134,7 +134,7 @@ describe NetSuite::Records::CustomerPayment do
134
134
  NetSuite::Actions::Delete.should_receive(:call).
135
135
  with([payment], {}).
136
136
  and_return(response)
137
- payment.delete.should be_true
137
+ payment.delete.should be_truthy
138
138
  end
139
139
  end
140
140
 
@@ -145,7 +145,7 @@ describe NetSuite::Records::CustomerPayment do
145
145
  NetSuite::Actions::Delete.should_receive(:call).
146
146
  with([payment], {}).
147
147
  and_return(response)
148
- payment.delete.should be_false
148
+ payment.delete.should be_falsey
149
149
  end
150
150
  end
151
151
  end
@@ -131,7 +131,7 @@ describe NetSuite::Records::CustomerRefund do
131
131
  NetSuite::Actions::Add.should_receive(:call).
132
132
  with([refund], {}).
133
133
  and_return(response)
134
- refund.add.should be_true
134
+ refund.add.should be_truthy
135
135
  end
136
136
  end
137
137
 
@@ -143,7 +143,7 @@ describe NetSuite::Records::CustomerRefund do
143
143
  NetSuite::Actions::Add.should_receive(:call).
144
144
  with([refund], {}).
145
145
  and_return(response)
146
- refund.add.should be_false
146
+ refund.add.should be_falsey
147
147
  end
148
148
  end
149
149
  end
@@ -157,7 +157,7 @@ describe NetSuite::Records::CustomerRefund do
157
157
  NetSuite::Actions::Delete.should_receive(:call).
158
158
  with([refund], {}).
159
159
  and_return(response)
160
- refund.delete.should be_true
160
+ refund.delete.should be_truthy
161
161
  end
162
162
  end
163
163
 
@@ -169,7 +169,7 @@ describe NetSuite::Records::CustomerRefund do
169
169
  NetSuite::Actions::Delete.should_receive(:call).
170
170
  with([refund], {}).
171
171
  and_return(response)
172
- refund.delete.should be_false
172
+ refund.delete.should be_falsey
173
173
  end
174
174
  end
175
175
  end
@@ -8,7 +8,7 @@ describe NetSuite::Records::Customer do
8
8
  :access_role, :account_number, :aging, :alt_email, :alt_name, :alt_phone, :balance, :bill_pay,
9
9
  :buying_reason, :buying_time_frame, :campaign_category, :click_stream, :comments, :company_name,
10
10
  :consol_aging, :consol_balance, :consol_days_overdue, :consol_deposit_balance, :consol_overdue_balance,
11
- :consol_unbilled_orders, :contact_roles_list, :contrib_pct, :credit_cards_list, :credit_hold_override, :credit_limit,
11
+ :consol_unbilled_orders, :contrib_pct, :credit_cards_list, :credit_hold_override, :credit_limit,
12
12
  :currency, :currency_list, :date_created, :days_overdue, :default_address,
13
13
  :deposit_balance, :download_list, :email, :email_preference, :email_transactions, :end_date, :entity_id,
14
14
  :estimated_budget, :fax, :fax_transactions, :first_name, :first_visit, :give_access, :global_subscription_status,
@@ -34,6 +34,8 @@ describe NetSuite::Records::Customer do
34
34
  end
35
35
  end
36
36
 
37
+ # TODO test contact_roles_list
38
+
37
39
  describe '#addressbook_list' do
38
40
  it 'can be set from attributes' do
39
41
  customer.addressbook_list = {
@@ -91,7 +93,7 @@ describe NetSuite::Records::Customer do
91
93
  NetSuite::Actions::Get.should_receive(:call).with([NetSuite::Records::Customer, {:external_id => 1}], {}).and_return(response)
92
94
  customer = NetSuite::Records::Customer.get(:external_id => 1)
93
95
  customer.should be_kind_of(NetSuite::Records::Customer)
94
- customer.is_person.should be_true
96
+ customer.is_person.should be_truthy
95
97
  end
96
98
  end
97
99
 
@@ -118,7 +120,7 @@ describe NetSuite::Records::Customer do
118
120
  NetSuite::Actions::Add.should_receive(:call).
119
121
  with([customer], {}).
120
122
  and_return(response)
121
- customer.add.should be_true
123
+ customer.add.should be_truthy
122
124
  end
123
125
  end
124
126
 
@@ -129,7 +131,7 @@ describe NetSuite::Records::Customer do
129
131
  NetSuite::Actions::Add.should_receive(:call).
130
132
  with([customer], {}).
131
133
  and_return(response)
132
- customer.add.should be_false
134
+ customer.add.should be_falsey
133
135
  end
134
136
  end
135
137
  end
@@ -142,7 +144,7 @@ describe NetSuite::Records::Customer do
142
144
  NetSuite::Actions::Delete.should_receive(:call).
143
145
  with([customer], {}).
144
146
  and_return(response)
145
- customer.delete.should be_true
147
+ customer.delete.should be_truthy
146
148
  end
147
149
  end
148
150
 
@@ -153,7 +155,7 @@ describe NetSuite::Records::Customer do
153
155
  NetSuite::Actions::Delete.should_receive(:call).
154
156
  with([customer], {}).
155
157
  and_return(response)
156
- customer.delete.should be_false
158
+ customer.delete.should be_falsey
157
159
  end
158
160
  end
159
161
  end
@@ -175,4 +177,76 @@ describe NetSuite::Records::Customer do
175
177
  end
176
178
  end
177
179
 
180
+ describe '.upsert_list' do
181
+ before { savon.mock! }
182
+ after { savon.unmock! }
183
+
184
+ context 'with one customer' do
185
+ before do
186
+ savon.expects(:upsert_list).with(:message =>
187
+ {
188
+ 'record' => [{
189
+ 'listRel:entityId' => 'Target',
190
+ 'listRel:companyName' => 'Target',
191
+ '@xsi:type' => 'listRel:Customer',
192
+ '@externalId' => 'ext2'
193
+ }]
194
+ }).returns(File.read('spec/support/fixtures/upsert_list/upsert_list_one_customer.xml'))
195
+ end
196
+
197
+ it 'returns collection with one Customer instances populated with the data from the response object' do
198
+ customers = NetSuite::Records::Customer.upsert_list([
199
+ {
200
+ external_id: 'ext2',
201
+ entity_id: 'Target',
202
+ company_name: 'Target'
203
+ }
204
+ ])
205
+ shutter_fly = customers[0]
206
+ expect(shutter_fly).to be_kind_of(NetSuite::Records::Customer)
207
+ expect(shutter_fly.entity_id).to eq('Target')
208
+ expect(shutter_fly.internal_id).to eq('974')
209
+ end
210
+ end
211
+
212
+ context 'with two customers' do
213
+ before do
214
+ savon.expects(:upsert_list).with(:message =>
215
+ {
216
+ 'record' => [{
217
+ 'listRel:entityId' => 'Shutter Fly',
218
+ 'listRel:companyName' => 'Shutter Fly, Inc.',
219
+ '@xsi:type' => 'listRel:Customer',
220
+ '@externalId' => 'ext1'
221
+ },
222
+ {
223
+ 'listRel:entityId' => 'Target',
224
+ 'listRel:companyName' => 'Target',
225
+ '@xsi:type' => 'listRel:Customer',
226
+ '@externalId' => 'ext2'
227
+ }
228
+ ]
229
+ }).returns(File.read('spec/support/fixtures/upsert_list/upsert_list_customers.xml'))
230
+ end
231
+
232
+ it 'returns collection of Customer instances populated with the data from the response object' do
233
+ customers = NetSuite::Records::Customer.upsert_list([
234
+ {
235
+ external_id: 'ext1',
236
+ entity_id: 'Shutter Fly',
237
+ company_name: 'Shutter Fly, Inc.'
238
+ },
239
+ {
240
+ external_id: 'ext2',
241
+ entity_id: 'Target',
242
+ company_name: 'Target'
243
+ }
244
+ ])
245
+ shutter_fly = customers[0]
246
+ expect(shutter_fly).to be_kind_of(NetSuite::Records::Customer)
247
+ expect(shutter_fly.entity_id).to eq('Shutter Fly')
248
+ expect(shutter_fly.internal_id).to eq('970')
249
+ end
250
+ end
251
+ end
178
252
  end
@@ -55,7 +55,7 @@ describe NetSuite::Records::Department do
55
55
  NetSuite::Actions::Add.should_receive(:call).
56
56
  with([department], {}).
57
57
  and_return(response)
58
- department.add.should be_true
58
+ department.add.should be_truthy
59
59
  end
60
60
  end
61
61
 
@@ -67,7 +67,7 @@ describe NetSuite::Records::Department do
67
67
  NetSuite::Actions::Add.should_receive(:call).
68
68
  with([department], {}).
69
69
  and_return(response)
70
- department.add.should be_false
70
+ department.add.should be_falsey
71
71
  end
72
72
  end
73
73
  end
@@ -83,7 +83,7 @@ describe NetSuite::Records::Department do
83
83
  NetSuite::Actions::Delete.should_receive(:call).
84
84
  with([department], {}).
85
85
  and_return(response)
86
- department.delete.should be_true
86
+ department.delete.should be_truthy
87
87
  end
88
88
  end
89
89
 
@@ -95,7 +95,7 @@ describe NetSuite::Records::Department do
95
95
  NetSuite::Actions::Delete.should_receive(:call).
96
96
  with([department], {}).
97
97
  and_return(response)
98
- department.delete.should be_false
98
+ department.delete.should be_falsey
99
99
  end
100
100
  end
101
101
  end
@@ -42,6 +42,24 @@ describe NetSuite::Records::Deposit do
42
42
  end
43
43
  end
44
44
 
45
+ describe '#cash_back_list' do
46
+ it 'can be set from attributes' do
47
+ attributes = {
48
+ amount: 100,
49
+ memo: "test"
50
+ }
51
+ deposit.cash_back_list.cashback = attributes
52
+ deposit.cash_back_list.should be_kind_of(NetSuite::Records::DepositCashBackList)
53
+ deposit.cash_back_list.cashbacks.length.should eql(1)
54
+ end
55
+
56
+ it 'can be set from a DepositCashBackList object' do
57
+ item_list = NetSuite::Records::DepositCashBackList.new
58
+ deposit.cash_back_list = item_list
59
+ deposit.cash_back_list.should eql(item_list)
60
+ end
61
+ end
62
+
45
63
  describe '.get' do
46
64
  context 'when the response is successful' do
47
65
  let(:response) { NetSuite::Response.new(:success => true, :body => { :memo => 'transfer for subscriptions' }) }
@@ -78,7 +96,7 @@ describe NetSuite::Records::Deposit do
78
96
  NetSuite::Actions::Add.should_receive(:call).
79
97
  with([deposit], {}).
80
98
  and_return(response)
81
- deposit.add.should be_true
99
+ deposit.add.should be_truthy
82
100
  end
83
101
  end
84
102
 
@@ -90,7 +108,7 @@ describe NetSuite::Records::Deposit do
90
108
  NetSuite::Actions::Add.should_receive(:call).
91
109
  with([deposit], {}).
92
110
  and_return(response)
93
- deposit.add.should be_false
111
+ deposit.add.should be_falsey
94
112
  end
95
113
  end
96
114
  end
@@ -106,7 +124,7 @@ describe NetSuite::Records::Deposit do
106
124
  NetSuite::Actions::Delete.should_receive(:call).
107
125
  with([deposit], {}).
108
126
  and_return(response)
109
- deposit.delete.should be_true
127
+ deposit.delete.should be_truthy
110
128
  end
111
129
  end
112
130
 
@@ -118,7 +136,7 @@ describe NetSuite::Records::Deposit do
118
136
  NetSuite::Actions::Delete.should_receive(:call).
119
137
  with([deposit], {}).
120
138
  and_return(response)
121
- deposit.delete.should be_false
139
+ deposit.delete.should be_falsey
122
140
  end
123
141
  end
124
142
  end
@@ -0,0 +1,124 @@
1
+ require 'spec_helper'
2
+
3
+ describe NetSuite::Records::DiscountItem do
4
+ let(:item) { NetSuite::Records::DiscountItem.new }
5
+
6
+ it 'has the right fields' do
7
+ [
8
+ :available_to_partners, :created_date, :description, :display_name, :include_children, :is_inactive, :is_pretax,
9
+ :item_id, :last_modified_date, :non_posting, :rate, :upc_code, :vendor_name
10
+ ].each do |field|
11
+ item.should have_field(field)
12
+ end
13
+
14
+ # TODO there is a probably a more robust way to test this
15
+ item.custom_field_list.class.should == NetSuite::Records::CustomFieldList
16
+ end
17
+
18
+ it 'has the right record_refs' do
19
+ [
20
+ :account, :custom_form, :deferred_revenue_account, :department, :expense_account,
21
+ :income_account, :issue_product, :klass, :location, :parent, :rev_rec_schedule, :sales_tax_code,
22
+ :subsidiary_list, :tax_schedule
23
+ ].each do |record_ref|
24
+ item.should have_record_ref(record_ref)
25
+ end
26
+ end
27
+
28
+ describe '.get' do
29
+ context 'when the response is successful' do
30
+ let(:response) { NetSuite::Response.new(:success => true, :body => { :item_id => 'penguins' }) }
31
+
32
+ it 'returns a DiscountItem instance populated with the data from the response object' do
33
+ NetSuite::Actions::Get.should_receive(:call).with([NetSuite::Records::DiscountItem, :external_id => 20], {}).and_return(response)
34
+ customer = NetSuite::Records::DiscountItem.get(:external_id => 20)
35
+ customer.should be_kind_of(NetSuite::Records::DiscountItem)
36
+ customer.item_id.should eql('penguins')
37
+ end
38
+ end
39
+
40
+ context 'when the response is unsuccessful' do
41
+ let(:response) { NetSuite::Response.new(:success => false, :body => {}) }
42
+
43
+ it 'raises a RecordNotFound exception' do
44
+ NetSuite::Actions::Get.should_receive(:call).with([NetSuite::Records::DiscountItem, :external_id => 20], {}).and_return(response)
45
+ lambda {
46
+ NetSuite::Records::DiscountItem.get(:external_id => 20)
47
+ }.should raise_error(NetSuite::RecordNotFound,
48
+ /NetSuite::Records::DiscountItem with OPTIONS=(.*) could not be found/)
49
+ end
50
+ end
51
+ end
52
+
53
+ describe '#add' do
54
+ # let(:item) { NetSuite::Records::DiscountItem.new(:cost => 100, :is_inactive => false) }
55
+
56
+ context 'when the response is successful' do
57
+ let(:response) { NetSuite::Response.new(:success => true, :body => { :internal_id => '1' }) }
58
+
59
+ it 'returns true' do
60
+ NetSuite::Actions::Add.should_receive(:call).
61
+ with([item], {}).
62
+ and_return(response)
63
+ item.add.should be_truthy
64
+ end
65
+ end
66
+
67
+ context 'when the response is unsuccessful' do
68
+ let(:response) { NetSuite::Response.new(:success => false, :body => {}) }
69
+
70
+ it 'returns false' do
71
+ NetSuite::Actions::Add.should_receive(:call).
72
+ with([item], {}).
73
+ and_return(response)
74
+ item.add.should be_falsey
75
+ end
76
+ end
77
+ end
78
+
79
+ describe '#delete' do
80
+ context 'when the response is successful' do
81
+ let(:response) { NetSuite::Response.new(:success => true, :body => { :internal_id => '1' }) }
82
+
83
+ it 'returns true' do
84
+ NetSuite::Actions::Delete.should_receive(:call).
85
+ with([item], {}).
86
+ and_return(response)
87
+ item.delete.should be_truthy
88
+ end
89
+ end
90
+
91
+ context 'when the response is unsuccessful' do
92
+ let(:response) { NetSuite::Response.new(:success => false, :body => {}) }
93
+
94
+ it 'returns false' do
95
+ NetSuite::Actions::Delete.should_receive(:call).
96
+ with([item], {}).
97
+ and_return(response)
98
+ item.delete.should be_falsey
99
+ end
100
+ end
101
+ end
102
+
103
+ describe '#to_record' do
104
+ before do
105
+ item.item_id = 'penguins'
106
+ item.is_inactive = true
107
+ end
108
+
109
+ it 'can represent itself as a SOAP record' do
110
+ record = {
111
+ 'listAcct:itemId' => 'penguins',
112
+ 'listAcct:isInactive' => true
113
+ }
114
+ item.to_record.should eql(record)
115
+ end
116
+ end
117
+
118
+ describe '#record_type' do
119
+ it 'returns a string of the SOAP type' do
120
+ item.record_type.should eql('listAcct:DiscountItem')
121
+ end
122
+ end
123
+
124
+ end