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.
Files changed (91) hide show
  1. data/.gitignore +11 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +85 -0
  4. data/Rakefile +81 -0
  5. data/VERSION +1 -0
  6. data/init.rb +3 -0
  7. data/install.rb +1 -0
  8. data/lib/qbfc.rb +41 -0
  9. data/lib/qbfc/base.rb +82 -0
  10. data/lib/qbfc/element.rb +243 -0
  11. data/lib/qbfc/entities/generated.rb +8 -0
  12. data/lib/qbfc/entity.rb +11 -0
  13. data/lib/qbfc/info.rb +42 -0
  14. data/lib/qbfc/infos/generated.rb +9 -0
  15. data/lib/qbfc/item.rb +29 -0
  16. data/lib/qbfc/items/generated.rb +11 -0
  17. data/lib/qbfc/list.rb +84 -0
  18. data/lib/qbfc/lists/account.rb +24 -0
  19. data/lib/qbfc/lists/generated.rb +15 -0
  20. data/lib/qbfc/lists/qb_class.rb +25 -0
  21. data/lib/qbfc/modifiable.rb +31 -0
  22. data/lib/qbfc/ole_wrapper.rb +201 -0
  23. data/lib/qbfc/qb_collection.rb +26 -0
  24. data/lib/qbfc/qb_types.rb +18 -0
  25. data/lib/qbfc/qbfc_const.rb +14 -0
  26. data/lib/qbfc/report.rb +95 -0
  27. data/lib/qbfc/reports/aging.rb +13 -0
  28. data/lib/qbfc/reports/budget_summary.rb +13 -0
  29. data/lib/qbfc/reports/custom_detail.rb +9 -0
  30. data/lib/qbfc/reports/custom_summary.rb +9 -0
  31. data/lib/qbfc/reports/general_detail.rb +44 -0
  32. data/lib/qbfc/reports/general_summary.rb +33 -0
  33. data/lib/qbfc/reports/job.rb +14 -0
  34. data/lib/qbfc/reports/payroll_detail.rb +13 -0
  35. data/lib/qbfc/reports/payroll_summary.rb +13 -0
  36. data/lib/qbfc/reports/rows.rb +51 -0
  37. data/lib/qbfc/reports/time.rb +12 -0
  38. data/lib/qbfc/request.rb +295 -0
  39. data/lib/qbfc/session.rb +147 -0
  40. data/lib/qbfc/terms.rb +10 -0
  41. data/lib/qbfc/terms/generated.rb +10 -0
  42. data/lib/qbfc/transaction.rb +110 -0
  43. data/lib/qbfc/transactions/generated.rb +25 -0
  44. data/lib/qbfc/voidable.rb +11 -0
  45. data/spec/fixtures/test.lgb +0 -0
  46. data/spec/fixtures/test.qbw +0 -0
  47. data/spec/fixtures/test.qbw.TLG +0 -0
  48. data/spec/integration/add_spec.rb +31 -0
  49. data/spec/integration/base_spec.rb +18 -0
  50. data/spec/integration/belongs_to_spec.rb +64 -0
  51. data/spec/integration/company_spec.rb +30 -0
  52. data/spec/integration/conditions_spec.rb +59 -0
  53. data/spec/integration/customer_spec.rb +46 -0
  54. data/spec/integration/element_finders_spec.rb +20 -0
  55. data/spec/integration/quick_test.rb +31 -0
  56. data/spec/integration/request_options_spec.rb +68 -0
  57. data/spec/rcov.opts +1 -0
  58. data/spec/spec.opts +6 -0
  59. data/spec/spec_helper.rb +62 -0
  60. data/spec/unit/base_spec.rb +138 -0
  61. data/spec/unit/element_finder_spec.rb +185 -0
  62. data/spec/unit/element_spec.rb +108 -0
  63. data/spec/unit/entities/generated_spec.rb +18 -0
  64. data/spec/unit/entity_spec.rb +18 -0
  65. data/spec/unit/info/generated_spec.rb +12 -0
  66. data/spec/unit/info_spec.rb +48 -0
  67. data/spec/unit/item_spec.rb +33 -0
  68. data/spec/unit/items/generated_spec.rb +16 -0
  69. data/spec/unit/list_finders_spec.rb +129 -0
  70. data/spec/unit/list_spec.rb +86 -0
  71. data/spec/unit/lists/account_spec.rb +20 -0
  72. data/spec/unit/lists/generated_spec.rb +15 -0
  73. data/spec/unit/lists/qb_class_spec.rb +9 -0
  74. data/spec/unit/modifiable_spec.rb +84 -0
  75. data/spec/unit/ole_wrapper_spec.rb +337 -0
  76. data/spec/unit/qb_collection_spec.rb +13 -0
  77. data/spec/unit/qbfc_const_spec.rb +10 -0
  78. data/spec/unit/qbfc_spec.rb +10 -0
  79. data/spec/unit/report_spec.rb +12 -0
  80. data/spec/unit/request_query_survey.txt +48 -0
  81. data/spec/unit/request_spec.rb +486 -0
  82. data/spec/unit/session_spec.rb +144 -0
  83. data/spec/unit/terms/generated_spec.rb +14 -0
  84. data/spec/unit/terms_spec.rb +18 -0
  85. data/spec/unit/transaction_finders_spec.rb +125 -0
  86. data/spec/unit/transaction_spec.rb +94 -0
  87. data/spec/unit/transactions/generated_spec.rb +20 -0
  88. data/spec/unit/voidable_spec.rb +32 -0
  89. data/tasks/qbfc_tasks.rake +4 -0
  90. data/uninstall.rb +1 -0
  91. metadata +180 -0
