qbfc 0.1.0-x86-mswin32-60

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 (58) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README +41 -0
  3. data/Rakefile +82 -0
  4. data/lib/qbfc.rb +39 -0
  5. data/lib/qbfc/base.rb +82 -0
  6. data/lib/qbfc/element.rb +178 -0
  7. data/lib/qbfc/entities/generated.rb +8 -0
  8. data/lib/qbfc/entity.rb +11 -0
  9. data/lib/qbfc/info.rb +42 -0
  10. data/lib/qbfc/infos/generated.rb +9 -0
  11. data/lib/qbfc/item.rb +10 -0
  12. data/lib/qbfc/items/generated.rb +11 -0
  13. data/lib/qbfc/list.rb +84 -0
  14. data/lib/qbfc/lists/generated.rb +15 -0
  15. data/lib/qbfc/lists/qb_class.rb +25 -0
  16. data/lib/qbfc/modifiable.rb +31 -0
  17. data/lib/qbfc/ole_wrapper.rb +193 -0
  18. data/lib/qbfc/qb_collection.rb +26 -0
  19. data/lib/qbfc/qb_types.rb +34 -0
  20. data/lib/qbfc/qbfc_const.rb +14 -0
  21. data/lib/qbfc/request.rb +158 -0
  22. data/lib/qbfc/session.rb +136 -0
  23. data/lib/qbfc/terms.rb +10 -0
  24. data/lib/qbfc/terms/generated.rb +10 -0
  25. data/lib/qbfc/transaction.rb +83 -0
  26. data/lib/qbfc/transactions/generated.rb +18 -0
  27. data/lib/qbfc/voidable.rb +11 -0
  28. data/spec/rcov.opts +1 -0
  29. data/spec/spec.opts +6 -0
  30. data/spec/spec_helper.rb +62 -0
  31. data/spec/unit/base_spec.rb +138 -0
  32. data/spec/unit/element_finder_spec.rb +180 -0
  33. data/spec/unit/element_spec.rb +118 -0
  34. data/spec/unit/entities/generated_spec.rb +18 -0
  35. data/spec/unit/entity_spec.rb +18 -0
  36. data/spec/unit/info/generated_spec.rb +12 -0
  37. data/spec/unit/info_spec.rb +48 -0
  38. data/spec/unit/item_spec.rb +18 -0
  39. data/spec/unit/items/generated_spec.rb +16 -0
  40. data/spec/unit/list_finders_spec.rb +128 -0
  41. data/spec/unit/list_spec.rb +86 -0
  42. data/spec/unit/lists/generated_spec.rb +15 -0
  43. data/spec/unit/lists/qb_class_spec.rb +9 -0
  44. data/spec/unit/modifiable_spec.rb +84 -0
  45. data/spec/unit/ole_wrapper_spec.rb +293 -0
  46. data/spec/unit/qb_collection_spec.rb +13 -0
  47. data/spec/unit/qbfc_const_spec.rb +10 -0
  48. data/spec/unit/qbfc_spec.rb +10 -0
  49. data/spec/unit/request_query_survey.txt +48 -0
  50. data/spec/unit/request_spec.rb +236 -0
  51. data/spec/unit/session_spec.rb +138 -0
  52. data/spec/unit/terms/generated_spec.rb +14 -0
  53. data/spec/unit/terms_spec.rb +18 -0
  54. data/spec/unit/transaction_finders_spec.rb +124 -0
  55. data/spec/unit/transaction_spec.rb +94 -0
  56. data/spec/unit/transactions/generated_spec.rb +20 -0
  57. data/spec/unit/voidable_spec.rb +32 -0
  58. metadata +140 -0
