rhodes-framework 1.0.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 (67) hide show
  1. data/.gitignore +2 -0
  2. data/History.txt +37 -0
  3. data/Manifest.txt +66 -0
  4. data/README.rdoc +2 -0
  5. data/Rakefile +50 -0
  6. data/lib/ServeME.rb +7 -0
  7. data/lib/TestServe.rb +9 -0
  8. data/lib/bsearch.rb +120 -0
  9. data/lib/builtinME.rb +626 -0
  10. data/lib/date/format.rb +1339 -0
  11. data/lib/date.rb +1792 -0
  12. data/lib/dateME.rb +24 -0
  13. data/lib/erb.rb +896 -0
  14. data/lib/find.rb +81 -0
  15. data/lib/rational.rb +19 -0
  16. data/lib/rationalME.rb +530 -0
  17. data/lib/rho/render.rb +51 -0
  18. data/lib/rho/rho.rb +255 -0
  19. data/lib/rho/rhoapplication.rb +36 -0
  20. data/lib/rho/rhocontact.rb +110 -0
  21. data/lib/rho/rhocontroller.rb +35 -0
  22. data/lib/rho/rhofsconnector.rb +32 -0
  23. data/lib/rho/rhosupport.rb +146 -0
  24. data/lib/rho/rhoviewhelpers.rb +130 -0
  25. data/lib/rho.rb +1 -0
  26. data/lib/rhodes-framework.rb +2 -0
  27. data/lib/rhodes.rb +9 -0
  28. data/lib/rhoframework.rb +38 -0
  29. data/lib/rhofsconnector.rb +1 -0
  30. data/lib/rhom/rhom.rb +58 -0
  31. data/lib/rhom/rhom_db_adapter.rb +185 -0
  32. data/lib/rhom/rhom_db_adapterME.rb +93 -0
  33. data/lib/rhom/rhom_object.rb +69 -0
  34. data/lib/rhom/rhom_object_factory.rb +309 -0
  35. data/lib/rhom/rhom_source.rb +60 -0
  36. data/lib/rhom.rb +1 -0
  37. data/lib/singleton.rb +137 -0
  38. data/lib/time.rb +489 -0
  39. data/lib/version.rb +8 -0
  40. data/res/sqlite3/constants.rb +49 -0
  41. data/res/sqlite3/database.rb +715 -0
  42. data/res/sqlite3/driver/dl/api.rb +154 -0
  43. data/res/sqlite3/driver/dl/driver.rb +307 -0
  44. data/res/sqlite3/driver/native/driver.rb +257 -0
  45. data/res/sqlite3/errors.rb +68 -0
  46. data/res/sqlite3/pragmas.rb +271 -0
  47. data/res/sqlite3/resultset.rb +176 -0
  48. data/res/sqlite3/sqlite3_api.rb +0 -0
  49. data/res/sqlite3/statement.rb +230 -0
  50. data/res/sqlite3/translator.rb +109 -0
  51. data/res/sqlite3/value.rb +57 -0
  52. data/res/sqlite3/version.rb +14 -0
  53. data/rhodes-framework.gemspec +18 -0
  54. data/rhodes.gemspec +18 -0
  55. data/spec/app_manifest.txt +4 -0
  56. data/spec/configs/account.rb +3 -0
  57. data/spec/configs/case.rb +3 -0
  58. data/spec/configs/employee.rb +3 -0
  59. data/spec/rho_controller_spec.rb +144 -0
  60. data/spec/rho_spec.rb +75 -0
  61. data/spec/rhom_object_factory_spec.rb +372 -0
  62. data/spec/rhom_spec.rb +45 -0
  63. data/spec/spec.opts +1 -0
  64. data/spec/spec_helper.rb +49 -0
  65. data/spec/stubs.rb +39 -0
  66. data/spec/syncdbtest.sqlite +0 -0
  67. metadata +202 -0