@@ -0,0 +1,129 @@
1
+ require 'spec_helper'
2
+
3
+ module QBFC::Test
4
+ class ListFind < QBFC::List
5
+ def self.qb_name
6
+ "Account"
7
+ end
8
+ end
9
+ end
10
+
11
+ describe QBFC::List do
12
+
13
+ before(:each) do
14
+ @sess = mock(QBFC::Session)
15
+ @ole_wrapper = mock(QBFC::OLEWrapper)
16
+ @list = QBFC::Test::List.new(@sess, @ole_wrapper)
17
+
18
+ # Request related mocks
19
+ @request = mock("QBFC::Request")
20
+ @request.stub!(:dup).and_return(@request)
21
+ @list_query = mock("QBFC::OLEWrapper#list_query")
22
+ @response = mock("QBFC::Request#response")
23
+
24
+ # Filter mock
25
+ @filter = mock("QBFC::OLEWrapper#Filter")
26
+ @request.stub!(:filter).and_return(@filter)
27
+ @request.stub!(:add_limit)
28
+ @request.stub!(:filter_available?).and_return(true)
29
+ @request.stub!(:apply_options)
30
+ end
31
+
32
+ def setup_request
33
+ QBFC::Request.should_receive(:new).with(@sess, 'AccountQuery').and_return(@request)
34
+ @request.should_receive(:kind_of?).with(QBFC::Request).and_return(true)
35
+ @request.stub!(:response).and_return(@response)
36
+ @response.stub!(:GetAt).with(0).and_return(@ole_wrapper)
37
+ @response.stub!(:ole_methods).and_return(["GetAt"])
38
+ end
39
+
40
+ describe ".find_by_name" do
41
+ before(:each) do
42
+ @full_name_list = mock("QBFC::OLEWrapper#full_name_list")
43
+ end
44
+
45
+ def setup_request
46
+ super
47
+ @request.should_receive(:query).and_return(@list_query)
48
+ @list_query.should_receive(:FullNameList).and_return(@full_name_list)
49
+ @full_name_list.should_receive(:Add).with("Bob Customer")
50
+ end
51
+
52
+ it "should set up Request, specifying FullNameList" do
53
+ setup_request
54
+ QBFC::Test::ListFind.find_by_name(@sess, "Bob Customer")
55
+ end
56
+
57
+ it "should return a List object" do
58
+ setup_request
59
+ list = QBFC::Test::ListFind.find_by_name(@sess, "Bob Customer")
60
+ list.should be_kind_of(QBFC::Test::ListFind)
61
+ end
62
+
63
+ it "should return nil if none found" do
64
+ setup_request
65
+ @request.should_receive(:response).and_return(nil)
66
+ QBFC::Test::ListFind.find_by_name(@sess, "Bob Customer").should be_nil
67
+ end
68
+
69
+ it "should alias as find_by_full_name" do
70
+ setup_request
71
+ QBFC::Test::ListFind.find_by_full_name(@sess, "Bob Customer")
72
+ end
73
+ end
74
+
75
+ describe ".find_by_id" do
76
+ before(:each) do
77
+ @list_id_list = mock("QBFC::OLEWrapper#list_id_list")
78
+ end
79
+
80
+ def setup_request
81
+ super
82
+ @request.should_receive(:query).and_return(@list_query)
83
+ @list_query.should_receive(:ListIDList).and_return(@list_id_list)
84
+ @list_id_list.should_receive(:Add).with("123-456")
85
+ end
86
+
87
+ it "should set up Request, specifying ListIDList" do
88
+ setup_request
89
+ QBFC::Test::ListFind.find_by_id(@sess, "123-456")
90
+ end
91
+
92
+ it "should return a List object" do
93
+ setup_request
94
+ list = QBFC::Test::ListFind.find_by_id(@sess, "123-456")
95
+ list.should be_kind_of(QBFC::Test::ListFind)
96
+ end
97
+
98
+ it "should return nil if none found" do
99
+ setup_request
100
+ @request.should_receive(:response).and_return(nil)
101
+ QBFC::Test::ListFind.find_by_id(@sess, "123-456").should be_nil
102
+ end
103
+ end
104
+
105
+ describe ".find_by_name_or_id" do
106
+ it "should try to find_by_id" do
107
+ QBFC::Test::ListFind.should_receive(:find_by_id).with(@sess, "123-456").and_return("List By ID")
108
+ QBFC::Test::ListFind.find_by_name_or_id(@sess, "123-456").should == "List By ID"
109
+ end
110
+
111
+ it "should try to find_by_name if id fails" do
112
+ QBFC::Test::ListFind.should_receive(:find_by_id).with(@sess, "123-456").and_return(nil)
113
+ QBFC::Test::ListFind.should_receive(:find_by_name).with(@sess, "123-456").and_return("List By Name")
114
+ QBFC::Test::ListFind.find_by_name_or_id(@sess, "123-456").should == "List By Name"
115
+ end
116
+
117
+ it "should return nil if both name and id return nil" do
118
+ QBFC::Test::ListFind.should_receive(:find_by_id).with(@sess, "123-456").and_return(nil)
119
+ QBFC::Test::ListFind.should_receive(:find_by_name).with(@sess, "123-456").and_return(nil)
120
+ QBFC::Test::ListFind.find_by_name_or_id(@sess, "123-456").should be_nil
121
+ end
122
+
123
+ it "should be aliased as .find_by_unique_id" do
124
+ QBFC::Test::ListFind.should_receive(:find_by_id).with(@sess, "123-456").and_return(nil)
125
+ QBFC::Test::ListFind.should_receive(:find_by_name).with(@sess, "123-456").and_return(nil)
126
+ QBFC::Test::ListFind.find_by_unique_id(@sess, "123-456").should be_nil
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,86 @@
1
+ require 'spec_helper'
2
+
3
+ module QBFC::Test
4
+ class List < QBFC::List
5
+ def self.qb_name
6
+ "Account"
7
+ end
8
+ end
9
+ end
10
+
11
+ describe QBFC::List do
12
+
13
+ before(:each) do
14
+ @sess = mock(QBFC::Session)
15
+ @ole_wrapper = mock(QBFC::OLEWrapper)
16
+ @list = QBFC::Test::List.new(@sess, @ole_wrapper)
17
+ end
18
+
19
+ it "should specify if it is a superclass_list (such as Entity)"
20
+
21
+ describe "::ID_NAME" do
22
+ it "should be 'ListID'" do
23
+ QBFC::Test::List::ID_NAME.should == "ListID"
24
+ end
25
+ end
26
+
27
+ describe "#id" do
28
+ it "is an alias of list_id" do
29
+ @ole_wrapper.should_receive(:list_id).and_return('L123')
30
+ @list.id.should == 'L123'
31
+ end
32
+ end
33
+
34
+ describe "#full_name" do
35
+ before(:each) do
36
+ @ole_wrapper.stub!(:full_name).and_return("Full Name")
37
+ @ole_wrapper.stub!(:name).and_return("Short Name")
38
+ end
39
+
40
+ it "aliases name if not defined by OLE object" do
41
+ @ole_wrapper.should_receive(:respond_to_ole?).with("FullName").and_return(false)
42
+ @list.full_name.should == "Short Name"
43
+ end
44
+
45
+ it "calls OLE object's FullName method if defined" do
46
+ @ole_wrapper.should_receive(:respond_to_ole?).with("FullName").and_return(true)
47
+ @list.full_name.should == "Full Name"
48
+ end
49
+ end
50
+
51
+ describe "#delete" do
52
+ it "should setup a ListDelRq with List Type and ID" do
53
+ @del_rq = mock(QBFC::Request)
54
+ @ole_wrapper.should_receive(:list_id).and_return('{123-456}')
55
+ QBFC::Request.should_receive(:new).with(@sess, "ListDel").and_return(@del_rq)
56
+ @del_rq.should_receive(:list_del_type=).with(QBFC_CONST::const_get("LdtAccount"))
57
+ @del_rq.should_receive(:list_id=).with("{123-456}")
58
+ @del_rq.should_receive(:submit)
59
+ @list.delete.should be_true
60
+ end
61
+ end
62
+
63
+ describe "#display" do
64
+ before(:each) do
65
+ @display_rq = mock(QBFC::Request)
66
+ end
67
+
68
+ it "should call ListDisplayAdd for new records" do
69
+ QBFC::Request.should_receive(:new).with(@sess, "ListDisplayAdd").and_return(@display_rq)
70
+ @display_rq.should_receive(:list_display_add_type=).with(QBFC_CONST::LdatAccount)
71
+ @display_rq.should_receive(:submit)
72
+ @list.instance_variable_set(:@new_record, true)
73
+ @list.display
74
+ end
75
+
76
+ it "should call ListDisplayMod for existing records" do
77
+ @ole_wrapper.should_receive(:list_id).and_return('123-456')
78
+
79
+ QBFC::Request.should_receive(:new).with(@sess, "ListDisplayMod").and_return(@display_rq)
80
+ @display_rq.should_receive(:list_display_mod_type=).with(QBFC_CONST::LdatAccount)
81
+ @display_rq.should_receive(:list_id=).with('123-456')
82
+ @display_rq.should_receive(:submit)
83
+ @list.display
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe QBFC::Account do
4
+
5
+ before(:each) do
6
+ @sess = mock(QBFC::Session)
7
+ @request = mock("QBFC::Request")
8
+ @response = mock("QBFC::Request#response")
9
+ end
10
+
11
+ it "should add a Special Account" do
12
+ QBFC::Request.should_receive(:new).with(@sess, "SpecialAccountAdd").and_return(@request)
13
+ @request.should_receive(:special_account_type=).with(QBFC_CONST::SatAccountsReceivable)
14
+ @request.should_receive(:response).and_return(@response)
15
+ QBFC::Account.should_receive(:new).with(@sess, @response)
16
+
17
+ QBFC::Account.add_special(@sess, QBFC_CONST::SatAccountsReceivable)
18
+ end
19
+
20
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe "QBFC::List generated.rb" do
4
+
5
+ it "should generate classes" do
6
+ QBFC::Customer.ancestors.should include(QBFC::List)
7
+ QBFC::Account.ancestors.should include(QBFC::List)
8
+ QBFC::Account.superclass.should be(QBFC::List)
9
+ end
10
+
11
+ it "should include Modifiable in modifiable classes" do
12
+ QBFC::Customer.included_modules.should include(QBFC::Modifiable)
13
+ QBFC::CustomerMsg.included_modules.should_not include(QBFC::Modifiable)
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe QBFC::QBClass do
4
+
5
+ it "should access QBFC 'Class' elements" do
6
+ QBFC::QBClass.qb_name.should == "Class"
7
+ end
8
+
9
+ end
@@ -0,0 +1,84 @@
1
+ require 'spec_helper'
2
+
3
+ module QBFC::Test
4
+ class ListMod < QBFC::List
5
+ include QBFC::Modifiable
6
+
7
+ def self.qb_name
8
+ "Account"
9
+ end
10
+ end
11
+
12
+ class TxnMod < QBFC::Transaction
13
+ include QBFC::Modifiable
14
+
15
+ def self.qb_name
16
+ "Check"
17
+ end
18
+ end
19
+ end
20
+
21
+ describe 'QBFC::Modifiable' do
22
+
23
+ before(:each) do
24
+ @sess = mock(QBFC::Session)
25
+ @ole_wrapper = mock(QBFC::OLEWrapper)
26
+ @ole_wrapper.stub!(:list_id).and_return "{list-id}"
27
+ @ole_wrapper.stub!(:txn_id).and_return "{txn-id}"
28
+ @ole_wrapper.stub!(:edit_sequence).and_return "123"
29
+ @ole_wrapper.stub!(:setter=)
30
+
31
+ @mod_rq = mock(QBFC::Request)
32
+ @mod_ole = mock(WIN32OLE)
33
+ @mod_rq.should_receive(:ole_object).and_return(@mod_ole)
34
+ @mod_rq.stub!(:list_id=)
35
+ @mod_rq.stub!(:txn_id=)
36
+ @mod_rq.stub!(:edit_sequence=)
37
+ QBFC::Request.stub!(:new).and_return(@mod_rq)
38
+ end
39
+
40
+ describe "#initialize" do
41
+ it "should setup Mod Request for existing records" do
42
+ QBFC::Request.should_receive(:new).with(@sess, "AccountMod").and_return(@mod_rq)
43
+ QBFC::Test::ListMod.new(@sess, @ole_wrapper)
44
+ end
45
+
46
+ it "should not set Mod Request for new records" do
47
+ QBFC::Request.should_not_receive(:new).with(@sess, "AccountMod")
48
+ QBFC::Test::ListMod.new(@sess)
49
+ end
50
+ end
51
+
52
+ describe "#setup_mod_request" do
53
+
54
+ it "should create a Mod Request object" do
55
+ QBFC::Request.should_receive(:new).with(@sess, "AccountMod").and_return(@mod_rq)
56
+ QBFC::Test::ListMod.new(@sess, @ole_wrapper)
57
+ end
58
+
59
+ it "should set the Mod's id (for Lists) to the ole_object's id" do
60
+ @mod_rq.should_receive(:list_id=).with("{list-id}")
61
+ QBFC::Test::ListMod.new(@sess, @ole_wrapper)
62
+ end
63
+
64
+ it "should set the Mod's txn_id (for Transaction) to the ole_object's id" do
65
+ @mod_rq.should_receive(:txn_id=).with("{txn-id}")
66
+ QBFC::Test::TxnMod.new(@sess, @ole_wrapper)
67
+ end
68
+
69
+ it "should set the Mod's edit_sequence" do
70
+ @mod_rq.should_receive(:edit_sequence=).with("123")
71
+ QBFC::Test::TxnMod.new(@sess, @ole_wrapper)
72
+ end
73
+
74
+ it "should add the Mod request's ole_object as the @ole.setter" do
75
+ @ole_wrapper.should_receive(:setter=).with(@mod_ole)
76
+ QBFC::Test::TxnMod.new(@sess, @ole_wrapper)
77
+ end
78
+
79
+ it "should assign the Mod request as the @setter" do
80
+ txn = QBFC::Test::TxnMod.new(@sess, @ole_wrapper)
81
+ txn.instance_variable_get(:@setter).should be(@mod_rq)
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,337 @@
1
+ require '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', 'ColDataList', 'ORReportDataList', 'colID'])
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 convert Dates in setter method" do
145
+ @ole_object.should_receive(:TimeModified).and_return(@full_name)
146
+ @full_name.should_receive(:SetValue).with('2008-01-01')
147
+
148
+ @wrapper.qbfc_method_missing(@sess, :time_modified=, Date.parse('2008-01-01'))
149
+ end
150
+
151
+ it "should set @setter also when acting as a setter method, if applicable" do
152
+ @setter = mock(WIN32OLE)
153
+ @setter.should_receive("ole_methods").and_return(["FullName", "ListID"])
154
+ @wrapper = QBFC::OLEWrapper.new(@ole_object, @setter)
155
+
156
+ @full_name_setter = WIN32OLE.new("QBFC6.QBSessionManager")
157
+ @setter.should_receive(:FullName).and_return(@full_name_setter)
158
+ @full_name.should_receive(:SetValue).with('Full Name')
159
+ @full_name_setter.should_receive(:SetValue).with('Full Name')
160
+
161
+ @wrapper.qbfc_method_missing(@sess, :full_name=, 'Full Name')
162
+ end
163
+
164
+ it "should convert 'Id' to 'ID' in setter" do
165
+ @ole_object.should_receive(:ListID).and_return(@full_name)
166
+ @full_name.should_receive(:SetValue).and_return('{123-456}')
167
+
168
+ @wrapper.qbfc_method_missing(@sess, :list_id=, '{123-456}')
169
+ end
170
+
171
+ it "should raise SetValueMissing error on a setter call for a method without SetValue" do
172
+ @ole_object.should_receive(:FullName).and_return(@full_name)
173
+ @full_name.should_receive(:ole_methods).and_return(['GetValue'])
174
+
175
+ lambda { @wrapper.qbfc_method_missing(@sess, :full_name=, 'Full Name') }.
176
+ should raise_error(QBFC::SetValueMissing)
177
+ end
178
+
179
+ it "should wrap *RetList objects in an Array" do
180
+ ret_list = mock('WIN32OLE.RetList')
181
+ ret_list.stub!(:ole_methods).and_return(['GetAt', 'Count'])
182
+ ret_list.should_receive(:Count).and_return(2)
183
+ ret_list.should_receive(:GetAt).with(0).and_return(@full_name)
184
+ ret_list.should_receive(:GetAt).with(1).and_return(@full_name)
185
+
186
+ @ole_object.should_receive(:LineRetList).and_return(ret_list)
187
+
188
+ @full_name_wrapper = QBFC::OLEWrapper.new(@full_name)
189
+ QBFC::OLEWrapper.should_receive(:new).with(@full_name).twice.and_return(@full_name_wrapper)
190
+
191
+ @wrapper.qbfc_method_missing(@sess, :lines).should ==
192
+ [@full_name_wrapper, @full_name_wrapper]
193
+ end
194
+
195
+ it "should wrap OR*RetList objects in an Array" do
196
+ ret_list = mock('WIN32OLE.ORInvoiceLineRetList')
197
+ list_item_wrapper = mock('WIN32OLE.InvoiceLineRetWrapper')
198
+ list_item = mock('WIN32OLE.InvoiceLineRet')
199
+ ret_list.stub!(:ole_methods).and_return(['GetAt', 'Count'])
200
+ ret_list.should_receive(:Count).and_return(2)
201
+ ret_list.should_receive(:GetAt).with(0).and_return(list_item_wrapper)
202
+ ret_list.should_receive(:GetAt).with(1).and_return(list_item_wrapper)
203
+ list_item_wrapper.should_receive(:InvoiceLineRet).twice.and_return(list_item)
204
+
205
+ @ole_object.should_receive(:ORInvoiceLineRetList).and_return(ret_list)
206
+
207
+ @wrapper.qbfc_method_missing(@sess, :invoice_lines).should ==
208
+ [list_item, list_item]
209
+ end
210
+
211
+ it "should wrap *List objects in an Array" do
212
+ ret_list = mock('WIN32OLE.List')
213
+ ret_list.stub!(:ole_methods).and_return(['GetAt', 'Count'])
214
+ ret_list.should_receive(:Count).and_return(2)
215
+ ret_list.should_receive(:GetAt).with(0).and_return(@full_name)
216
+ ret_list.should_receive(:GetAt).with(1).and_return(@full_name)
217
+
218
+ @ole_object.should_receive(:ColDataList).and_return(ret_list)
219
+
220
+ @full_name_wrapper = QBFC::OLEWrapper.new(@full_name)
221
+ QBFC::OLEWrapper.should_receive(:new).with(@full_name).twice.and_return(@full_name_wrapper)
222
+
223
+ @wrapper.qbfc_method_missing(@sess, :col_datas).should ==
224
+ [@full_name_wrapper, @full_name_wrapper]
225
+ end
226
+
227
+ it "should wrap OR*List objects in an Array" do
228
+ ret_list = mock('WIN32OLE.ORInvoiceLineList')
229
+ list_item_wrapper = mock('WIN32OLE.InvoiceLineWrapper')
230
+ list_item = mock('WIN32OLE.InvoiceLine')
231
+ ret_list.stub!(:ole_methods).and_return(['GetAt', 'Count'])
232
+ ret_list.should_receive(:Count).and_return(2)
233
+ ret_list.should_receive(:GetAt).with(0).and_return(list_item_wrapper)
234
+ ret_list.should_receive(:GetAt).with(1).and_return(list_item_wrapper)
235
+ list_item_wrapper.should_receive(:ReportData).twice.and_return(list_item)
236
+
237
+ @ole_object.should_receive(:ORReportDataList).and_return(ret_list)
238
+
239
+ @wrapper.qbfc_method_missing(@sess, :report_datas).should ==
240
+ [list_item, list_item]
241
+ end
242
+
243
+ it "should call a lower-case method defined by QBFC" do
244
+ @ole_object.should_receive(:colID).and_return('Id')
245
+ @wrapper.qbfc_method_missing(@sess, :colID).should == 'Id'
246
+ end
247
+
248
+ it "should have *_full_name for *Ref" do
249
+ ref = mock('WIN32OLE.PayeeRef')
250
+ @ole_object.should_receive(:AccountRef).and_return(ref)
251
+
252
+ full_name = "Full Name"
253
+ full_name_obj = mock('WIN32OLE.FullName')
254
+ ref.should_receive(:FullName).and_return(full_name_obj)
255
+ full_name_obj.should_receive(:GetValue).and_return(full_name)
256
+
257
+ @wrapper.qbfc_method_missing(@sess, :account_full_name).should == full_name
258
+ end
259
+
260
+ it "should have *_id for *Ref" do
261
+ ref = mock('WIN32OLE.PayeeRef')
262
+ @ole_object.should_receive(:AccountRef).and_return(ref)
263
+
264
+ list_id = "1"
265
+ list_id_obj = mock('WIN32OLE.ListID')
266
+ ref.should_receive(:ListID).and_return(list_id_obj)
267
+ list_id_obj.should_receive(:GetValue).and_return(list_id)
268
+
269
+ @wrapper.qbfc_method_missing(@sess, :account_id).should == list_id
270
+ end
271
+
272
+ it "should have *_full_name for *EntityRef" do
273
+ ref = mock('WIN32OLE.PayeeEntityRef')
274
+ @ole_object.should_receive(:PayeeEntityRef).and_return(ref)
275
+
276
+ full_name = "Full Name"
277
+ full_name_obj = mock('WIN32OLE.FullName')
278
+ ref.should_receive(:FullName).and_return(full_name_obj)
279
+ full_name_obj.should_receive(:GetValue).and_return(full_name)
280
+
281
+ @wrapper.qbfc_method_missing(@sess, :payee_full_name).should == full_name
282
+ end
283
+
284
+ it "should have *_id for *EntityRef" do
285
+ ref = mock('WIN32OLE.PayeeEntityRef')
286
+ @ole_object.should_receive(:PayeeEntityRef).and_return(ref)
287
+
288
+ list_id = "1"
289
+ list_id_obj = mock('WIN32OLE.ListID')
290
+ ref.should_receive(:ListID).and_return(list_id_obj)
291
+ list_id_obj.should_receive(:GetValue).and_return(list_id)
292
+
293
+ @wrapper.qbfc_method_missing(@sess, :payee_id).should == list_id
294
+ end
295
+
296
+ it "should create a Base-inherited object from a *EntityRef" do
297
+ entity_ref = mock('WIN32OLE.PayeeEntityRef')
298
+ @ole_object.should_receive(:PayeeEntityRef).and_return(entity_ref)
299
+
300
+ list_id = "1"
301
+ list_id_obj = mock('WIN32OLE.ListID')
302
+ entity_ref.should_receive(:ListID).and_return(list_id_obj)
303
+ list_id_obj.should_receive(:GetValue).and_return(list_id)
304
+
305
+ entity = mock(QBFC::Entity)
306
+
307
+ QBFC::Entity.should_receive(:find_by_id).with(@sess, list_id).and_return(entity)
308
+
309
+ @wrapper.qbfc_method_missing(@sess, :payee).should == entity
310
+ end
311
+
312
+ it "should return nil for a *Ref if the ole_method calling *Ref returns nil" do
313
+ @ole_object.should_receive(:PayeeEntityRef).and_return(nil)
314
+ @wrapper.qbfc_method_missing(@sess, :payee).should be_nil
315
+ end
316
+
317
+ it "should create a Base-inherited object from a *Ref" do
318
+ account_ref = mock('WIN32OLE.AccountRef')
319
+ @ole_object.should_receive(:AccountRef).and_return(account_ref)
320
+
321
+ list_id = "1"
322
+ list_id_obj = mock('WIN32OLE.ListID')
323
+ account_ref.should_receive(:ListID).and_return(list_id_obj)
324
+ list_id_obj.should_receive(:GetValue).and_return(list_id)
325
+
326
+ account = mock(QBFC::Account)
327
+
328
+ QBFC::Account.should_receive(:find_by_id).with(@sess, list_id).and_return(account)
329
+
330
+ @wrapper.qbfc_method_missing(@sess, :account).should == account
331
+ end
332
+
333
+ it "should raise NoMethodError if none of the above apply" do
334
+ lambda { @wrapper.qbfc_method_missing(@sess, :no_method) }.should raise_error(NoMethodError, 'no_method')
335
+ end
336
+ end
337
+ end