@@ -0,0 +1,293 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe QBFC::OLEWrapper do
4
+
5
+ before(:each) do
6
+ @sess = mock(QBFC::Session)
7
+ @ole_object = mock(WIN32OLE)
8
+ @wrapper = QBFC::OLEWrapper.new(@ole_object)
9
+ end
10
+
11
+ it "should initialize with a WIN32OLE object" do
12
+ lambda{ QBFC::OLEWrapper.new(@ole_object) }.should_not raise_error
13
+ end
14
+
15
+ it "should initialize with a String name a WIN32OLE server" do
16
+ WIN32OLE.should_receive(:new).with("ServerName")
17
+ QBFC::OLEWrapper.new("ServerName")
18
+ end
19
+
20
+ it "should return ole_methods" do
21
+ @ole_object.should_receive("ole_methods").and_return([])
22
+ @wrapper.ole_methods.should == []
23
+ end
24
+
25
+ it "should check if the OLE object responds to a given ole_method" do
26
+ @ole_object.should_receive("ole_methods").twice.and_return(["FullName", "ListID"])
27
+ @wrapper.respond_to_ole?(:FullName).should_not be_false
28
+ @wrapper.respond_to_ole?(:NonMethod).should be_nil
29
+ end
30
+
31
+ it "should make a list responding to GetAt act as an Array" do
32
+ @get_at_object = mock(WIN32OLE)
33
+ @get_at_wrapper = QBFC::OLEWrapper.new(@get_at_object)
34
+
35
+ @ole_object.should_receive("GetAt").with(1).and_return(@get_at_object)
36
+ QBFC::OLEWrapper.should_receive(:new).with(@get_at_object).and_return(@get_at_wrapper)
37
+
38
+ @wrapper[1].should == @get_at_wrapper
39
+ end
40
+
41
+ it "should pass non-integer values to [] on to ole_object" do
42
+ @ole_object.should_receive("[]").with('1').and_return("Second Object")
43
+ @wrapper['1'].should == "Second Object"
44
+ end
45
+
46
+ describe "QBFC::OLEWrapper#qbfc_method_missing" do
47
+
48
+ before(:each) do
49
+ @sess = mock(QBFC::Session)
50
+ @ole_object = mock(WIN32OLE)
51
+ @wrapper = QBFC::OLEWrapper.new(@ole_object)
52
+
53
+ @full_name = mock('WIN32OLE.FullName')
54
+ @full_name.stub!(:ole_methods).and_return(['GetValue', 'SetValue'])
55
+
56
+ @ole_object.stub!(:FullName).and_return(@full_name)
57
+ @ole_object.stub!(:ole_methods).and_return(['FullName', 'LineRetList', 'PayeeEntityRef', 'AccountRef', 'TimeModified', 'ListID', 'ORInvoiceLineRetList'])
58
+ end
59
+
60
+ it "should call a capitalized method directly" do
61
+ @ole_object.should_receive(:TestValue).and_return(0)
62
+ QBFC::OLEWrapper.should_not_receive(:new)
63
+
64
+ @wrapper.qbfc_method_missing(@sess, :TestValue).should == 0
65
+ end
66
+
67
+ it "should call a capitalized method directly and wrap in OLEWrapper if it returns a WIN32OLE" do
68
+ @full_name = WIN32OLE.new("QBFC6.QBSessionManager")
69
+ @ole_object.should_receive(:FullName).and_return(@full_name)
70
+ @full_name.should_not_receive(:GetValue)
71
+
72
+ @full_name_wrapper = QBFC::OLEWrapper.new(@ole_object)
73
+ QBFC::OLEWrapper.should_receive(:new).with(@full_name).and_return(@full_name_wrapper)
74
+
75
+ @wrapper.qbfc_method_missing(@sess, :FullName).should == @full_name_wrapper
76
+ end
77
+
78
+ it "should act as a getter method" do
79
+ @ole_object.should_receive(:FullName).and_return(@full_name)
80
+ @full_name.should_receive(:GetValue).and_return('Full Name')
81
+
82
+ @wrapper.qbfc_method_missing(@sess, :full_name).should == 'Full Name'
83
+ end
84
+
85
+ it "should convert 'Id' to 'ID' in getter" do
86
+ @ole_object.should_receive(:ListID).and_return(@full_name)
87
+ @full_name.should_receive(:GetValue).and_return('{123-456}')
88
+
89
+ @wrapper.qbfc_method_missing(@sess, :list_id).should == '{123-456}'
90
+ end
91
+
92
+ it "should convert return of date/time getter methods to Time" do
93
+ time_modified = @full_name
94
+ @ole_object.should_receive(:TimeModified).and_return(time_modified)
95
+ time_modified.should_receive(:GetValue).and_return('2007-01-01 10:00:00')
96
+
97
+ ret = @wrapper.qbfc_method_missing(@sess, :time_modified)
98
+ ret.should be_kind_of(Time)
99
+ ret.strftime("%Y-%m-%d %H:%M:%S").should == '2007-01-01 10:00:00'
100
+ end
101
+
102
+ it "should wrap WIN32OLE objects returned by getter that don't respond to GetValue" do
103
+ @full_name = WIN32OLE.new("QBFC6.QBSessionManager")
104
+ @ole_object.should_receive(:FullName).and_return(@full_name)
105
+ @full_name.should_receive(:ole_methods).and_return(['SetValue'])
106
+ @full_name.should_not_receive(:GetValue)
107
+
108
+ @full_name_wrapper = QBFC::OLEWrapper.new(@ole_object)
109
+ QBFC::OLEWrapper.should_receive(:new).with(@full_name).and_return(@full_name_wrapper)
110
+
111
+ @wrapper.qbfc_method_missing(@sess, :full_name).should == @full_name_wrapper
112
+ end
113
+
114
+ it "should wrap @setter if applicable when wrapping WIN32OLE objects returned by getter " do
115
+ @setter = mock(WIN32OLE)
116
+ @setter.should_receive("ole_methods").and_return(["FullName", "ListID"])
117
+ @wrapper = QBFC::OLEWrapper.new(@ole_object, @setter)
118
+
119
+ @full_name_getter = WIN32OLE.new("QBFC6.QBSessionManager")
120
+ @full_name_setter = WIN32OLE.new("QBFC6.QBSessionManager")
121
+ @ole_object.should_receive(:FullName).and_return(@full_name_getter)
122
+ @full_name_getter.should_receive(:ole_methods).and_return(['SetValue'])
123
+ @setter.should_receive(:FullName).and_return(@full_name_setter)
124
+
125
+ @full_name_wrapper = QBFC::OLEWrapper.new(@full_name_getter, @full_name_setter)
126
+ QBFC::OLEWrapper.should_receive(:new).with(@full_name_getter, @full_name_setter).and_return(@full_name_wrapper)
127
+
128
+ @wrapper.qbfc_method_missing(@sess, :full_name).should == @full_name_wrapper
129
+ end
130
+
131
+ it "should return non-WIN32OLE returned by getter that don't respond to GetValue" do
132
+ @ole_object.should_receive(:FullName).and_return('Full Name')
133
+ @full_name.should_not_receive(:GetValue)
134
+ @wrapper.qbfc_method_missing(@sess, :full_name).should == 'Full Name'
135
+ end
136
+
137
+ it "should act as a setter method" do
138
+ @ole_object.should_receive(:FullName).and_return(@full_name)
139
+ @full_name.should_receive(:SetValue).with('Full Name')
140
+
141
+ @wrapper.qbfc_method_missing(@sess, :full_name=, 'Full Name')
142
+ end
143
+
144
+ it "should set @setter also when acting as a setter method, if applicable" do
145
+ @setter = mock(WIN32OLE)
146
+ @setter.should_receive("ole_methods").and_return(["FullName", "ListID"])
147
+ @wrapper = QBFC::OLEWrapper.new(@ole_object, @setter)
148
+
149
+ @full_name_setter = WIN32OLE.new("QBFC6.QBSessionManager")
150
+ @setter.should_receive(:FullName).and_return(@full_name_setter)
151
+ @full_name.should_receive(:SetValue).with('Full Name')
152
+ @full_name_setter.should_receive(:SetValue).with('Full Name')
153
+
154
+ @wrapper.qbfc_method_missing(@sess, :full_name=, 'Full Name')
155
+ end
156
+
157
+ it "should convert 'Id' to 'ID' in setter" do
158
+ @ole_object.should_receive(:ListID).and_return(@full_name)
159
+ @full_name.should_receive(:SetValue).and_return('{123-456}')
160
+
161
+ @wrapper.qbfc_method_missing(@sess, :list_id=, '{123-456}')
162
+ end
163
+
164
+ it "should raise SetValueMissing error on a setter call for a method without SetValue" do
165
+ @ole_object.should_receive(:FullName).and_return(@full_name)
166
+ @full_name.should_receive(:ole_methods).and_return(['GetValue'])
167
+
168
+ lambda { @wrapper.qbfc_method_missing(@sess, :full_name=, 'Full Name') }.
169
+ should raise_error(QBFC::SetValueMissing)
170
+ end
171
+
172
+ it "should wrap *RetList objects in an Array" do
173
+ ret_list = mock('WIN32OLE.RetList')
174
+ ret_list.stub!(:ole_methods).and_return(['GetAt', 'Count'])
175
+ ret_list.should_receive(:Count).and_return(2)
176
+ ret_list.should_receive(:GetAt).with(0).and_return(@full_name)
177
+ ret_list.should_receive(:GetAt).with(1).and_return(@full_name)
178
+
179
+ @ole_object.should_receive(:LineRetList).and_return(ret_list)
180
+
181
+ @full_name_wrapper = QBFC::OLEWrapper.new(@full_name)
182
+ QBFC::OLEWrapper.should_receive(:new).with(@full_name).twice.and_return(@full_name_wrapper)
183
+
184
+ @wrapper.qbfc_method_missing(@sess, :lines).should ==
185
+ [@full_name_wrapper, @full_name_wrapper]
186
+ end
187
+
188
+ it "should wrap OR*RetList objects in an Array" do
189
+ ret_list = mock('WIN32OLE.ORInvoiceLineRetList')
190
+ list_item_wrapper = mock('WIN32OLE.InvoiceLineRetWrapper')
191
+ list_item = mock('WIN32OLE.InvoiceLineRet')
192
+ ret_list.stub!(:ole_methods).and_return(['GetAt', 'Count'])
193
+ ret_list.should_receive(:Count).and_return(2)
194
+ ret_list.should_receive(:GetAt).with(0).and_return(list_item_wrapper)
195
+ ret_list.should_receive(:GetAt).with(1).and_return(list_item_wrapper)
196
+ list_item_wrapper.should_receive(:InvoiceLineRet).twice.and_return(list_item)
197
+
198
+ @ole_object.should_receive(:ORInvoiceLineRetList).and_return(ret_list)
199
+
200
+ @wrapper.qbfc_method_missing(@sess, :invoice_lines).should ==
201
+ [list_item, list_item]
202
+ end
203
+
204
+ it "should have *_full_name for *Ref" do
205
+ ref = mock('WIN32OLE.PayeeRef')
206
+ @ole_object.should_receive(:AccountRef).and_return(ref)
207
+
208
+ full_name = "Full Name"
209
+ full_name_obj = mock('WIN32OLE.FullName')
210
+ ref.should_receive(:FullName).and_return(full_name_obj)
211
+ full_name_obj.should_receive(:GetValue).and_return(full_name)
212
+
213
+ @wrapper.qbfc_method_missing(@sess, :account_full_name).should == full_name
214
+ end
215
+
216
+ it "should have *_id for *Ref" do
217
+ ref = mock('WIN32OLE.PayeeRef')
218
+ @ole_object.should_receive(:AccountRef).and_return(ref)
219
+
220
+ list_id = "1"
221
+ list_id_obj = mock('WIN32OLE.ListID')
222
+ ref.should_receive(:ListID).and_return(list_id_obj)
223
+ list_id_obj.should_receive(:GetValue).and_return(list_id)
224
+
225
+ @wrapper.qbfc_method_missing(@sess, :account_id).should == list_id
226
+ end
227
+
228
+ it "should have *_full_name for *EntityRef" do
229
+ ref = mock('WIN32OLE.PayeeEntityRef')
230
+ @ole_object.should_receive(:PayeeEntityRef).and_return(ref)
231
+
232
+ full_name = "Full Name"
233
+ full_name_obj = mock('WIN32OLE.FullName')
234
+ ref.should_receive(:FullName).and_return(full_name_obj)
235
+ full_name_obj.should_receive(:GetValue).and_return(full_name)
236
+
237
+ @wrapper.qbfc_method_missing(@sess, :payee_full_name).should == full_name
238
+ end
239
+
240
+ it "should have *_id for *EntityRef" do
241
+ ref = mock('WIN32OLE.PayeeEntityRef')
242
+ @ole_object.should_receive(:PayeeEntityRef).and_return(ref)
243
+
244
+ list_id = "1"
245
+ list_id_obj = mock('WIN32OLE.ListID')
246
+ ref.should_receive(:ListID).and_return(list_id_obj)
247
+ list_id_obj.should_receive(:GetValue).and_return(list_id)
248
+
249
+ @wrapper.qbfc_method_missing(@sess, :payee_id).should == list_id
250
+ end
251
+
252
+ it "should create a Base-inherited object from a *EntityRef" do
253
+ entity_ref = mock('WIN32OLE.PayeeEntityRef')
254
+ @ole_object.should_receive(:PayeeEntityRef).and_return(entity_ref)
255
+
256
+ list_id = "1"
257
+ list_id_obj = mock('WIN32OLE.ListID')
258
+ entity_ref.should_receive(:ListID).and_return(list_id_obj)
259
+ list_id_obj.should_receive(:GetValue).and_return(list_id)
260
+
261
+ entity = mock(QBFC::Entity)
262
+
263
+ QBFC::Entity.should_receive(:find_by_id).with(@sess, list_id).and_return(entity)
264
+
265
+ @wrapper.qbfc_method_missing(@sess, :payee).should == entity
266
+ end
267
+
268
+ it "should return nil for a *Ref if the ole_method calling *Ref returns nil" do
269
+ @ole_object.should_receive(:PayeeEntityRef).and_return(nil)
270
+ @wrapper.qbfc_method_missing(@sess, :payee).should be_nil
271
+ end
272
+
273
+ it "should create a Base-inherited object from a *Ref" do
274
+ account_ref = mock('WIN32OLE.AccountRef')
275
+ @ole_object.should_receive(:AccountRef).and_return(account_ref)
276
+
277
+ list_id = "1"
278
+ list_id_obj = mock('WIN32OLE.ListID')
279
+ account_ref.should_receive(:ListID).and_return(list_id_obj)
280
+ list_id_obj.should_receive(:GetValue).and_return(list_id)
281
+
282
+ account = mock(QBFC::Account)
283
+
284
+ QBFC::Account.should_receive(:find_by_id).with(@sess, list_id).and_return(account)
285
+
286
+ @wrapper.qbfc_method_missing(@sess, :account).should == account
287
+ end
288
+
289
+ it "should raise NoMethodError if none of the above apply" do
290
+ lambda { @wrapper.qbfc_method_missing(@sess, :no_method) }.should raise_error(NoMethodError, 'no_method')
291
+ end
292
+ end
293
+ end
@@ -0,0 +1,13 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe QBFC::QBCollection do
4
+
5
+ before(:each) do
6
+ @sess = mock(QBFC::Session)
7
+ end
8
+
9
+ it "should send missing methods to the Class specified, with the Session" do
10
+ QBFC::Customer.should_receive(:find).with(@sess, :all)
11
+ QBFC::QBCollection.new(@sess, 'Customer').find(:all)
12
+ end
13
+ end
@@ -0,0 +1,10 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe QBFC_CONST do
4
+
5
+ it "should load QBFC constants" do
6
+ QBFC_CONST::DmToday.should == 1
7
+ QBFC_CONST::OmDontCare.should == 2
8
+ end
9
+
10
+ end
@@ -0,0 +1,10 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe QBFC do
4
+
5
+ it "should have a session method which calls QBFC::Session.open" do
6
+ QBFC::Session.should_receive(:open).with({:filename => "file"})
7
+ QBFC::session({:filename => "file"})
8
+ end
9
+
10
+ end
@@ -0,0 +1,48 @@
1
+ These are notes from a "survey" through possible options for Query Requests.
2
+ This is intended to inform what specs are added to Request (particularly
3
+ #apply_options and the methods it calls).
4
+
5
+ lists
6
+ - list_id_list
7
+ - full_name_list
8
+ - txn_id_list
9
+ - ref_number_list
10
+ - ref_number_case_sensitive_list
11
+
12
+ filters
13
+ - max_returned (alias limit)
14
+ - active_status (alias active)
15
+
16
+ - from_modified_date (for lists)
17
+ - to_modified_date (for lists)
18
+
19
+ - ORDateRangeFilter
20
+ - modified_date_range_filter (from and to)
21
+ - txn_date_range_filter (from and to OR macro)
22
+
23
+ - entity_filter / account_filter / item_filter (all ORs)
24
+ - ListIDList, FullNameList, ListIDWithChildren, FullNameWithChildren
25
+
26
+ - ORNameFilter / ORRefNumFilter
27
+ - name_filter (has criterion and name)
28
+ - name_range_filter (from and to)
29
+
30
+ - time_tracking_entity_filter
31
+
32
+ - ItemRef
33
+
34
+ - account_type_list
35
+
36
+ - txn_filter_no_account (SalesOrder)
37
+
38
+ - pending_status
39
+ - paid_status
40
+ - done_status
41
+
42
+ TransactionQuery has a bunch of extras
43
+
44
+ includes
45
+ - include_ret_element_list
46
+ - include_line_items
47
+ - include_linked_txns
48
+ - IncludeComponentLineItems
@@ -0,0 +1,236 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe QBFC::Request do
4
+
5
+ before(:each) do
6
+ @sess = mock(QBFC::Session)
7
+ @request_set = mock(QBFC::OLEWrapper)
8
+ @ole_request = mock(QBFC::OLEWrapper)
9
+
10
+ @sess.stub!(:CreateMsgSetRequest).and_return(@request_set)
11
+ @request_set.stub!(:AppendCustomerQueryRq).and_return(@ole_request)
12
+ end
13
+
14
+ it "sends CreateMsgSetRequest to Quickbooks Session" do
15
+ @sess.should_receive(:CreateMsgSetRequest).with('US', 6, 0).and_return(@request_set)
16
+ QBFC::Request.new(@sess, 'CustomerQuery')
17
+ end
18
+
19
+ it "appends a query to MsgSetRequest" do
20
+ @request_set.should_receive(:AppendCustomerQueryRq).and_return @ole_request
21
+ QBFC::Request.new(@sess, 'CustomerQuery')
22
+ end
23
+
24
+ it "accepts version information" do
25
+ @sess.should_receive(:CreateMsgSetRequest).with('CA', 5, 5).and_return(@request_set)
26
+ QBFC::Request.new(@sess, 'CustomerQuery', 'CA', 5, 5)
27
+ end
28
+
29
+ it "should raise a QBFC::QBXMLVersionError if the version is not supported" do
30
+ @sess.should_receive(:CreateMsgSetRequest).and_raise(WIN32OLERuntimeError.new('error code:8004030A'))
31
+ lambda { QBFC::Request.new(@sess, 'CustomerQuery')}.should raise_error(QBFC::QBXMLVersionError)
32
+ end
33
+
34
+ it "should re-raise errors other than QBXMLVersionError" do
35
+ @sess.should_receive(:CreateMsgSetRequest).and_raise(WIN32OLERuntimeError.new('error'))
36
+ lambda { QBFC::Request.new(@sess, 'CustomerQuery')}.should raise_error(WIN32OLERuntimeError)
37
+ end
38
+
39
+ it "should raise a QBFC::UnknownRequestError if the request is not supported" do
40
+ @request_set.should_receive(:AppendCustomerQueryRq).and_raise(WIN32OLERuntimeError.new('error code:0x80020006'))
41
+ lambda { QBFC::Request.new(@sess, 'CustomerQuery')}.should raise_error(QBFC::UnknownRequestError)
42
+ end
43
+
44
+ it "should re-raise errors other than UnknownRequestError" do
45
+ @request_set.should_receive(:AppendCustomerQueryRq).and_raise(WIN32OLERuntimeError.new('error'))
46
+ lambda { QBFC::Request.new(@sess, 'CustomerQuery')}.should raise_error(WIN32OLERuntimeError)
47
+ end
48
+
49
+ it "should show ole_methods" do
50
+ @ole_request.should_receive(:ole_methods)
51
+ QBFC::Request.new(@sess, 'CustomerQuery').ole_methods
52
+ end
53
+
54
+ it "gives direct access to the request's ole_object" do
55
+ @ole_request.should_receive(:ole_object).and_return("OLEObject")
56
+ QBFC::Request.new(@sess, 'CustomerQuery').ole_object.should == "OLEObject"
57
+ end
58
+
59
+ it "should have the OLEWrapper object handle missing methods" do
60
+ @ole_request.should_receive(:qbfc_method_missing).with(@sess, :no_method)
61
+ QBFC::Request.new(@sess, 'CustomerQuery').no_method
62
+
63
+ @ole_request.should_receive(:qbfc_method_missing).with(@sess, :NoMethod)
64
+ QBFC::Request.new(@sess, 'CustomerQuery').NoMethod
65
+ end
66
+
67
+ it "should return xml of the request" do
68
+ @request_set.should_receive(:ToXMLString)
69
+ QBFC::Request.new(@sess, 'CustomerQuery').to_xml
70
+ end
71
+
72
+ describe "#response" do
73
+ before(:each) do
74
+ @sess = mock(QBFC::Session)
75
+ @request_set = mock(QBFC::OLEWrapper)
76
+ @ole_request = mock(QBFC::OLEWrapper)
77
+
78
+ @sess.stub!(:CreateMsgSetRequest).and_return(@request_set)
79
+ @request_set.stub!(:AppendCustomerQueryRq).and_return(@ole_request)
80
+
81
+ @response_set = mock("DoRequestsRespost")
82
+ @response_list = mock("ResponseList")
83
+ @response = mock("GetAt")
84
+ @detail = mock("Detail")
85
+
86
+ @sess.stub!(:DoRequests).and_return @response_set
87
+ @response_set.stub!(:ResponseList).and_return @response_list
88
+ @response_list.stub!(:GetAt).and_return @response
89
+ @response.stub!(:Detail).and_return @detail
90
+ end
91
+
92
+ it "gets a response" do
93
+ @sess.should_receive(:DoRequests).and_return @response_set
94
+ @response_set.should_receive(:ResponseList).and_return @response_list
95
+ @response_list.should_receive(:GetAt).with(0).and_return @response
96
+ @response.should_receive(:Detail).and_return @detail
97
+
98
+ request = QBFC::Request.new(@sess, 'CustomerQuery')
99
+
100
+ request.response.should == @detail
101
+ end
102
+
103
+ it "returns a nil response if the response has no Detail" do
104
+ @response.should_receive(:Detail).and_return nil
105
+
106
+ request = QBFC::Request.new(@sess, 'CustomerQuery')
107
+
108
+ QBFC::OLEWrapper.should_not_receive(:new)
109
+ request.response.should be_nil
110
+ end
111
+
112
+
113
+ it "should return xml of the response" do
114
+ request = QBFC::Request.new(@sess, 'CustomerQuery')
115
+ @response_set.should_receive(:ToXMLString)
116
+ request.response_xml
117
+ end
118
+ end
119
+
120
+ describe "#query" do
121
+ before(:each) do
122
+ @request = QBFC::Request.new(@sess, 'CustomerQuery')
123
+ @request.instance_variable_set(:@request, @ole_request)
124
+
125
+ @or_query = mock("OLEWrapper#or_query")
126
+ end
127
+
128
+ it "gets the OR*Query for the given Request" do
129
+ @ole_request.should_receive(:ole_methods).and_return(["TxnID", "RefNumber", "ORTransactionQuery", "OwnerIDList"])
130
+ @ole_request.should_receive(:ORTransactionQuery).and_return(@or_query)
131
+ @request.query.should be(@or_query)
132
+ end
133
+
134
+ it "should return nil if no query name is detected" do
135
+ @ole_request.should_receive(:ole_methods).and_return(["TxnID", "RefNumber", "OwnerIDList"])
136
+ @request.query.should be_nil
137
+ end
138
+ end
139
+
140
+ describe "#filter" do
141
+ before(:each) do
142
+ @request = QBFC::Request.new(@sess, 'CustomerQuery')
143
+ @request.instance_variable_set(:@request, @ole_request)
144
+
145
+ @or_query = mock("OLEWrapper#or_query")
146
+ @filter = mock("OLEWrapper#filter")
147
+ @ole_request.stub!(:ole_methods).and_return(["TxnID", "RefNumber", "ORTransactionQuery", "OwnerIDList"])
148
+ @ole_request.stub!(:ORTransactionQuery).and_return(@or_query)
149
+ end
150
+
151
+ it "gets the *Filter for the given Request" do
152
+ @or_query.should_receive(:ole_methods).and_return(["TxnIDList", "RefNumberList", "TransactionFilter"])
153
+ @or_query.should_receive(:TransactionFilter).and_return(@filter)
154
+ @request.filter.should be(@filter)
155
+ end
156
+
157
+ it "should return nil if no filter name is detected" do
158
+ @or_query.should_receive(:ole_methods).and_return(["TxnIDList", "RefNumberList"])
159
+ @request.filter.should be_nil
160
+ end
161
+
162
+ it "should return nil if the #query is nil" do
163
+ @ole_request.should_receive(:ole_methods).and_return([])
164
+ @request.filter.should be_nil
165
+ end
166
+ end
167
+
168
+ describe "#filter_available?" do
169
+ before(:each) do
170
+ @request = QBFC::Request.new(@sess, 'CustomerQuery')
171
+
172
+ @or_query = mock("OLEWrapper#or_query")
173
+ @filter = mock("OLEWrapper#filter")
174
+ @ole_request.stub!(:ole_methods).and_return(["TxnID", "RefNumber", "ORTransactionQuery", "OwnerIDList", "ortype"])
175
+ @ole_request.stub!(:ORTransactionQuery).and_return(@or_query)
176
+
177
+ @ole_object = mock(WIN32OLE)
178
+ @or_query.stub!(:ole_object).and_return(@ole_object)
179
+ @ole_object.stub!(:ole_object).and_return(["TxnID", "RefNumber", "ORTransactionQuery", "OwnerIDList", "ortype"])
180
+ end
181
+
182
+ it "should be true if no query options have been set" do
183
+ @ole_object.should_receive(:ortype).at_least(:once).and_return(-1)
184
+ @request.filter_available?.should be_true
185
+ end
186
+
187
+ it "should be true if Filter option has been set" do
188
+ @ole_object.should_receive(:ortype).at_least(:once).and_return(2)
189
+ @request.filter_available?.should be_true
190
+ end
191
+
192
+ it "should be false if a *List option has been set" do
193
+ @ole_object.should_receive(:ortype).at_least(:once).and_return(1)
194
+ @request.filter_available?.should be_false
195
+ end
196
+
197
+ end
198
+
199
+ describe "#apply_options" do
200
+ before(:each) do
201
+ @request = QBFC::Request.new(@sess, 'CustomerQuery')
202
+ end
203
+
204
+ it "accepts an :owner_id option" do
205
+ @request.should_receive(:add_owner_ids).with(1)
206
+ @request.apply_options(:owner_id => 1)
207
+ end
208
+ end
209
+
210
+ describe "#add_owner_ids" do
211
+ before(:each) do
212
+ @request = QBFC::Request.new(@sess, 'CustomerQuery')
213
+ @owner_list = mock(QBFC::OLEWrapper)
214
+ end
215
+
216
+ it "can add a single owner id to the Request" do
217
+ @ole_request.should_receive(:OwnerIDList).and_return(@owner_list)
218
+ @owner_list.should_receive(:Add).with(0)
219
+ @request.add_owner_ids(0)
220
+ end
221
+
222
+ it "can add multiple owner ids to the Request" do
223
+ ids = ["{6B063959-81B0-4622-85D6-F548C8CCB517}", 0]
224
+ @ole_request.should_receive(:OwnerIDList).twice.and_return(@owner_list)
225
+ @owner_list.should_receive(:Add).with(ids[0])
226
+ @owner_list.should_receive(:Add).with(ids[1])
227
+ @request.add_owner_ids(ids)
228
+ end
229
+
230
+ it "can accept nil and will do nothing" do
231
+ @ole_request.should_not_receive(:OwnerIDList)
232
+ @owner_list.should_not_receive(:Add)
233
+ @request.add_owner_ids(nil)
234
+ end
235
+ end
236
+ end