@@ -0,0 +1,144 @@
1
+ #
2
+ # rho_controller_spec.rb
3
+ # rhodes
4
+ #
5
+ # Copyright (C) 2008 Rhomobile, Inc. All rights reserved.
6
+ #
7
+ # This program is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # This program is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
+ #
20
+ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
21
+ require File.dirname(__FILE__) + "/spec_helper"
22
+ require 'rho/rhocontroller'
23
+
24
+ describe "Rho" do
25
+
26
+ it_should_behave_like "rho initializer"
27
+
28
+ describe "url_for and link_to" do
29
+
30
+ before(:each) do
31
+ @c = Rho::RhoController.new
32
+ @c.stub!(:send).and_return(nil)
33
+ @c.serve(nil,{'application' => 'application', 'model' => 'model'},{})
34
+ end
35
+
36
+ it "should generate urls for empty params" do
37
+ @c.url_for().should == '/application/model'
38
+ end
39
+
40
+ it "should generate urls for a url" do
41
+ @c.url_for('/some_url').should == '/some_url'
42
+ end
43
+
44
+ it "should generate urls for a symbol" do
45
+ @c.url_for(:new).should == 'new'
46
+ end
47
+
48
+ it "should generate urls for an action" do
49
+ @c.url_for(:action => :new).should == '/application/model/new'
50
+ end
51
+
52
+ it "should generate urls for an action and id" do
53
+ @c.url_for(:action => :show, :id => '{12}').should == '/application/model/{12}/show'
54
+ end
55
+
56
+ it "should generate urls for create or index actions" do
57
+ @c.url_for(:action => :index, :id => '{12}').should == '/application/model'
58
+ @c.url_for(:action => :create).should == '/application/model'
59
+ end
60
+
61
+ it "should generate urls for an model, action, and id" do
62
+ @c.url_for(:model => 'another_model', :action => :show, :id => '{12}').should == '/application/another_model/{12}/show'
63
+ @c.url_for(:model => :another_model, :action => :show, :id => '{12}').should == '/application/another_model/{12}/show'
64
+ end
65
+
66
+ it "should generate urls for an controller, action, and id" do
67
+ @c.url_for(:controller => 'another_controller', :action => :show, :id => '{12}').should == '/application/another_controller/{12}/show'
68
+ @c.url_for(:controller => :another_controller, :action => :show, :id => '{12}').should == '/application/another_controller/{12}/show'
69
+ end
70
+
71
+ it "should generate urls for an application, model, action, and id" do
72
+ @c.url_for(:application => :another_app, :model => :another_model,
73
+ :action => :show, :id => '{12}').should == '/another_app/another_model/{12}/show'
74
+ end
75
+
76
+ it "should generate urls with a query" do
77
+ @c.url_for(:action => :create, :query => {:name => 'John Smith',
78
+ 'address' => "http://john.smith.com"}).should == '/application/model?name=John%20Smith&address=http%3A%2F%2Fjohn.smith.com'
79
+ end
80
+
81
+ it "should generate urls with a fragment" do
82
+ @c.url_for(:action => :show, :id => '{12}', :fragment => "an-anchor").should == '/application/model/{12}/show#an-anchor'
83
+ end
84
+
85
+ it "should generate link for a url" do
86
+ @c.link_to("Visit Other Site", "http://www.rhomobile.com/").should == "<a href=\"http://www.rhomobile.com/\" >Visit Other Site</a>"
87
+ end
88
+
89
+ it "should generate link for an action" do
90
+ @c.link_to("Help", :action => "help").should == "<a href=\"/application/model/help\" >Help</a>"
91
+ end
92
+
93
+ it "should generate link for 'delete' action" do
94
+ @c.link_to("Delete", :action => "delete", :id => '{12}').should == "<a href=\"/application/model/{12}/delete\" onclick=\"var f = document.createElement('form'); f.style.display = 'none';this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;f.submit();return false;\">Delete</a>"
95
+ end
96
+
97
+ it "should generate link for an action and style it" do
98
+ @c.link_to("Show", { :action => "show", :id => '{12}'},"style=\"height:4px;width:7px;border-width:0px;\"").should == "<a href=\"/application/model/{12}/show\" style=\"height:4px;width:7px;border-width:0px;\">Show</a>"
99
+ end
100
+
101
+ it "should generate link for 'delete' action and style it" do
102
+ @c.link_to("Delete", { :action => "delete", :id => '{12}' }, "class=\"delete_link\"").should == "<a href=\"/application/model/{12}/delete\" class=\"delete_link\" onclick=\"var f = document.createElement('form'); f.style.display = 'none';this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;f.submit();return false;\">Delete</a>"
103
+ end
104
+
105
+ it "should generate link with a query" do
106
+ @c.link_to("Invate",:action => :invite, :query => {:name => 'John Smith', 'address' => "http://john.smith.com"}).should == "<a href=\"/application/model/invite?name=John%20Smith&address=http%3A%2F%2Fjohn.smith.com\" >Invate</a>"
107
+ end
108
+
109
+ end #describe "url_for and link_to"
110
+
111
+ describe "redirect" do
112
+
113
+ before(:each) do
114
+ @response = Hash.new
115
+ @response['headers'] = {}
116
+ @c = Rho::RhoController.new
117
+ @c.stub!(:send).and_return(nil)
118
+ @c.serve(nil,{'application' => 'application', 'model' => 'model'},@response)
119
+ end
120
+
121
+ it "should redirect to a url" do
122
+ @c.redirect "/start-page"
123
+ @response['headers']['Location'].should == "/start-page"
124
+ @response['status'].should == 302
125
+ @response['message'].should == 'Moved temporarily'
126
+ end
127
+
128
+ it "should redirect to an action" do
129
+ @c.redirect :action => :show, :id => '{12}'
130
+ @response['headers']['Location'].should == "/application/model/{12}/show"
131
+ @response['status'].should == 302
132
+ @response['message'].should == 'Moved temporarily'
133
+ end
134
+
135
+ it "should redirect to an action with 301 status code and status message" do
136
+ @c.redirect({:action => :show, :id => '{12}'}, {'status' => 301, 'message' => 'Moved permanently'})
137
+ @response['headers']['Location'].should == "/application/model/{12}/show"
138
+ @response['status'].should == 301
139
+ @response['message'].should == 'Moved permanently'
140
+ end
141
+
142
+ end #describe "redirect"
143
+
144
+ end
data/spec/rho_spec.rb ADDED
@@ -0,0 +1,75 @@
1
+ #
2
+ # rho_spec.rb
3
+ # rhodes
4
+ #
5
+ # Copyright (C) 2008 Rhomobile, Inc. All rights reserved.
6
+ #
7
+ # This program is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # This program is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
+ #
20
+ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
21
+ require File.dirname(__FILE__) + "/spec_helper"
22
+
23
+ describe "Rho" do
24
+
25
+ it_should_behave_like "rho initializer"
26
+ it_should_behave_like "rho db initializer"
27
+
28
+ it "should populate configuration in sources table" do
29
+ sources = Rhom::RhomDbAdapter::select_from_table('sources','*')
30
+ sources.size.should > 1
31
+ end
32
+
33
+ it "should initialize configuration only once" do
34
+ Rhom::RhomDbAdapter::delete_all_from_table('sources')
35
+ @rho.source_initialized?(1).should == false
36
+ @rho.init_sources
37
+ @rho.source_initialized?(1).should == true
38
+ end
39
+
40
+ it "should have start_path" do
41
+ Rho::RhoConfig.start_path.should == '/'
42
+ end
43
+
44
+ it "should set start_path" do
45
+ Rho::RhoConfig.start_path = '/foo/bar'
46
+ Rho::RhoConfig.start_path.should == '/foo/bar'
47
+ end
48
+
49
+ it "should retrieve start_path" do
50
+ Rho::RhoConfig.start_path = '/'
51
+ @rho.get_start_path.should == '/'
52
+ end
53
+
54
+ it "should have options_path" do
55
+ Rho::RhoConfig.options_path.should == '/'
56
+ end
57
+
58
+ it "should set options_path" do
59
+ Rho::RhoConfig.options_path = '/ops2'
60
+ Rho::RhoConfig.options_path.should == '/ops2'
61
+ end
62
+
63
+ it "should retrieve options_path" do
64
+ Rho::RhoConfig.options_path = '/ops3'
65
+ @rho.get_options_path.should == '/ops3'
66
+ end
67
+
68
+ it "should return from get_app" do
69
+ pending "fix relative paths for testing of get_app"
70
+ end
71
+
72
+ it "should serve request" do
73
+ pending "need to mock request"
74
+ end
75
+ end
@@ -0,0 +1,372 @@
1
+ #
2
+ # rhom_object_factory_spec.rb
3
+ # rhodes
4
+ #
5
+ # Copyright (C) 2008 Rhomobile, Inc. All rights reserved.
6
+ #
7
+ # This program is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+ #
19
+ require File.dirname(__FILE__) + "/spec_helper"
20
+
21
+ describe "RhomObjectFactory" do
22
+
23
+ it_should_behave_like "rho initializer"
24
+ it_should_behave_like "rho db initializer"
25
+
26
+ it "should set source_id attributes" do
27
+ Account.get_source_id.should == "1"
28
+ Case.get_source_id.should == "2"
29
+ Employee.get_source_id.should == "3"
30
+ end
31
+
32
+ it "should dynamically assign values" do
33
+ account = Account.new
34
+ account.name = 'hello name'
35
+ account.industry = 'hello industry'
36
+ account.object = '3560c0a0-ef58-2f40-68a5-fffffffffffff'
37
+ account.value = 'xyz industries'
38
+ account.name.should == 'hello name'
39
+ account.industry.should == 'hello industry'
40
+ account.object.should == '3560c0a0-ef58-2f40-68a5-fffffffffffff'
41
+ account.value.should == 'xyz industries'
42
+ end
43
+
44
+ it "should retrieve Case models" do
45
+ results = Case.find(:all)
46
+ results.length.should == 7
47
+ results[0].case_number.should == "57"
48
+ results[4].name.should == "implement SugarCRM sample app"
49
+ end
50
+
51
+ it "should retrieve Account models" do
52
+ results = Account.find(:all)
53
+ results.length.should == 5
54
+ results[0].name.should == "vSpring"
55
+ results[0].industry.should == "Finance"
56
+ results[1].name.should == "Rhomobile"
57
+ results[1].industry.should == "Technology"
58
+ results[4].industry.should == "Technology"
59
+ results[4].name.should == "Mobio India"
60
+ end
61
+
62
+ it "should have correct number of attributes" do
63
+ @account = Account.find(:all).first
64
+
65
+ @account.instance_variables.size.should == 37
66
+ end
67
+
68
+ it "should get count of objects" do
69
+ Account.count.should == 5
70
+ end
71
+
72
+ it "should create multiple records offline" do
73
+ vars = {"name"=>"foobarthree", "industry"=>"entertainment"}
74
+ account = Account.new(vars)
75
+ account.save
76
+ acct = Account.find(:first, :conditions =>{'name'=>'foobarthree'})
77
+ acct.name.should == 'foobarthree'
78
+ acct.industry.should == 'entertainment'
79
+
80
+ account = Account.new
81
+ account.name = 'foobarfour'
82
+ account.industry = 'solar'
83
+ account.save
84
+
85
+ acct = Account.find(:first, :conditions =>{'name'=>'foobarfour'})
86
+ acct.name.should == 'foobarfour'
87
+ acct.industry.should == 'solar'
88
+ end
89
+
90
+ it "should create a record" do
91
+ vars = {"name"=>"some new record", "industry"=>"electronices"}
92
+ @account1 = Account.new(vars)
93
+ new_id = @account1.object
94
+ @account1.save
95
+ @account2 = Account.find(new_id)
96
+ @account2.object.should =="{#{@account1.object}}"
97
+ @account2.name.should == vars['name']
98
+ @account2.industry.should == vars['industry']
99
+ end
100
+
101
+ it "should destroy a record" do
102
+ count = Account.find(:all).size
103
+ @account = Account.find(:all)[0]
104
+ destroy_id = @account.object
105
+ @account.destroy
106
+ @account_nil = Account.find(destroy_id)
107
+ @account_nil.should be_nil
108
+ new_count = Account.find(:all).size
109
+ (count - 1).should == new_count
110
+ end
111
+
112
+ it "should partially update a record" do
113
+ new_attributes = {"name"=>"Mobio US"}
114
+ @account = Account.find("44e804f2-4933-4e20-271c-48fcecd9450d")
115
+ @account.update_attributes(new_attributes)
116
+ @new_acct = Account.find("44e804f2-4933-4e20-271c-48fcecd9450d")
117
+ @new_acct.name.should == "Mobio US"
118
+ @new_acct.industry.should == "Technology"
119
+ end
120
+
121
+ it "should fully update a record" do
122
+ new_attributes = {"name"=>"Mobio US", "industry"=>"Electronics"}
123
+ @account = Account.find(:all).first
124
+ @account.update_attributes(new_attributes)
125
+
126
+ @new_acct = Account.find(:all).first
127
+
128
+ @new_acct.name.should == "Mobio US"
129
+ @new_acct.industry.should == "Electronics"
130
+ end
131
+
132
+ it "should set <something>_type_<something> or <something>_object_<something> field for a record" do
133
+ new_attributes = {"account_type"=>"Partner",
134
+ "type_acct"=>"Customer",
135
+ "object_acct"=>"new object",
136
+ "acct_object"=>"same object"}
137
+ @account = Account.find('44e804f2-4933-4e20-271c-48fcecd9450d')
138
+ @account.update_attributes(new_attributes)
139
+
140
+ @new_acct = Account.find('44e804f2-4933-4e20-271c-48fcecd9450d')
141
+
142
+ @new_acct.name.should == "Mobio India"
143
+ @new_acct.account_type.should == "Partner"
144
+ @new_acct.type_acct.should == "Customer"
145
+ @new_acct.object_acct.should == "new object"
146
+ @new_acct.acct_object.should == "same object"
147
+ end
148
+
149
+ it "should _NOT_ set 'type' field for a record" do
150
+ new_attributes = {"type"=>"Partner"}
151
+ @account = Account.find('44e804f2-4933-4e20-271c-48fcecd9450d')
152
+ @account.update_attributes(new_attributes)
153
+
154
+ @new_acct = Account.find('44e804f2-4933-4e20-271c-48fcecd9450d')
155
+
156
+ @new_acct.name.should == "Mobio India"
157
+ @new_acct.instance_variables.each do |var|
158
+ var.gsub(/@/,'').match('\btype\b').should be_nil
159
+ end
160
+ end
161
+
162
+ it "should update an attribute that was previously nil" do
163
+ new_attributes = {"new_name"=>"Mobio Europe"}
164
+ @account = Account.find('44e804f2-4933-4e20-271c-48fcecd9450d')
165
+ @account.update_attributes(new_attributes)
166
+
167
+ @new_acct = Account.find('44e804f2-4933-4e20-271c-48fcecd9450d')
168
+
169
+ @new_acct.new_name.should == "Mobio Europe"
170
+ @new_acct.name.should == "Mobio India"
171
+ @new_acct.industry.should == "Technology"
172
+ end
173
+
174
+ it "should store only last updated value for attrib" do
175
+ new_attributes1 = {"new_name"=>"Mobio Europe"}
176
+ @account = Account.find('44e804f2-4933-4e20-271c-48fcecd9450d')
177
+ @account.update_attributes(new_attributes1)
178
+
179
+ @new_acct = Account.find('44e804f2-4933-4e20-271c-48fcecd9450d')
180
+
181
+ @new_acct.new_name.should == "Mobio Europe"
182
+ @new_acct.name.should == "Mobio India"
183
+ @new_acct.industry.should == "Technology"
184
+
185
+ new_attributes2 = {"new_name"=>"Mobio Asia"}
186
+ @account = Account.find('44e804f2-4933-4e20-271c-48fcecd9450d')
187
+ @account.update_attributes(new_attributes2)
188
+
189
+ @new_acct = Account.find('44e804f2-4933-4e20-271c-48fcecd9450d')
190
+
191
+ @new_acct.new_name.should == "Mobio Asia"
192
+ @new_acct.name.should == "Mobio India"
193
+ @new_acct.industry.should == "Technology"
194
+
195
+ records = Rhom::RhomDbAdapter::select_from_table('object_values','*', 'update_type' => 'update')
196
+ records.length.should == 1
197
+ end
198
+
199
+ it "should retrieve and modify one record" do
200
+ @acct = Account.find('44e804f2-4933-4e20-271c-48fcecd9450d')
201
+
202
+ @acct.name.should == "Mobio India"
203
+ @acct.industry.should == "Technology"
204
+
205
+ @acct.name = "Rhomobile US"
206
+
207
+ @acct.name.should == "Rhomobile US"
208
+ end
209
+
210
+ it "should return an empty value for a non-existent attribute" do
211
+ @acct = Account.find('44e804f2-4933-4e20-271c-48fcecd9450d')
212
+
213
+ @acct.foobar.should be_nil
214
+ end
215
+
216
+ it "should respond to ask" do
217
+ question = 'Rhodes'
218
+ Account.ask(question)
219
+ res = Rhom::RhomDbAdapter::select_from_table('object_values','*', 'update_type' => 'ask')
220
+ res.length.should == 1
221
+
222
+ res[0]['attrib'].should == 'question'
223
+ res[0]['value'].should == question
224
+ end
225
+
226
+ it "should respond to ask with last question only" do
227
+ question = 'Rhodes'
228
+ Account.ask(question)
229
+ res = Rhom::RhomDbAdapter::select_from_table('object_values','*', 'update_type' => 'ask')
230
+ res.length.should == 1
231
+
232
+ res[0]['attrib'].should == 'question'
233
+ res[0]['value'].should == question
234
+
235
+ question = 'Ruby on Rails'
236
+ question_encoded = 'Ruby%20on%20Rails'
237
+ Account.ask(question)
238
+ res = Rhom::RhomDbAdapter::select_from_table('object_values','*', 'update_type' => 'ask')
239
+ res.length.should == 1
240
+
241
+ res[0]['attrib'].should == 'question'
242
+ res[0]['value'].should == question_encoded
243
+ end
244
+
245
+ it "should encode ask params" do
246
+ question = 'where am i?'
247
+ question_encoded = 'where%20am%20i%3F'
248
+ Account.ask(question)
249
+ @res = Rhom::RhomDbAdapter::select_from_table('object_values','*', 'update_type' => 'ask')
250
+ @res.length.should == 1
251
+
252
+ @res[0]['attrib'].should == 'question'
253
+ @res[0]['value'].should == question_encoded
254
+ end
255
+
256
+ it "should store all ask db operations as query" do
257
+ question = 'where am i?'
258
+ question_encoded = 'where%20am%20i%3F'
259
+ Contact.ask(question)
260
+
261
+ @contact = Contact.find(:first)
262
+ @contact.update_attributes({"question"=>"i am here"})
263
+
264
+ @res = Rhom::RhomDbAdapter::select_from_table('object_values','*', {'update_type' => 'query', 'source_id' => 350})
265
+ @res.length.should == 1
266
+ @res[0]['attrib'].should == 'question'
267
+ @res[0]['value'].should == 'i am here'
268
+
269
+ ['create','update','delete'].each do |u_type|
270
+ @res = Rhom::RhomDbAdapter::select_from_table('object_values','*', {'update_type' =>u_type, 'source_id' => 350})
271
+ @res.length.should == 0
272
+ end
273
+ end
274
+
275
+ it "should delete ask records without delete sync operation" do
276
+ question = 'where am i?'
277
+ question_encoded = 'where%20am%20i%3F'
278
+ Contact.ask(question)
279
+
280
+ @contact = Contact.find(:first)
281
+ @contact.destroy
282
+
283
+ ['query','create','update','delete'].each do |u_type|
284
+ @res = Rhom::RhomDbAdapter::select_from_table('object_values','*', {'update_type' =>u_type, 'source_id' => 350})
285
+ @res.length.should == 0
286
+ end
287
+ end
288
+
289
+ it "should find with conditions" do
290
+ @accts = Account.find(:all, :conditions => {'industry' => 'Technology'})
291
+ @accts.length.should == 3
292
+ @accts[0].name.should == "Rhomobile"
293
+ @accts[0].industry.should == "Technology"
294
+ @accts[1].name.should == "Aeroprise"
295
+ @accts[1].industry.should == "Technology"
296
+ end
297
+
298
+ it "should find first with conditions" do
299
+ @mobio_ind_acct = Account.find(:first, :conditions => {'name' => 'Mobio India'})
300
+ @mobio_ind_acct.name.should == "Mobio India"
301
+ @mobio_ind_acct.industry.should == "Technology"
302
+ end
303
+
304
+ it "should order by column" do
305
+ @accts = Account.find(:all, :order => 'name')
306
+
307
+ @accts.first.name.should == "Aeroprise"
308
+ @accts.first.industry.should == "Technology"
309
+ @accts[1].name.should == "Mirapath"
310
+ @accts[1].industry.should == "Electronics"
311
+ @accts.last.name.should == "vSpring"
312
+ @accts.last.industry.should == "Finance"
313
+ end
314
+
315
+ it "should return records when order by is nil for some records" do
316
+ @accts = Account.find(:all, :order => 'billing_address_country')
317
+ @accts.length.should == 5
318
+ @accts.first.name.should == "vSpring"
319
+ end
320
+
321
+ it "should include only selected columns" do
322
+ pending "need to implement"
323
+ @accts = Account.find(:all, :select => ['name'])
324
+
325
+ @accts[0].name.should == "vSpring"
326
+ @accts[0].industry.should be_nil
327
+ end
328
+
329
+ it "should include selected columns and conditions" do
330
+ pending "need to implement"
331
+ @accts = Account.find(:all, :conditions => {'name' => 'vSpring'}, :select => ['name'])
332
+
333
+ @accts[0].name.should == "vSpring"
334
+ @accts[0].industry.should be_nil
335
+ end
336
+
337
+ it "should delete_all" do
338
+ Account.delete_all
339
+
340
+ Account.find(:all).length.should == 0
341
+ end
342
+
343
+ it "should delete_all with conditions" do
344
+ Account.delete_all(:conditions => {'name' => 'Mirapath'})
345
+
346
+ @accts = Account.find(:all, :conditions => {'name' => 'Mirapath'})
347
+ @accts.length.should == 0
348
+ end
349
+
350
+ it "should delete_all with conditions across objects" do
351
+ Account.delete_all(:conditions => {'industry' => 'Technology'})
352
+
353
+ @accts = Account.find(:all, :conditions => {'industry' => 'Technology'})
354
+ @accts.length.should == 0
355
+
356
+ @accts = Account.find(:all)
357
+
358
+ @accts.length.should == 2
359
+ @accts[0].name.should == "vSpring"
360
+ @accts[0].industry.should == "Finance"
361
+ @accts[1].name.should == "Mirapath"
362
+ @accts[1].industry.should == "Electronics"
363
+ end
364
+
365
+ it "should support blob file type" do
366
+ @acct = Account.new({'image_uri'=>"/db/images/mynewimage.png"})
367
+ @acct.name = "my new acct"
368
+ @acct.save
369
+ @res = Rhom::RhomDbAdapter::select_from_table('object_values','*', 'attrib_type' => "blob.file")
370
+ @res.length.should == 1
371
+ end
372
+ end
data/spec/rhom_spec.rb ADDED
@@ -0,0 +1,45 @@
1
+ #
2
+ # rhom_spec.rb
3
+ # rhodes
4
+ #
5
+ # Copyright (C) 2008 Rhomobile, Inc. All rights reserved.
6
+ #
7
+ # This program is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # This program is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
+ #
20
+ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
21
+ require File.dirname(__FILE__) + "/spec_helper"
22
+
23
+ describe "Rhom" do
24
+
25
+ it_should_behave_like "rho initializer"
26
+ it_should_behave_like "rho db initializer"
27
+
28
+ it "should get client_id" do
29
+ Rhom::Rhom::client_id.should == '67320d31-e42e-4156-af91-5d9bd7175b08'
30
+ end
31
+
32
+ it "should perform full reset of database" do
33
+ Rhom::Rhom::database_full_reset
34
+ Rhom::RhomDbAdapter::select_from_table('object_values','*').length.should == 0
35
+ Rhom::RhomDbAdapter::select_from_table('client_info','*').length.should == 0
36
+ Rhom::Rhom::client_id.should be_nil
37
+ end
38
+
39
+ it "should perform full database reset and logout" do
40
+ Rhom::Rhom::database_full_reset_and_logout
41
+ Rhom::RhomDbAdapter::select_from_table('object_values','*').length.should == 0
42
+ Rhom::RhomDbAdapter::select_from_table('client_info','*').length.should == 0
43
+ Rhom::Rhom::client_id.should be_nil
44
+ end
45
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,49 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
8
+
9
+ $:.unshift(File.join(File.dirname(__FILE__), '..'))
10
+
11
+ # Use the rubygem for local testing
12
+ require 'spec/stubs'
13
+ require 'rho/rho'
14
+ require 'rhom/rhom'
15
+
16
+ describe "rho initializer", :shared => true do
17
+
18
+ attr_accessor :rhom, :rho
19
+
20
+ before(:all) do
21
+ FileUtils.mkdir_p('build')
22
+ end
23
+
24
+ after(:all) do
25
+ FileUtils.rm_rf('build')
26
+ end
27
+
28
+ def array_print(arr)
29
+ arr.each_with_index do |x,i|
30
+ puts "arr[#{i}] = #{x.inspect}"
31
+ end
32
+ end
33
+ end
34
+
35
+ describe "rho db initializer", :shared => true do
36
+ before(:each) do
37
+ FileUtils.rm_rf('build/syncdbtest.sqlite')
38
+ FileUtils.cp_r('spec/syncdbtest.sqlite','build/syncdbtest.sqlite')
39
+ Object::const_set("SYNC_DB_FILE", "build/syncdbtest.sqlite") unless defined? SYNC_DB_FILE
40
+ @rho = Rho::RHO.new(File.join(File.dirname(File.expand_path(__FILE__)), 'app_manifest.txt'))
41
+ @rhom = Rhom::RhomObjectFactory.new
42
+ end
43
+
44
+ after(:each) do
45
+ Rhom::RhomDbAdapter.close
46
+ @rho = nil
47
+ @rhom = nil
48
+ end
49
+ end