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,18 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe "QBFC::Entity generated.rb" do
4
+
5
+ it "should generate classes" do
6
+ QBFC::Customer.superclass.should be(QBFC::Entity)
7
+ QBFC::Vendor.superclass.should be(QBFC::Entity)
8
+ QBFC::OtherName.superclass.should be(QBFC::Entity)
9
+ QBFC::Employee.superclass.should be(QBFC::Entity)
10
+ end
11
+
12
+ it "should include Modifiable in all classes" do
13
+ QBFC::Customer.included_modules.should include(QBFC::Modifiable)
14
+ QBFC::Vendor.included_modules.should include(QBFC::Modifiable)
15
+ QBFC::OtherName.included_modules.should include(QBFC::Modifiable)
16
+ QBFC::Employee.included_modules.should include(QBFC::Modifiable)
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe QBFC::Entity do
4
+
5
+ before(:each) do
6
+ @sess = mock(QBFC::Session)
7
+ @ole_wrapper = mock(QBFC::OLEWrapper)
8
+ end
9
+
10
+ it "is a base class" do
11
+ QBFC::Entity.is_base_class?.should be_true
12
+ end
13
+
14
+ describe ".find" do
15
+ it "should return subclass objects"
16
+ end
17
+
18
+ end
@@ -0,0 +1,12 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe "QBFC::Info generated.rb" do
4
+
5
+ it "should generate classes" do
6
+ QBFC::Company.superclass.should be(QBFC::Info)
7
+ QBFC::CompanyActivity.superclass.should be(QBFC::Info)
8
+ QBFC::Host.superclass.should be(QBFC::Info)
9
+ QBFC::Preferences.superclass.should be(QBFC::Info)
10
+ end
11
+
12
+ end
@@ -0,0 +1,48 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ module QBFC::Test
4
+ class Info < QBFC::Info
5
+ def self.qb_name
6
+ "Company"
7
+ end
8
+ end
9
+ end
10
+
11
+ describe QBFC::Info do
12
+
13
+ before(:each) do
14
+ @sess = mock(QBFC::Session)
15
+ @ole_wrapper = mock(QBFC::OLEWrapper)
16
+ @info = mock(QBFC::Test::Info)
17
+
18
+ # Request related mocks
19
+ @request = mock("QBFC::Request")
20
+ @response = mock("QBFC::Request#response")
21
+
22
+ QBFC::Request.stub!(:new).with(@sess, 'CompanyQuery').and_return(@request)
23
+ @request.stub!(:response).and_return(@response)
24
+ QBFC::Test::Info.stub!(:new).with(@sess, @response).and_return(@info)
25
+ @request.stub!(:apply_options)
26
+ end
27
+
28
+ describe ".get" do
29
+ it "should create Request and get response" do
30
+ QBFC::Request.should_receive(:new).with(@sess, 'CompanyQuery').and_return(@request)
31
+ @request.should_receive(:response).and_return(@response)
32
+ QBFC::Test::Info.should_receive(:new).with(@sess, @response).and_return(@info)
33
+ QBFC::Test::Info::get(@sess)
34
+ end
35
+
36
+ it "applies options to Request" do
37
+ @request.should_receive(:apply_options).with({:owner_id => 0})
38
+ QBFC::Test::Info::get(@sess, :owner_id => 0)
39
+ end
40
+ end
41
+
42
+ describe ".find" do
43
+ it "should forward request, without 'what' argument, to get" do
44
+ QBFC::Test::Info.should_receive(:get).with(@sess, {})
45
+ QBFC::Test::Info::find(@sess, :first, {})
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,18 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe QBFC::Item do
4
+
5
+ before(:each) do
6
+ @sess = mock(QBFC::Session)
7
+ @ole_wrapper = mock(QBFC::OLEWrapper)
8
+ end
9
+
10
+ it "is a base class" do
11
+ QBFC::Item.is_base_class?.should be_true
12
+ end
13
+
14
+ describe ".find" do
15
+ it "should return subclass objects"
16
+ end
17
+
18
+ end
@@ -0,0 +1,16 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe "QBFC::Item generated.rb" do
4
+
5
+ it "should generate classes" do
6
+ QBFC::ItemGroup.superclass.should be(QBFC::Item)
7
+ QBFC::ItemDiscount.superclass.should be(QBFC::Item)
8
+ QBFC::ItemPayment.superclass.should be(QBFC::Item)
9
+ end
10
+
11
+ it "should include Modifiable in all classes" do
12
+ QBFC::ItemGroup.included_modules.should include(QBFC::Modifiable)
13
+ QBFC::ItemDiscount.included_modules.should include(QBFC::Modifiable)
14
+ QBFC::ItemPayment.included_modules.should include(QBFC::Modifiable)
15
+ end
16
+ end
@@ -0,0 +1,128 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../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
+ @list_query = mock("QBFC::OLEWrapper#list_query")
21
+ @response = mock("QBFC::Request#response")
22
+
23
+ # Filter mock
24
+ @filter = mock("QBFC::OLEWrapper#Filter")
25
+ @request.stub!(:filter).and_return(@filter)
26
+ @filter.stub!(:max_returned=)
27
+ @request.stub!(:filter_available?).and_return(true)
28
+ @request.stub!(:apply_options)
29
+ end
30
+
31
+ def setup_request
32
+ QBFC::Request.should_receive(:new).with(@sess, 'AccountQuery').and_return(@request)
33
+ @request.should_receive(:kind_of?).with(QBFC::Request).and_return(true)
34
+ @request.stub!(:response).and_return(@response)
35
+ @response.stub!(:GetAt).with(0).and_return(@ole_wrapper)
36
+ @response.stub!(:ole_methods).and_return(["GetAt"])
37
+ end
38
+
39
+ describe ".find_by_name" do
40
+ before(:each) do
41
+ @full_name_list = mock("QBFC::OLEWrapper#full_name_list")
42
+ end
43
+
44
+ def setup_request
45
+ super
46
+ @request.should_receive(:query).and_return(@list_query)
47
+ @list_query.should_receive(:FullNameList).and_return(@full_name_list)
48
+ @full_name_list.should_receive(:Add).with("Bob Customer")
49
+ end
50
+
51
+ it "should set up Request, specifying FullNameList" do
52
+ setup_request
53
+ QBFC::Test::ListFind.find_by_name(@sess, "Bob Customer")
54
+ end
55
+
56
+ it "should return a List object" do
57
+ setup_request
58
+ list = QBFC::Test::ListFind.find_by_name(@sess, "Bob Customer")
59
+ list.should be_kind_of(QBFC::Test::ListFind)
60
+ end
61
+
62
+ it "should return nil if none found" do
63
+ setup_request
64
+ @request.should_receive(:response).and_return(nil)
65
+ QBFC::Test::ListFind.find_by_name(@sess, "Bob Customer").should be_nil
66
+ end
67
+
68
+ it "should alias as find_by_full_name" do
69
+ setup_request
70
+ QBFC::Test::ListFind.find_by_full_name(@sess, "Bob Customer")
71
+ end
72
+ end
73
+
74
+ describe ".find_by_id" do
75
+ before(:each) do
76
+ @list_id_list = mock("QBFC::OLEWrapper#list_id_list")
77
+ end
78
+
79
+ def setup_request
80
+ super
81
+ @request.should_receive(:query).and_return(@list_query)
82
+ @list_query.should_receive(:ListIDList).and_return(@list_id_list)
83
+ @list_id_list.should_receive(:Add).with("123-456")
84
+ end
85
+
86
+ it "should set up Request, specifying ListIDList" do
87
+ setup_request
88
+ QBFC::Test::ListFind.find_by_id(@sess, "123-456")
89
+ end
90
+
91
+ it "should return a List object" do
92
+ setup_request
93
+ list = QBFC::Test::ListFind.find_by_id(@sess, "123-456")
94
+ list.should be_kind_of(QBFC::Test::ListFind)
95
+ end
96
+
97
+ it "should return nil if none found" do
98
+ setup_request
99
+ @request.should_receive(:response).and_return(nil)
100
+ QBFC::Test::ListFind.find_by_id(@sess, "123-456").should be_nil
101
+ end
102
+ end
103
+
104
+ describe ".find_by_name_or_id" do
105
+ it "should try to find_by_id" do
106
+ QBFC::Test::ListFind.should_receive(:find_by_id).with(@sess, "123-456").and_return("List By ID")
107
+ QBFC::Test::ListFind.find_by_name_or_id(@sess, "123-456").should == "List By ID"
108
+ end
109
+
110
+ it "should try to find_by_name if id fails" do
111
+ QBFC::Test::ListFind.should_receive(:find_by_id).with(@sess, "123-456").and_return(nil)
112
+ QBFC::Test::ListFind.should_receive(:find_by_name).with(@sess, "123-456").and_return("List By Name")
113
+ QBFC::Test::ListFind.find_by_name_or_id(@sess, "123-456").should == "List By Name"
114
+ end
115
+
116
+ it "should return nil if both name and id return nil" do
117
+ QBFC::Test::ListFind.should_receive(:find_by_id).with(@sess, "123-456").and_return(nil)
118
+ QBFC::Test::ListFind.should_receive(:find_by_name).with(@sess, "123-456").and_return(nil)
119
+ QBFC::Test::ListFind.find_by_name_or_id(@sess, "123-456").should be_nil
120
+ end
121
+
122
+ it "should be aliased as .find_by_unique_id" do
123
+ QBFC::Test::ListFind.should_receive(:find_by_id).with(@sess, "123-456").and_return(nil)
124
+ QBFC::Test::ListFind.should_receive(:find_by_name).with(@sess, "123-456").and_return(nil)
125
+ QBFC::Test::ListFind.find_by_unique_id(@sess, "123-456").should be_nil
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,86 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../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,15 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../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 File.expand_path(File.dirname(__FILE__) + '/../../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 File.expand_path(File.dirname(__FILE__) + '/../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