jm81-qbfc 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.
- data/.gitignore +11 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +85 -0
- data/Rakefile +81 -0
- data/VERSION +1 -0
- data/init.rb +3 -0
- data/install.rb +1 -0
- data/lib/qbfc.rb +41 -0
- data/lib/qbfc/base.rb +82 -0
- data/lib/qbfc/element.rb +243 -0
- data/lib/qbfc/entities/generated.rb +8 -0
- data/lib/qbfc/entity.rb +11 -0
- data/lib/qbfc/info.rb +42 -0
- data/lib/qbfc/infos/generated.rb +9 -0
- data/lib/qbfc/item.rb +29 -0
- data/lib/qbfc/items/generated.rb +11 -0
- data/lib/qbfc/list.rb +84 -0
- data/lib/qbfc/lists/account.rb +24 -0
- data/lib/qbfc/lists/generated.rb +15 -0
- data/lib/qbfc/lists/qb_class.rb +25 -0
- data/lib/qbfc/modifiable.rb +31 -0
- data/lib/qbfc/ole_wrapper.rb +201 -0
- data/lib/qbfc/qb_collection.rb +26 -0
- data/lib/qbfc/qb_types.rb +18 -0
- data/lib/qbfc/qbfc_const.rb +14 -0
- data/lib/qbfc/report.rb +95 -0
- data/lib/qbfc/reports/aging.rb +13 -0
- data/lib/qbfc/reports/budget_summary.rb +13 -0
- data/lib/qbfc/reports/custom_detail.rb +9 -0
- data/lib/qbfc/reports/custom_summary.rb +9 -0
- data/lib/qbfc/reports/general_detail.rb +44 -0
- data/lib/qbfc/reports/general_summary.rb +33 -0
- data/lib/qbfc/reports/job.rb +14 -0
- data/lib/qbfc/reports/payroll_detail.rb +13 -0
- data/lib/qbfc/reports/payroll_summary.rb +13 -0
- data/lib/qbfc/reports/rows.rb +51 -0
- data/lib/qbfc/reports/time.rb +12 -0
- data/lib/qbfc/request.rb +295 -0
- data/lib/qbfc/session.rb +147 -0
- data/lib/qbfc/terms.rb +10 -0
- data/lib/qbfc/terms/generated.rb +10 -0
- data/lib/qbfc/transaction.rb +110 -0
- data/lib/qbfc/transactions/generated.rb +25 -0
- data/lib/qbfc/voidable.rb +11 -0
- data/spec/fixtures/test.lgb +0 -0
- data/spec/fixtures/test.qbw +0 -0
- data/spec/fixtures/test.qbw.TLG +0 -0
- data/spec/integration/add_spec.rb +31 -0
- data/spec/integration/base_spec.rb +18 -0
- data/spec/integration/belongs_to_spec.rb +64 -0
- data/spec/integration/company_spec.rb +30 -0
- data/spec/integration/conditions_spec.rb +59 -0
- data/spec/integration/customer_spec.rb +46 -0
- data/spec/integration/element_finders_spec.rb +20 -0
- data/spec/integration/quick_test.rb +31 -0
- data/spec/integration/request_options_spec.rb +68 -0
- data/spec/rcov.opts +1 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +62 -0
- data/spec/unit/base_spec.rb +138 -0
- data/spec/unit/element_finder_spec.rb +185 -0
- data/spec/unit/element_spec.rb +108 -0
- data/spec/unit/entities/generated_spec.rb +18 -0
- data/spec/unit/entity_spec.rb +18 -0
- data/spec/unit/info/generated_spec.rb +12 -0
- data/spec/unit/info_spec.rb +48 -0
- data/spec/unit/item_spec.rb +33 -0
- data/spec/unit/items/generated_spec.rb +16 -0
- data/spec/unit/list_finders_spec.rb +129 -0
- data/spec/unit/list_spec.rb +86 -0
- data/spec/unit/lists/account_spec.rb +20 -0
- data/spec/unit/lists/generated_spec.rb +15 -0
- data/spec/unit/lists/qb_class_spec.rb +9 -0
- data/spec/unit/modifiable_spec.rb +84 -0
- data/spec/unit/ole_wrapper_spec.rb +337 -0
- data/spec/unit/qb_collection_spec.rb +13 -0
- data/spec/unit/qbfc_const_spec.rb +10 -0
- data/spec/unit/qbfc_spec.rb +10 -0
- data/spec/unit/report_spec.rb +12 -0
- data/spec/unit/request_query_survey.txt +48 -0
- data/spec/unit/request_spec.rb +486 -0
- data/spec/unit/session_spec.rb +144 -0
- data/spec/unit/terms/generated_spec.rb +14 -0
- data/spec/unit/terms_spec.rb +18 -0
- data/spec/unit/transaction_finders_spec.rb +125 -0
- data/spec/unit/transaction_spec.rb +94 -0
- data/spec/unit/transactions/generated_spec.rb +20 -0
- data/spec/unit/voidable_spec.rb +32 -0
- data/tasks/qbfc_tasks.rake +4 -0
- data/uninstall.rb +1 -0
- metadata +180 -0
@@ -0,0 +1,13 @@
|
|
1
|
+
require '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,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe QBFC::Report do
|
4
|
+
|
5
|
+
describe ".get_class" do
|
6
|
+
it "should get the class for this report" do
|
7
|
+
QBFC::Report.get_class("AuditTrail").should be(QBFC::Reports::GeneralDetail)
|
8
|
+
QBFC::Report.get_class("PayrollSummary").should be(QBFC::Reports::PayrollSummary)
|
9
|
+
QBFC::Report.get_class("TimeByJobDetail").should be(QBFC::Reports::Time)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
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
|
+
X 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,486 @@
|
|
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
|
+
@query = mock('Request#query')
|
203
|
+
@filter = mock('Request#filter')
|
204
|
+
@request.stub!(:query).and_return(@query)
|
205
|
+
end
|
206
|
+
|
207
|
+
it "should apply an :owner_id option" do
|
208
|
+
@request.should_receive(:add_owner_ids).with(1)
|
209
|
+
@request.apply_options(:owner_id => 1)
|
210
|
+
end
|
211
|
+
|
212
|
+
it "should apply an :limit option" do
|
213
|
+
@request.should_receive(:add_limit).with(1)
|
214
|
+
@request.apply_options(:limit => 1)
|
215
|
+
end
|
216
|
+
|
217
|
+
it "should apply an :include option" do
|
218
|
+
include_ary = [1,2,3]
|
219
|
+
@request.should_receive(:add_includes).with(include_ary)
|
220
|
+
@request.apply_options(:include => include_ary)
|
221
|
+
end
|
222
|
+
|
223
|
+
it "should apply lists to query" do
|
224
|
+
ref_number_list = mock('OLEWrapper#ref_number_list')
|
225
|
+
@query.should_receive(:RefNumberList).and_return(ref_number_list)
|
226
|
+
ref_number_list.should_receive(:Add).with('82')
|
227
|
+
ref_number_list.should_receive(:Add).with('1234')
|
228
|
+
|
229
|
+
@request.apply_options(:conditions => {:ref_number_list => %w{82 1234}})
|
230
|
+
end
|
231
|
+
|
232
|
+
it "should apply lists to query when given a single item" do
|
233
|
+
ref_number_list = mock('OLEWrapper#ref_number_list')
|
234
|
+
@query.should_receive(:RefNumberList).and_return(ref_number_list)
|
235
|
+
ref_number_list.should_receive(:Add).with('20')
|
236
|
+
|
237
|
+
@request.apply_options(:conditions => {:ref_number_list => '20'})
|
238
|
+
end
|
239
|
+
|
240
|
+
describe "(range)" do
|
241
|
+
before(:each) do
|
242
|
+
@range_filter = mock('Request#TxnDateRangeFilter')
|
243
|
+
@request.stub!(:filter_for).with('txn_date_range').and_return(@range_filter)
|
244
|
+
@request.stub!(:filter_for).with('modified_date_range').and_return(@range_filter)
|
245
|
+
@range_filter.stub!(:from_txn_date=)
|
246
|
+
@range_filter.stub!(:to_txn_date=)
|
247
|
+
end
|
248
|
+
|
249
|
+
it "should #parse_range_value" do
|
250
|
+
@request.should_receive(:parse_range_value).with([0,2]).and_return([0,2])
|
251
|
+
@request.apply_options(:conditions => {:txn_date_range => [0,2]})
|
252
|
+
end
|
253
|
+
|
254
|
+
it "should get appropriate filter" do
|
255
|
+
@request.should_receive(:filter_for).with('txn_date_range').and_return(@range_filter)
|
256
|
+
@request.apply_options(:conditions => {:txn_date_range => [0,2]})
|
257
|
+
end
|
258
|
+
|
259
|
+
it "should apply date range to filter" do
|
260
|
+
@range_filter.should_receive(:from_txn_date=).with(0)
|
261
|
+
@range_filter.should_receive(:to_txn_date=).with(2)
|
262
|
+
@request.apply_options(:conditions => {:txn_date_range => [0,2]})
|
263
|
+
end
|
264
|
+
|
265
|
+
it "should add 'true' argument (asDateOnly) for modified_date ranges" do
|
266
|
+
@range_filter.should_receive(:from_modified_date=).with(0, true)
|
267
|
+
@range_filter.should_receive(:to_modified_date=).with(2, true)
|
268
|
+
@request.apply_options(:conditions => {:modified_date_range => [0,2]})
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
describe "(status)" do
|
273
|
+
it "should set status" do
|
274
|
+
@filter = mock('Request#filter')
|
275
|
+
@request.stub!(:filter).and_return(@filter)
|
276
|
+
@filter.should_receive(:paid_status=).with(QBFC_CONST::PsPaidOnly)
|
277
|
+
@request.apply_options(:conditions => {:paid_status => QBFC_CONST::PsPaidOnly})
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
describe "(reference)" do
|
282
|
+
before(:each) do
|
283
|
+
@ref_filter = mock('Request#RefFilter')
|
284
|
+
@full_name_list = mock('OLEWrapper#FullNameList')
|
285
|
+
@request.stub!(:filter_for).with('entity').and_return(@ref_filter)
|
286
|
+
@ref_filter.should_receive(:FullNameList).at_least(:once).and_return(@full_name_list)
|
287
|
+
@full_name_list.stub!(:Add)
|
288
|
+
end
|
289
|
+
|
290
|
+
it "should get appropriate filter" do
|
291
|
+
@request.should_receive(:filter_for).with('entity').and_return(@ref_filter)
|
292
|
+
@request.apply_options(:conditions => {:entity => 'ABC Supplies'})
|
293
|
+
end
|
294
|
+
|
295
|
+
it "should set a single full name" do
|
296
|
+
@full_name_list.should_receive(:Add).with('ABC Supplies')
|
297
|
+
@request.apply_options(:conditions => {:entity => 'ABC Supplies'})
|
298
|
+
end
|
299
|
+
|
300
|
+
it "should set a single full name (non-string)" do
|
301
|
+
@full_name_list.should_receive(:Add).with(1)
|
302
|
+
@request.apply_options(:conditions => {:entity => 1})
|
303
|
+
end
|
304
|
+
|
305
|
+
it "should set a multiple full names" do
|
306
|
+
@full_name_list.should_receive(:Add).with('ABC Supplies')
|
307
|
+
@full_name_list.should_receive(:Add).with('CompuStuff')
|
308
|
+
@request.apply_options(:conditions => {:entity => %w{ABC\ Supplies CompuStuff}})
|
309
|
+
end
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
describe "#add_includes" do
|
314
|
+
before(:each) do
|
315
|
+
@request = QBFC::Request.new(@sess, 'CustomerQuery')
|
316
|
+
@ret_list = mock('RetElementList')
|
317
|
+
|
318
|
+
@ole_request.stub!(:respond_to_ole?).with('IncludeLineItems').and_return(true)
|
319
|
+
@ole_request.stub!(:respond_to_ole?).with('IncludeLinkedTxns').and_return(true)
|
320
|
+
@ole_request.stub!(:respond_to_ole?).with('IncludeTxnID').and_return(false)
|
321
|
+
@ole_request.stub!(:respond_to_ole?).with('IncludeCustomerRef').and_return(false)
|
322
|
+
end
|
323
|
+
|
324
|
+
it "should add specific include requests" do
|
325
|
+
@ole_request.should_receive(:include_line_items=).with(true)
|
326
|
+
@request.__send__(:add_includes, [:line_items])
|
327
|
+
end
|
328
|
+
|
329
|
+
it "should apply additional includes to IncludeRetElementList" do
|
330
|
+
@ole_request.should_receive(:IncludeRetElementList).twice.and_return(@ret_list)
|
331
|
+
@ret_list.should_receive(:Add).with('TxnID')
|
332
|
+
@ret_list.should_receive(:Add).with('CustomerRef')
|
333
|
+
@request.__send__(:add_includes, [:txn_id, :customer_ref])
|
334
|
+
end
|
335
|
+
|
336
|
+
it "should include :all" do
|
337
|
+
@ole_request.should_receive(:ole_methods).and_return(%w{ORTxnQuery IncludeLineItems IncludeLinkedTxns iterator})
|
338
|
+
@ole_request.should_receive(:include_line_items=).with(true)
|
339
|
+
@ole_request.should_receive(:include_linked_txns=).with(true)
|
340
|
+
@request.__send__(:add_includes, :all)
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
344
|
+
describe "#parse_range_value" do
|
345
|
+
before(:each) do
|
346
|
+
@request = QBFC::Request.new(@sess, 'CustomerQuery')
|
347
|
+
end
|
348
|
+
|
349
|
+
it "should add a nil element to a one-element Array" do
|
350
|
+
ary = [0]
|
351
|
+
@request.__send__(:parse_range_value, ary).should == [0, nil]
|
352
|
+
end
|
353
|
+
|
354
|
+
it "should return unchanged a multiple element Array" do
|
355
|
+
ary = [0, 1]
|
356
|
+
@request.__send__(:parse_range_value, ary).should be(ary)
|
357
|
+
end
|
358
|
+
|
359
|
+
it "should return unchanged a Range" do
|
360
|
+
rng = 0..1
|
361
|
+
@request.__send__(:parse_range_value, rng).should be(rng)
|
362
|
+
end
|
363
|
+
|
364
|
+
it "should take a scalar and return an array with the second element nil" do
|
365
|
+
val = 0
|
366
|
+
@request.__send__(:parse_range_value, val).should == [val, nil]
|
367
|
+
end
|
368
|
+
|
369
|
+
it "should take a String scalar and return an array with the second element nil" do
|
370
|
+
val = '0'
|
371
|
+
@request.__send__(:parse_range_value, val).should == [val, nil]
|
372
|
+
end
|
373
|
+
|
374
|
+
end
|
375
|
+
|
376
|
+
describe "#filter_for" do
|
377
|
+
before(:each) do
|
378
|
+
@request = QBFC::Request.new(@sess, 'CustomerQuery')
|
379
|
+
@query = mock('Request#query')
|
380
|
+
@filter = mock('Request#filter')
|
381
|
+
@request.stub!(:query).and_return(@query)
|
382
|
+
@request.stub!(:filter).and_return(@filter)
|
383
|
+
|
384
|
+
@or_date_range_filter = mock('Request#ORDateRangeFilter')
|
385
|
+
@or_ref_number_filter = mock('Request#ORRefNumberFilter')
|
386
|
+
@txn_date_range_filter = mock('Request#TxnDateRangeFilter')
|
387
|
+
@final_filter = mock('Request#FinalFilter')
|
388
|
+
|
389
|
+
@filter.stub!(:respond_to_ole?).and_return(false)
|
390
|
+
@or_date_range_filter.stub!(:respond_to_ole?).and_return(false)
|
391
|
+
@final_filter.stub!(:respond_to_ole?).and_return(false)
|
392
|
+
end
|
393
|
+
|
394
|
+
it "should follow ORDateRangeFilter for date_ranges" do
|
395
|
+
@filter.should_receive(:respond_to_ole?).with('ORDateRangeFilter').and_return(true)
|
396
|
+
@filter.should_receive(:ORDateRangeFilter).and_return(@or_date_range_filter)
|
397
|
+
@or_date_range_filter.should_receive(:ModifiedDateRangeFilter).and_return(@final_filter)
|
398
|
+
|
399
|
+
@request.__send__(:filter_for, 'modified_date_range').should be(@final_filter)
|
400
|
+
end
|
401
|
+
|
402
|
+
it "should follow OR{name}Filter" do
|
403
|
+
@filter.should_receive(:respond_to_ole?).with('ORRefNumberFilter').and_return(true)
|
404
|
+
@filter.should_receive(:ORRefNumberFilter).and_return(@or_ref_number_filter)
|
405
|
+
@or_ref_number_filter.should_receive(:RefNumberFilter).and_return(@final_filter)
|
406
|
+
|
407
|
+
@request.__send__(:filter_for, 'ref_number').should be(@final_filter)
|
408
|
+
end
|
409
|
+
|
410
|
+
it "should follow OR{name}Filter, with 'Range' removed" do
|
411
|
+
@filter.should_receive(:respond_to_ole?).with('ORRefNumberFilter').and_return(true)
|
412
|
+
@filter.should_receive(:ORRefNumberFilter).and_return(@or_ref_number_filter)
|
413
|
+
@or_ref_number_filter.should_receive(:RefNumberRangeFilter).and_return(@final_filter)
|
414
|
+
|
415
|
+
@request.__send__(:filter_for, 'ref_number_range').should be(@final_filter)
|
416
|
+
end
|
417
|
+
|
418
|
+
it "should return #filter if *ModifiedDate in #filter" do
|
419
|
+
@filter.should_receive(:respond_to_ole?).with('FromModifiedDate').and_return(true)
|
420
|
+
@request.__send__(:filter_for, 'modified_date_range').should == @filter
|
421
|
+
end
|
422
|
+
|
423
|
+
it "should follow OR below the Filter" do
|
424
|
+
@filter.should_receive(:respond_to_ole?).with('TxnDateRangeFilter').and_return(true)
|
425
|
+
@filter.should_receive(:TxnDateRangeFilter).and_return(@txn_date_range_filter)
|
426
|
+
|
427
|
+
@txn_date_range_filter.should_receive(:respond_to_ole?).with('ORTxnDateRangeFilter').and_return(true)
|
428
|
+
@txn_date_range_filter.should_receive(:ORTxnDateRangeFilter).and_return(@or_date_range_filter)
|
429
|
+
|
430
|
+
@request.__send__(:filter_for, 'txn_date_range').should be(@or_date_range_filter)
|
431
|
+
end
|
432
|
+
|
433
|
+
it "should get a nested Filter with 'Range' removed" do
|
434
|
+
@filter.should_receive(:respond_to_ole?).with('TxnDateRangeFilter').and_return(true)
|
435
|
+
@filter.should_receive(:TxnDateRangeFilter).and_return(@txn_date_range_filter)
|
436
|
+
|
437
|
+
@txn_date_range_filter.should_receive(:respond_to_ole?).with('ORTxnDateRangeFilter').and_return(true)
|
438
|
+
@txn_date_range_filter.should_receive(:ORTxnDateRangeFilter).and_return(@or_date_range_filter)
|
439
|
+
|
440
|
+
@or_date_range_filter.should_receive(:respond_to_ole?).with('TxnDateFilter').and_return(true)
|
441
|
+
@or_date_range_filter.should_receive(:TxnDateFilter).and_return(@final_filter)
|
442
|
+
|
443
|
+
@request.__send__(:filter_for, 'txn_date_range').should be(@final_filter)
|
444
|
+
end
|
445
|
+
end
|
446
|
+
|
447
|
+
describe "#add_owner_ids" do
|
448
|
+
before(:each) do
|
449
|
+
@request = QBFC::Request.new(@sess, 'CustomerQuery')
|
450
|
+
@owner_list = mock(QBFC::OLEWrapper)
|
451
|
+
end
|
452
|
+
|
453
|
+
it "can add a single owner id to the Request" do
|
454
|
+
@ole_request.should_receive(:OwnerIDList).and_return(@owner_list)
|
455
|
+
@owner_list.should_receive(:Add).with(0)
|
456
|
+
@request.add_owner_ids(0)
|
457
|
+
end
|
458
|
+
|
459
|
+
it "can add multiple owner ids to the Request" do
|
460
|
+
ids = ["{6B063959-81B0-4622-85D6-F548C8CCB517}", 0]
|
461
|
+
@ole_request.should_receive(:OwnerIDList).twice.and_return(@owner_list)
|
462
|
+
@owner_list.should_receive(:Add).with(ids[0])
|
463
|
+
@owner_list.should_receive(:Add).with(ids[1])
|
464
|
+
@request.add_owner_ids(ids)
|
465
|
+
end
|
466
|
+
|
467
|
+
it "can accept nil and will do nothing" do
|
468
|
+
@ole_request.should_not_receive(:OwnerIDList)
|
469
|
+
@owner_list.should_not_receive(:Add)
|
470
|
+
@request.add_owner_ids(nil)
|
471
|
+
end
|
472
|
+
end
|
473
|
+
|
474
|
+
describe "#add_limit" do
|
475
|
+
before(:each) do
|
476
|
+
@request = QBFC::Request.new(@sess, 'CustomerQuery')
|
477
|
+
@filter = mock('Request#filter')
|
478
|
+
@request.stub!(:filter).and_return(@filter)
|
479
|
+
end
|
480
|
+
|
481
|
+
it "can should update the filter's max_returned value" do
|
482
|
+
@filter.should_receive(:max_returned=).with(1)
|
483
|
+
@request.add_limit(1)
|
484
|
+
end
|
485
|
+
end
|
486
|
+
end
|