rhosync 2.0.3 → 2.0.4
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/CHANGELOG +5 -0
- data/Rakefile +2 -3
- data/doc/protocol.html +75 -75
- data/lib/rhosync/api/create_client.rb +1 -1
- data/lib/rhosync/api/create_user.rb +1 -1
- data/lib/rhosync/api/delete_client.rb +1 -1
- data/lib/rhosync/api/delete_user.rb +1 -1
- data/lib/rhosync/api/get_api_token.rb +1 -1
- data/lib/rhosync/api/get_client_params.rb +1 -1
- data/lib/rhosync/api/get_db_doc.rb +2 -2
- data/lib/rhosync/api/get_license_info.rb +1 -1
- data/lib/rhosync/api/get_source_params.rb +1 -1
- data/lib/rhosync/api/list_client_docs.rb +1 -1
- data/lib/rhosync/api/list_clients.rb +1 -1
- data/lib/rhosync/api/list_source_docs.rb +1 -1
- data/lib/rhosync/api/list_sources.rb +1 -1
- data/lib/rhosync/api/list_users.rb +1 -1
- data/lib/rhosync/api/ping.rb +2 -2
- data/lib/rhosync/api/push_deletes.rb +1 -1
- data/lib/rhosync/api/push_objects.rb +1 -1
- data/lib/rhosync/api/reset.rb +1 -1
- data/lib/rhosync/api/set_db_doc.rb +1 -1
- data/lib/rhosync/api/set_refresh_time.rb +1 -1
- data/lib/rhosync/api/update_user.rb +1 -1
- data/lib/rhosync/api/upload_file.rb +1 -1
- data/lib/rhosync/console/app/routes/auth.rb +1 -1
- data/lib/rhosync/console/rhosync_api.rb +139 -44
- data/lib/rhosync/model.rb +6 -1
- data/lib/rhosync/store.rb +19 -17
- data/lib/rhosync/version.rb +1 -1
- data/lib/rhosync.rb +2 -1
- data/spec/api/api_helper.rb +2 -2
- data/spec/api/rhosync_api_spec.rb +306 -0
- data/spec/doc/doc_spec.rb +2 -2
- data/spec/model_spec.rb +4 -0
- data/spec/server/server_spec.rb +9 -9
- data/spec/store_spec.rb +26 -18
- metadata +13 -11
@@ -0,0 +1,306 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__),'..','..','lib','rhosync','console','rhosync_api.rb')
|
2
|
+
require File.join(File.dirname(__FILE__),'api_helper')
|
3
|
+
|
4
|
+
describe "RhosyncApi" do
|
5
|
+
it_should_behave_like "ApiHelper"
|
6
|
+
|
7
|
+
it "should return api token using direct api call" do
|
8
|
+
RhosyncApi::get_token('','rhoadmin','').should == @api_token
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should return api token using rest call" do
|
12
|
+
response = {'set-cookie'=>"rhosync_session=c21...42b64; path=/; expires=Tue, 02-Aug-2011 23:55:19 GMT"}
|
13
|
+
res = mock('HttpResponse')
|
14
|
+
res.stub!(:response).and_return(response)
|
15
|
+
http = mock('NetHttp')
|
16
|
+
http.stub!(:post).and_return(res)
|
17
|
+
Net::HTTP.stub!(:new).and_return(http)
|
18
|
+
RestClient.stub(:post).and_return(@api_token)
|
19
|
+
|
20
|
+
Net::HTTP.should_receive(:new).once
|
21
|
+
RestClient.should_receive(:post).once
|
22
|
+
RhosyncApi::get_token('some_url','rhoadmin','').should == @api_token
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should list users using direct api call" do
|
26
|
+
RhosyncApi::list_users('',@api_token).should == ['testuser']
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should list users using rect call" do
|
30
|
+
res = mock('HttpResponse')
|
31
|
+
res.stub!(:body).and_return(['testuser'].to_json)
|
32
|
+
RestClient.stub(:post).and_return(res)
|
33
|
+
RestClient.should_receive(:post).once
|
34
|
+
RhosyncApi::list_users('some_url',@api_token).should == ['testuser']
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should create user using direct api call" do
|
38
|
+
RhosyncApi::create_user('',@api_token,'testuser1','testpass1')
|
39
|
+
User.load('testuser1').login.should == 'testuser1'
|
40
|
+
User.authenticate('testuser1','testpass1').login.should == 'testuser1'
|
41
|
+
@a.users.members.sort.should == [@u.login, 'testuser1']
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should create user using rect call" do
|
45
|
+
RestClient.stub(:post).and_return("User created")
|
46
|
+
RestClient.should_receive(:post).once
|
47
|
+
RhosyncApi::create_user('some_url',@api_token,'testuser1','testpass1').should == "User created"
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should delete user direct api call" do
|
51
|
+
RhosyncApi::create_user('',@api_token,'testuser1','testpass1').should == "User created"
|
52
|
+
User.is_exist?('testuser1').should == true
|
53
|
+
RhosyncApi::delete_user('',@api_token,'testuser1').should == "User deleted"
|
54
|
+
User.is_exist?('testuser1').should == false
|
55
|
+
App.load(@test_app_name).users.members.should == ["testuser"]
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should delete user using rect call" do
|
59
|
+
RestClient.stub(:post).and_return("User deleted")
|
60
|
+
RestClient.should_receive(:post).once
|
61
|
+
RhosyncApi::delete_user('some_url',@api_token,'testuser1').should == "User deleted"
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should list clients using direct api call" do
|
65
|
+
res = RhosyncApi::list_clients('',@api_token,@u_fields[:login])
|
66
|
+
res.is_a?(Array).should == true
|
67
|
+
res.size.should == 1
|
68
|
+
res[0].is_a?(String) == true
|
69
|
+
res[0].length.should == 32
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should handle empty client's list" do
|
73
|
+
@u.clients.delete(@c.id)
|
74
|
+
RhosyncApi::list_clients('',@api_token,@u_fields[:login]).should == []
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should create user using rect call" do
|
78
|
+
res = mock('HttpResponse')
|
79
|
+
res.stub!(:body).and_return(["21325fd9911044c6ad974785bf23c173"].to_json)
|
80
|
+
RestClient.stub(:post).and_return(res)
|
81
|
+
RestClient.should_receive(:post).once
|
82
|
+
RhosyncApi::list_clients('some_url',@api_token,'testuser1').should == ["21325fd9911044c6ad974785bf23c173"]
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should create client for a user using direct api call" do
|
86
|
+
RhosyncApi::create_client('',@api_token,@u_fields[:login])
|
87
|
+
clients = User.load(@u_fields[:login]).clients.members
|
88
|
+
clients.size.should == 2
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should create client using rect call" do
|
92
|
+
res = mock('HttpResponse')
|
93
|
+
res.stub!(:body).and_return("")
|
94
|
+
RestClient.stub(:post).and_return(res)
|
95
|
+
RestClient.should_receive(:post).once
|
96
|
+
RhosyncApi::create_client('some_url',@api_token,'testuser1')
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should delete client using direct api call" do
|
100
|
+
RhosyncApi::delete_client('',@api_token,@u_fields[:login],@c.id).should == "Client deleted"
|
101
|
+
Client.is_exist?(@c.id).should == false
|
102
|
+
User.load(@u_fields[:login]).clients.members.should == []
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should delete client using rect call" do
|
106
|
+
RestClient.stub(:post).and_return("Client deleted")
|
107
|
+
RestClient.should_receive(:post).once
|
108
|
+
RhosyncApi::delete_client('some_url',@api_token,@u_fields[:login],@c.id).should == "Client deleted"
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should list client attributes using direct api call" do
|
112
|
+
res = RhosyncApi::get_client_params('',@api_token,@c.id)
|
113
|
+
res.delete_if { |attrib| attrib['name'] == 'rho__id' }
|
114
|
+
res.sort{|x,y| x['name']<=>y['name']}.should == [
|
115
|
+
{"name"=>"device_type", "value"=>"iPhone", "type"=>"string"},
|
116
|
+
{"name"=>"device_pin", "value"=>"abcd", "type"=>"string"},
|
117
|
+
{"name"=>"device_port", "value"=>"3333", "type"=>"string"},
|
118
|
+
{"name"=>"user_id", "value"=>"testuser", "type"=>"string"},
|
119
|
+
{"name"=>"app_id", "value"=>"application", "type"=>"string"}].sort{|x,y| x['name']<=>y['name']}
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should list client attributes using rest call" do
|
123
|
+
res = mock('HttpResponse')
|
124
|
+
res.stub!(:body).and_return(["blah"].to_json)
|
125
|
+
RestClient.stub(:post).and_return(res)
|
126
|
+
RestClient.should_receive(:post).once
|
127
|
+
RhosyncApi::get_client_params('some_url',@api_token,'client_id')
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should list all application sources using direct api call" do
|
131
|
+
RhosyncApi::list_sources('',@api_token).sort.should ==
|
132
|
+
["SimpleAdapter", "SampleAdapter", "FixedSchemaAdapter"].sort
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should list all application sources using rest call" do
|
136
|
+
res = mock('HttpResponse')
|
137
|
+
res.stub!(:body).and_return(["SimpleAdapter", "SampleAdapter", "FixedSchemaAdapter"].to_json)
|
138
|
+
RestClient.stub(:post).and_return(res)
|
139
|
+
RestClient.should_receive(:post).once
|
140
|
+
RhosyncApi::list_sources('some_url',@api_token)
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should list source attributes using direct api call" do
|
144
|
+
RhosyncApi::get_source_params('',@api_token,"SampleAdapter").should == [
|
145
|
+
{"name"=>"rho__id", "value"=>"SampleAdapter", "type"=>"string"},
|
146
|
+
{"name"=>"source_id", "value"=>nil, "type"=>"integer"},
|
147
|
+
{"name"=>"name", "value"=>"SampleAdapter", "type"=>"string"},
|
148
|
+
{"name"=>"url", "value"=>"", "type"=>"string"},
|
149
|
+
{"name"=>"login", "value"=>"", "type"=>"string"},
|
150
|
+
{"name"=>"password", "value"=>"", "type"=>"string"},
|
151
|
+
{"name"=>"priority", "value"=>3, "type"=>"integer"},
|
152
|
+
{"name"=>"callback_url", "value"=>nil, "type"=>"string"},
|
153
|
+
{"name"=>"poll_interval", "value"=>300, "type"=>"integer"},
|
154
|
+
{"name"=>"partition_type", "value"=>"user", "type"=>"string"},
|
155
|
+
{"name"=>"sync_type", "value"=>"incremental", "type"=>"string"},
|
156
|
+
{"name"=>"belongs_to", "type"=>"string", "value"=>nil},
|
157
|
+
{"name"=>"has_many", "type"=>"string", "value"=>"FixedSchemaAdapter,brand"},
|
158
|
+
{"name"=>"queue", "value"=>nil, "type"=>"string"},
|
159
|
+
{"name"=>"query_queue", "value"=>nil, "type"=>"string"},
|
160
|
+
{"name"=>"cud_queue", "value"=>nil, "type"=>"string"},
|
161
|
+
{"name"=>"schema", "value"=>nil, "type"=>"string"}]
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should list source attributes using rest call" do
|
165
|
+
res = mock('HttpResponse')
|
166
|
+
res.stub!(:body).and_return(["SimpleAdapter"].to_json)
|
167
|
+
RestClient.stub(:post).and_return(res)
|
168
|
+
RestClient.should_receive(:post).once
|
169
|
+
RhosyncApi::get_source_params('some_url',@api_token,"SimpleAdapter")
|
170
|
+
end
|
171
|
+
|
172
|
+
it "should list of shared source documents using direct api call" do
|
173
|
+
RhosyncApi::list_source_docs('',@api_token,"SimpleAdapter","*").sort.should == {
|
174
|
+
"md"=>"source:application:__shared__:SimpleAdapter:md",
|
175
|
+
"errors"=>"source:application:__shared__:SimpleAdapter:errors",
|
176
|
+
"md_size"=>"source:application:__shared__:SimpleAdapter:md_size",
|
177
|
+
"md_copy"=>"source:application:__shared__:SimpleAdapter:md_copy"}.sort
|
178
|
+
end
|
179
|
+
|
180
|
+
it "should list of shared source documents using rest call" do
|
181
|
+
res = mock('HttpResponse')
|
182
|
+
res.stub!(:body).and_return(["SimpleAdapter"].to_json)
|
183
|
+
RestClient.stub(:post).and_return(res)
|
184
|
+
RestClient.should_receive(:post).once
|
185
|
+
RhosyncApi::list_source_docs('some_url',@api_token,"SimpleAdapter",'*')
|
186
|
+
end
|
187
|
+
|
188
|
+
it "should list client documents using direct api call" do
|
189
|
+
RhosyncApi::list_client_docs('',@api_token,"SimpleAdapter",@c.id).should == {
|
190
|
+
"cd"=>"client:application:testuser:#{@c.id}:SimpleAdapter:cd",
|
191
|
+
"cd_size"=>"client:application:testuser:#{@c.id}:SimpleAdapter:cd_size",
|
192
|
+
"create"=>"client:application:testuser:#{@c.id}:SimpleAdapter:create",
|
193
|
+
"update"=>"client:application:testuser:#{@c.id}:SimpleAdapter:update",
|
194
|
+
"delete"=>"client:application:testuser:#{@c.id}:SimpleAdapter:delete",
|
195
|
+
|
196
|
+
"page"=>"client:application:testuser:#{@c.id}:SimpleAdapter:page",
|
197
|
+
"page_token"=>"client:application:testuser:#{@c.id}:SimpleAdapter:page_token",
|
198
|
+
"delete_page"=>"client:application:testuser:#{@c.id}:SimpleAdapter:delete_page",
|
199
|
+
"create_links"=>"client:application:testuser:#{@c.id}:SimpleAdapter:create_links",
|
200
|
+
"create_links_page"=>"client:application:testuser:#{@c.id}:SimpleAdapter:create_links_page",
|
201
|
+
|
202
|
+
"delete_errors"=>"client:application:testuser:#{@c.id}:SimpleAdapter:delete_errors",
|
203
|
+
"login_error"=>"client:application:testuser:#{@c.id}:SimpleAdapter:login_error",
|
204
|
+
"create_errors"=>"client:application:testuser:#{@c.id}:SimpleAdapter:create_errors",
|
205
|
+
"update_errors"=>"client:application:testuser:#{@c.id}:SimpleAdapter:update_errors",
|
206
|
+
"logoff_error"=>"client:application:testuser:#{@c.id}:SimpleAdapter:logoff_error",
|
207
|
+
|
208
|
+
"search"=>"client:application:testuser:#{@c.id}:SimpleAdapter:search",
|
209
|
+
"search_token"=>"client:application:testuser:#{@c.id}:SimpleAdapter:search_token",
|
210
|
+
"search_errors"=>"client:application:testuser:#{@c.id}:SimpleAdapter:search_errors"}
|
211
|
+
end
|
212
|
+
|
213
|
+
it "should list client documents using rest call" do
|
214
|
+
res = mock('HttpResponse')
|
215
|
+
res.stub!(:body).and_return(["SimpleAdapter"].to_json)
|
216
|
+
RestClient.stub(:post).and_return(res)
|
217
|
+
RestClient.should_receive(:post).once
|
218
|
+
RhosyncApi::list_client_docs('some_url',@api_token,"SimpleAdapter",'*')
|
219
|
+
end
|
220
|
+
|
221
|
+
it "should return db document by name using direct api call" do
|
222
|
+
data = {'1' => {'foo' => 'bar'}}
|
223
|
+
set_state('abc:abc' => data)
|
224
|
+
RhosyncApi::get_db_doc('',@api_token,'abc:abc').should == data
|
225
|
+
end
|
226
|
+
|
227
|
+
it "should return db document by name and data_type using direct api call" do
|
228
|
+
data = 'some string'
|
229
|
+
set_state('abc:abc' => data)
|
230
|
+
RhosyncApi::get_db_doc('',@api_token,'abc:abc','string').should == data
|
231
|
+
end
|
232
|
+
|
233
|
+
it "should return db document using rest call" do
|
234
|
+
data = 'some string'
|
235
|
+
res = mock('HttpResponse')
|
236
|
+
res.stub!(:body).and_return(data)
|
237
|
+
RestClient.stub(:post).and_return(res)
|
238
|
+
RestClient.should_receive(:post).once
|
239
|
+
RhosyncApi::get_db_doc('some_url',@api_token,'abc:abc','string').should == data
|
240
|
+
end
|
241
|
+
|
242
|
+
it "should set db document by doc name and data using direct api call" do
|
243
|
+
data = {'1' => {'foo' => 'bar'}}
|
244
|
+
RhosyncApi::set_db_doc('',@api_token,'abc:abc',data)
|
245
|
+
verify_result('abc:abc' => data)
|
246
|
+
end
|
247
|
+
|
248
|
+
it "should set db document by doc name, data type, and data using direct api call" do
|
249
|
+
data = 'some string'
|
250
|
+
RhosyncApi::set_db_doc('',@api_token,'abc:abc:str',data,'string')
|
251
|
+
verify_result('abc:abc:str' => data)
|
252
|
+
end
|
253
|
+
|
254
|
+
it "should set db document using rest call" do
|
255
|
+
data = 'some string'
|
256
|
+
RestClient.stub(:post)
|
257
|
+
RestClient.should_receive(:post).once
|
258
|
+
RhosyncApi::set_db_doc('some_url',@api_token,'abc:abc:str',data,'string')
|
259
|
+
end
|
260
|
+
|
261
|
+
it "should reset and re-create rhoadmin user with bootstrap using direct api call" do
|
262
|
+
Store.put_data('somedoc',{'foo'=>'bar'})
|
263
|
+
RhosyncApi::reset('',@api_token).should == "DB reset"
|
264
|
+
App.is_exist?(@test_app_name).should == true
|
265
|
+
Store.get_data('somedoc').should == {}
|
266
|
+
User.authenticate('rhoadmin','').should_not be_nil
|
267
|
+
end
|
268
|
+
|
269
|
+
it "should reset db using rest call" do
|
270
|
+
RestClient.stub(:post).and_return("DB reset")
|
271
|
+
RestClient.should_receive(:post).once
|
272
|
+
RhosyncApi::reset('some_url',@api_token).should == "DB reset"
|
273
|
+
end
|
274
|
+
|
275
|
+
it "should do ping asynchronously using direct api call" do
|
276
|
+
params = {"user_id" => @u.id, "api_token" => @api_token,
|
277
|
+
"async" => "true","sources" => [@s.name], "message" => 'hello world',
|
278
|
+
"vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3'}
|
279
|
+
PingJob.should_receive(:enqueue).once.with(params)
|
280
|
+
RhosyncApi::ping('',@api_token,@u.id,params)
|
281
|
+
end
|
282
|
+
|
283
|
+
it "should do ping using rest call" do
|
284
|
+
RestClient.stub(:post)
|
285
|
+
RestClient.should_receive(:post).once
|
286
|
+
RhosyncApi::ping('some_url',@api_token,@u.id,{})
|
287
|
+
end
|
288
|
+
|
289
|
+
it "should get license info using direct api call" do
|
290
|
+
RhosyncApi::get_license_info('',@api_token).should == {
|
291
|
+
"available" => 9,
|
292
|
+
"issued" => "Fri Apr 23 17:20:13 -0700 2010",
|
293
|
+
"seats" => 10,
|
294
|
+
"rhosync_version" => "Version 1",
|
295
|
+
"licensee" => "Rhomobile" }
|
296
|
+
end
|
297
|
+
|
298
|
+
it "should get license info using rest call" do
|
299
|
+
res = mock('HttpResponse')
|
300
|
+
res.stub!(:body).and_return(['data'].to_json)
|
301
|
+
RestClient.stub(:post).and_return(res)
|
302
|
+
RestClient.should_receive(:post).once
|
303
|
+
RhosyncApi::get_license_info('some_url',@api_token)
|
304
|
+
end
|
305
|
+
|
306
|
+
end
|
data/spec/doc/doc_spec.rb
CHANGED
@@ -23,7 +23,7 @@ describe "Protocol" do
|
|
23
23
|
Rhosync.bootstrap(get_testapp_path) do |rhosync|
|
24
24
|
rhosync.vendor_directory = File.join(rhosync.base_directory,'..','..','..','vendor')
|
25
25
|
end
|
26
|
-
Server.set(
|
26
|
+
Rhosync::Server.set(
|
27
27
|
:environment => :test,
|
28
28
|
:run => false,
|
29
29
|
:secret => "secure!"
|
@@ -37,7 +37,7 @@ describe "Protocol" do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def app
|
40
|
-
@app ||= Server.new
|
40
|
+
@app ||= Rhosync::Server.new
|
41
41
|
end
|
42
42
|
|
43
43
|
after(:each) do
|
data/spec/model_spec.rb
CHANGED
@@ -187,6 +187,10 @@ describe Rhosync::Model do
|
|
187
187
|
@x.set_date.diff('x', 'y')[0].should be_kind_of(DateTime)
|
188
188
|
end
|
189
189
|
|
190
|
+
it "should handle empty members" do
|
191
|
+
@xRedisMock.stub!(:smembers).and_return(nil)
|
192
|
+
@x.set_date.members.should == []
|
193
|
+
end
|
190
194
|
end
|
191
195
|
|
192
196
|
context "increment/decrement" do
|
data/spec/server/server_spec.rb
CHANGED
@@ -20,17 +20,17 @@ describe "Server" do
|
|
20
20
|
Rhosync.bootstrap(get_testapp_path) do |rhosync|
|
21
21
|
rhosync.vendor_directory = File.join(rhosync.base_directory,'..','..','..','vendor')
|
22
22
|
end
|
23
|
-
Server.set(
|
23
|
+
Rhosync::Server.set(
|
24
24
|
:environment => :test,
|
25
25
|
:run => false,
|
26
26
|
:secret => "secure!"
|
27
27
|
)
|
28
|
-
Server.use Rack::Static, :urls => ["/data"],
|
28
|
+
Rhosync::Server.use Rack::Static, :urls => ["/data"],
|
29
29
|
:root => File.expand_path(File.join(File.dirname(__FILE__),'..','apps','rhotestapp'))
|
30
30
|
end
|
31
31
|
|
32
32
|
def app
|
33
|
-
@app ||= Server.new
|
33
|
+
@app ||= Rhosync::Server.new
|
34
34
|
end
|
35
35
|
|
36
36
|
it "should show status page" do
|
@@ -54,20 +54,20 @@ describe "Server" do
|
|
54
54
|
end
|
55
55
|
|
56
56
|
it "should have default session secret" do
|
57
|
-
Server.secret.should == "secure!"
|
57
|
+
Rhosync::Server.secret.should == "secure!"
|
58
58
|
end
|
59
59
|
|
60
60
|
it "should update session secret to default" do
|
61
|
-
Server.set :secret, "<changeme>"
|
62
|
-
Server.secret.should == "<changeme>"
|
63
|
-
Server.should_receive(:log).any_number_of_times.with(any_args())
|
61
|
+
Rhosync::Server.set :secret, "<changeme>"
|
62
|
+
Rhosync::Server.secret.should == "<changeme>"
|
63
|
+
Rhosync::Server.should_receive(:log).any_number_of_times.with(any_args())
|
64
64
|
check_default_secret!("<changeme>")
|
65
|
-
Server.set :secret, "secure!"
|
65
|
+
Rhosync::Server.set :secret, "secure!"
|
66
66
|
end
|
67
67
|
|
68
68
|
it "should complain about hsqldata.jar missing" do
|
69
69
|
Rhosync.vendor_directory = 'missing'
|
70
|
-
Server.should_receive(:log).any_number_of_times.with(any_args())
|
70
|
+
Rhosync::Server.should_receive(:log).any_number_of_times.with(any_args())
|
71
71
|
check_hsql_lib!
|
72
72
|
end
|
73
73
|
|
data/spec/store_spec.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__),'spec_helper')
|
2
2
|
|
3
3
|
describe "Store" do
|
4
|
-
|
4
|
+
|
5
|
+
it_should_behave_like "SpecBootstrapHelper"
|
5
6
|
it_should_behave_like "SourceAdapterHelper"
|
6
7
|
|
7
8
|
describe "store methods" do
|
@@ -10,12 +11,10 @@ describe "Store" do
|
|
10
11
|
end
|
11
12
|
|
12
13
|
it "should set redis connection" do
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
Store.db = ''
|
18
|
-
end
|
14
|
+
Store.db = nil
|
15
|
+
Store.db = 'localhost:6379'
|
16
|
+
Store.db.client.host.should == 'localhost'
|
17
|
+
Store.db.client.port.should == 6379
|
19
18
|
end
|
20
19
|
|
21
20
|
it "should create default redis connection" do
|
@@ -23,10 +22,12 @@ describe "Store" do
|
|
23
22
|
Store.db.class.name.should match(/Redis/)
|
24
23
|
end
|
25
24
|
|
26
|
-
it "should create
|
27
|
-
|
28
|
-
|
29
|
-
Store.db =
|
25
|
+
it "should create redis connection based on ENV" do
|
26
|
+
ENV[REDIS_URL] = 'redis://localhost:6379'
|
27
|
+
Redis.should_receive(:connect).with(:url => 'redis://localhost:6379').and_return { Redis.new }
|
28
|
+
Store.db = nil
|
29
|
+
Store.db.should_not == nil
|
30
|
+
ENV.delete(REDIS_URL)
|
30
31
|
end
|
31
32
|
|
32
33
|
it "should add simple data to new set" do
|
@@ -39,7 +40,7 @@ describe "Store" do
|
|
39
40
|
Store.put_data(@s.docname(:md),@data).should == true
|
40
41
|
Store.get_data(@s.docname(:md),Array).sort.should == @data
|
41
42
|
end
|
42
|
-
|
43
|
+
|
43
44
|
it "should replace simple data to existing set" do
|
44
45
|
new_data,new_data['3'] = {},{'name' => 'Droid','brand' => 'Google'}
|
45
46
|
Store.put_data(@s.docname(:md),@data).should == true
|
@@ -71,7 +72,7 @@ describe "Store" do
|
|
71
72
|
Store.get_data(@c.docname(:cd)).should == @data1
|
72
73
|
Store.get_diff_data(@s.docname(:md),@c.docname(:cd)).should == [expected,1]
|
73
74
|
end
|
74
|
-
|
75
|
+
|
75
76
|
it "should return attributes modified and missed in doc2" do
|
76
77
|
Store.put_data(@s.docname(:md),@data).should == true
|
77
78
|
Store.get_data(@s.docname(:md)).should == @data
|
@@ -84,7 +85,7 @@ describe "Store" do
|
|
84
85
|
Store.get_data(@c.docname(:cd)).should == @data1
|
85
86
|
Store.get_diff_data(@c.docname(:cd),@s.docname(:md)).should == [expected,2]
|
86
87
|
end
|
87
|
-
|
88
|
+
|
88
89
|
it "should ignore reserved attributes" do
|
89
90
|
@newproduct = {
|
90
91
|
'name' => 'iPhone',
|
@@ -116,19 +117,26 @@ describe "Store" do
|
|
116
117
|
it "should lock document" do
|
117
118
|
doc = "locked_data"
|
118
119
|
m_lock = Store.get_lock(doc)
|
119
|
-
|
120
|
+
pid = Process.fork do
|
121
|
+
Store.db = Redis.new
|
120
122
|
t_lock = Store.get_lock(doc)
|
121
123
|
Store.put_data(doc,{'1'=>@product1},true)
|
122
124
|
Store.release_lock(doc,t_lock)
|
125
|
+
Process.exit(0)
|
123
126
|
end
|
124
127
|
Store.put_data(doc,{'2'=>@product2},true)
|
125
128
|
Store.get_data(doc).should == {'2'=>@product2}
|
126
|
-
th.alive?.should == true
|
127
129
|
Store.release_lock(doc,m_lock)
|
128
|
-
|
130
|
+
Process.waitpid(pid)
|
129
131
|
m_lock = Store.get_lock(doc)
|
130
132
|
Store.get_data(doc).should == {'1'=>@product1,'2'=>@product2}
|
131
|
-
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should lock key for timeout" do
|
136
|
+
doc = "locked_data"
|
137
|
+
Store.db.set "#{doc}:lock", Time.now.to_i+3
|
138
|
+
Store.should_receive(:sleep).at_least(:once).with(1).and_return { sleep 1 }
|
139
|
+
m_lock = Store.get_lock(doc,2)
|
132
140
|
end
|
133
141
|
|
134
142
|
it "should lock document in block" do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rhosync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 2.0.
|
9
|
+
- 4
|
10
|
+
version: 2.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Rhomobile
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-08-04 00:00:00 -07:00
|
19
19
|
default_executable: rhosync
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -106,12 +106,12 @@ dependencies:
|
|
106
106
|
requirements:
|
107
107
|
- - ~>
|
108
108
|
- !ruby/object:Gem::Version
|
109
|
-
hash:
|
109
|
+
hash: 15
|
110
110
|
segments:
|
111
|
-
-
|
111
|
+
- 2
|
112
112
|
- 0
|
113
113
|
- 0
|
114
|
-
version:
|
114
|
+
version: 2.0.0
|
115
115
|
type: :runtime
|
116
116
|
version_requirements: *id006
|
117
117
|
- !ruby/object:Gem::Dependency
|
@@ -122,12 +122,12 @@ dependencies:
|
|
122
122
|
requirements:
|
123
123
|
- - ">="
|
124
124
|
- !ruby/object:Gem::Version
|
125
|
-
hash:
|
125
|
+
hash: 61
|
126
126
|
segments:
|
127
127
|
- 1
|
128
|
-
-
|
129
|
-
-
|
130
|
-
version: 1.
|
128
|
+
- 9
|
129
|
+
- 7
|
130
|
+
version: 1.9.7
|
131
131
|
type: :runtime
|
132
132
|
version_requirements: *id007
|
133
133
|
- !ruby/object:Gem::Dependency
|
@@ -448,6 +448,7 @@ files:
|
|
448
448
|
- spec/api/push_deletes_spec.rb
|
449
449
|
- spec/api/push_objects_spec.rb
|
450
450
|
- spec/api/reset_spec.rb
|
451
|
+
- spec/api/rhosync_api_spec.rb
|
451
452
|
- spec/api/set_db_doc_spec.rb
|
452
453
|
- spec/api/set_refresh_time_spec.rb
|
453
454
|
- spec/api/update_user_spec.rb
|
@@ -560,6 +561,7 @@ test_files:
|
|
560
561
|
- spec/api/push_deletes_spec.rb
|
561
562
|
- spec/api/push_objects_spec.rb
|
562
563
|
- spec/api/reset_spec.rb
|
564
|
+
- spec/api/rhosync_api_spec.rb
|
563
565
|
- spec/api/set_db_doc_spec.rb
|
564
566
|
- spec/api/set_refresh_time_spec.rb
|
565
567
|
- spec/api/update_user_spec.rb
|