rhosync 2.0.0.beta2 → 2.0.0.beta3
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 +11 -1
- data/Rakefile +2 -2
- data/doc/protocol.html +83 -83
- data/generators/rhosync.rb +11 -1
- data/generators/templates/application/spec/spec_helper.rb +27 -0
- data/generators/templates/source/source_adapter.rb +1 -1
- data/generators/templates/source/source_spec.rb +25 -0
- data/lib/rhosync/app.rb +1 -3
- data/lib/rhosync/bulk_data/bulk_data.rb +1 -1
- data/lib/rhosync/bulk_data/syncdb.schema +8 -5
- data/lib/rhosync/client_sync.rb +5 -4
- data/lib/rhosync/jobs/bulk_data_job.rb +18 -4
- data/lib/rhosync/server.rb +10 -4
- data/lib/rhosync/source_adapter.rb +23 -19
- data/lib/rhosync/source_sync.rb +1 -2
- data/lib/rhosync/store.rb +5 -2
- data/lib/rhosync/tasks.rb +45 -18
- data/lib/rhosync/test_methods.rb +72 -0
- data/lib/rhosync/version.rb +1 -1
- data/lib/rhosync.rb +15 -6
- data/spec/apps/rhotestapp/application.rb +3 -1
- data/spec/apps/rhotestapp/settings/settings.yml +3 -0
- data/spec/apps/rhotestapp/sources/sample_adapter.rb +8 -3
- data/spec/client_sync_spec.rb +16 -4
- data/spec/generator/generator_spec.rb +11 -7
- data/spec/jobs/bulk_data_job_spec.rb +24 -0
- data/spec/rhosync_spec.rb +1 -0
- data/spec/server/server_spec.rb +23 -4
- data/spec/source_adapter_spec.rb +14 -14
- data/spec/source_sync_spec.rb +9 -0
- data/spec/spec_helper.rb +107 -86
- data/spec/store_spec.rb +11 -0
- data/spec/test_methods_spec.rb +89 -0
- metadata +13 -8
@@ -58,9 +58,14 @@ class SampleAdapter < SourceAdapter
|
|
58
58
|
|
59
59
|
def _read(operation,params)
|
60
60
|
@result = Store.get_data('test_db_storage')
|
61
|
-
|
62
|
-
|
63
|
-
|
61
|
+
if params and params['stash_result']
|
62
|
+
stash_result
|
63
|
+
# @result is nil at this point; if @result is empty then md will be cleared
|
64
|
+
else
|
65
|
+
raise SourceAdapterServerErrorException.new(@result[ERROR]['an_attribute']) if @result[ERROR] and
|
66
|
+
@result[ERROR]['name'] == "#{operation} error"
|
67
|
+
@result.reject! {|key,value| value['name'] != params['name']} if params
|
68
|
+
end
|
64
69
|
@result
|
65
70
|
end
|
66
71
|
end
|
data/spec/client_sync_spec.rb
CHANGED
@@ -351,7 +351,7 @@ describe "ClientSync" do
|
|
351
351
|
"class"=>"Rhosync::BulkDataJob"}
|
352
352
|
end
|
353
353
|
|
354
|
-
it "should create bulk data job app partition if none exists and no
|
354
|
+
it "should create bulk data job app partition if none exists and no partition sources" do
|
355
355
|
ClientSync.bulk_data(:app,@c).should == {:result => :nop}
|
356
356
|
Resque.peek(:bulk_data).should == nil
|
357
357
|
end
|
@@ -369,7 +369,7 @@ describe "ClientSync" do
|
|
369
369
|
ClientSync.bulk_data(:user,@c)
|
370
370
|
BulkDataJob.perform("data_name" => bulk_data_docname(@a.id,@u.id))
|
371
371
|
ClientSync.bulk_data(:user,@c).should == {:result => :url,
|
372
|
-
:url => BulkData.load(bulk_data_docname(@a.id,@u.id)).
|
372
|
+
:url => BulkData.load(bulk_data_docname(@a.id,@u.id)).url}
|
373
373
|
verify_result(
|
374
374
|
"client:#{@a_fields[:name]}:#{@u_fields[:login]}:#{@c.id}:#{@s_fields[:name]}:cd" => @data,
|
375
375
|
"source:#{@a_fields[:name]}:#{@u_fields[:login]}:#{@s_fields[:name]}:md" => @data,
|
@@ -382,7 +382,7 @@ describe "ClientSync" do
|
|
382
382
|
ClientSync.bulk_data(:app,@c)
|
383
383
|
BulkDataJob.perform("data_name" => bulk_data_docname(@a.id,"*"))
|
384
384
|
ClientSync.bulk_data(:app,@c).should == {:result => :url,
|
385
|
-
:url => BulkData.load(bulk_data_docname(@a.id,"*")).
|
385
|
+
:url => BulkData.load(bulk_data_docname(@a.id,"*")).url}
|
386
386
|
verify_result(
|
387
387
|
"client:#{@a_fields[:name]}:#{@u_fields[:login]}:#{@c.id}:#{@s_fields[:name]}:cd" => @data,
|
388
388
|
"source:#{@a_fields[:name]}:__shared__:#{@s_fields[:name]}:md" => @data,
|
@@ -395,11 +395,23 @@ describe "ClientSync" do
|
|
395
395
|
ClientSync.bulk_data(:user,@c)
|
396
396
|
BulkDataJob.perform("data_name" => bulk_data_docname(@a.id,@u.id))
|
397
397
|
ClientSync.bulk_data(:user,@c).should == {:result => :url,
|
398
|
-
:url => BulkData.load(bulk_data_docname(@a.id,@u.id)).
|
398
|
+
:url => BulkData.load(bulk_data_docname(@a.id,@u.id)).url}
|
399
399
|
verify_result(
|
400
400
|
"client:#{@a_fields[:name]}:#{@u_fields[:login]}:#{@c.id}:#{@s_fields[:name]}:cd" => {},
|
401
401
|
"source:#{@a_fields[:name]}:#{@u_fields[:login]}:#{@s_fields[:name]}:md" => @data,
|
402
402
|
"source:#{@a_fields[:name]}:#{@u_fields[:login]}:#{@s_fields[:name]}:md_copy" => {})
|
403
403
|
end
|
404
|
+
|
405
|
+
it "should create bulk data job if no file exists" do
|
406
|
+
set_state('test_db_storage' => @data)
|
407
|
+
ClientSync.bulk_data(:user,@c)
|
408
|
+
BulkDataJob.perform("data_name" => bulk_data_docname(@a.id,@u.id))
|
409
|
+
data = BulkData.load(bulk_data_docname(@a.id,@u.id))
|
410
|
+
ClientSync.bulk_data(:user,@c).should == {:result => :url, :url => data.url}
|
411
|
+
File.delete(data.dbfile)
|
412
|
+
ClientSync.bulk_data(:user,@c).should == {:result => :wait}
|
413
|
+
Resque.peek(:bulk_data).should == {"args"=>
|
414
|
+
[{"data_name"=>bulk_data_docname(@a.id,@u.id)}], "class"=>"Rhosync::BulkDataJob"}
|
415
|
+
end
|
404
416
|
end
|
405
417
|
end
|
@@ -5,8 +5,8 @@ describe "Generator" do
|
|
5
5
|
source = 'mysource'
|
6
6
|
path = File.expand_path(File.join(File.dirname(__FILE__)))
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
before(:each) do
|
9
|
+
FileUtils.mkdir_p '/tmp'
|
10
10
|
end
|
11
11
|
|
12
12
|
describe "AppGenerator" do
|
@@ -26,7 +26,8 @@ describe "Generator" do
|
|
26
26
|
"application.rb",
|
27
27
|
'settings/settings.yml',
|
28
28
|
'settings/license.key',
|
29
|
-
'Rakefile'
|
29
|
+
'Rakefile',
|
30
|
+
'spec/spec_helper.rb'
|
30
31
|
].each do |template|
|
31
32
|
@generator.should create("/tmp/#{appname}/#{template}")
|
32
33
|
end
|
@@ -41,12 +42,15 @@ describe "Generator" do
|
|
41
42
|
end
|
42
43
|
|
43
44
|
before(:each) do
|
44
|
-
|
45
|
+
FileUtils.rm_rf "/tmp/#{appname}"
|
46
|
+
@app_generator = Rhosync::AppGenerator.new('/tmp',{},appname)
|
47
|
+
@app_generator.invoke!
|
48
|
+
@generator = Rhosync::SourceGenerator.new("/tmp/#{appname}",{},source)
|
45
49
|
end
|
46
50
|
|
47
|
-
it "should create new source adapter" do
|
48
|
-
|
49
|
-
@generator.should create("/tmp/sources/#{source}.rb")
|
51
|
+
it "should create new source adapter and spec" do
|
52
|
+
@generator.should create("/tmp/#{appname}/sources/#{source}.rb")
|
53
|
+
@generator.should create("/tmp/#{appname}/spec/sources/#{source}_spec.rb")
|
50
54
|
end
|
51
55
|
end
|
52
56
|
|
@@ -26,9 +26,14 @@ describe "BulkDataJob" do
|
|
26
26
|
data.completed?.should == true
|
27
27
|
verify_result(@s.docname(:md) => @data,@s.docname(:md_copy) => @data)
|
28
28
|
validate_db(data,@data).should == true
|
29
|
+
File.exists?(data.dbfile+'.rzip').should == true
|
29
30
|
File.exists?(data.dbfile+'.hsqldb.data').should == true
|
30
31
|
File.exists?(data.dbfile+'.hsqldb.script').should == true
|
31
32
|
File.exists?(data.dbfile+'.hsqldb.properties').should == true
|
33
|
+
path = File.join(File.dirname(data.dbfile),'tmp')
|
34
|
+
FileUtils.mkdir_p path
|
35
|
+
unzip_file("#{data.dbfile}.rzip",path)
|
36
|
+
validate_db_by_name(File.join(path,File.basename(data.dbfile)),@data)
|
32
37
|
end
|
33
38
|
|
34
39
|
it "should not create hsql db files if blackberry_bulk_sync is disabled" do
|
@@ -49,6 +54,25 @@ describe "BulkDataJob" do
|
|
49
54
|
File.exists?(data.dbfile+'.hsqldb.properties').should == false
|
50
55
|
end
|
51
56
|
|
57
|
+
it "should create sqlite data with source metadata" do
|
58
|
+
set_state('test_db_storage' => @data)
|
59
|
+
mock_metadata_method([SampleAdapter]) do
|
60
|
+
docname = bulk_data_docname(@a.id,@u.id)
|
61
|
+
data = BulkData.create(:name => docname,
|
62
|
+
:state => :inprogress,
|
63
|
+
:app_id => @a.id,
|
64
|
+
:user_id => @u.id,
|
65
|
+
:sources => [@s_fields[:name]])
|
66
|
+
BulkDataJob.perform("data_name" => data.name)
|
67
|
+
data = BulkData.load(docname)
|
68
|
+
data.completed?.should == true
|
69
|
+
verify_result(@s.docname(:md) => @data,
|
70
|
+
@s.docname(:metadata) => {'foo'=>'bar'}.to_json,
|
71
|
+
@s.docname(:md_copy) => @data)
|
72
|
+
validate_db(data,@data).should == true
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
52
76
|
it "should raise exception if hsqldata fails" do
|
53
77
|
data = BulkData.create(:name => bulk_data_docname(@a.id,@u.id),
|
54
78
|
:state => :inprogress,
|
data/spec/rhosync_spec.rb
CHANGED
@@ -14,6 +14,7 @@ describe "Rhosync" do
|
|
14
14
|
File.expand_path(Rhosync.data_directory).should == File.join(path,'data')
|
15
15
|
Rhosync.vendor_directory.should == 'foo'
|
16
16
|
Rhosync.blackberry_bulk_sync.should == false
|
17
|
+
Rhosync.bulk_sync_poll_interval.should == 3600
|
17
18
|
Rhosync.environment.should == :development
|
18
19
|
App.is_exist?(@test_app_name).should be_true
|
19
20
|
end
|
data/spec/server/server_spec.rb
CHANGED
@@ -43,6 +43,11 @@ describe "Server" do
|
|
43
43
|
last_response.should be_ok
|
44
44
|
end
|
45
45
|
|
46
|
+
it "should login as admin user" do
|
47
|
+
post "/login", "login" => 'admin', "password" => ''
|
48
|
+
last_response.should be_ok
|
49
|
+
end
|
50
|
+
|
46
51
|
it "should respond with 401 to /:app_name" do
|
47
52
|
get "/application"
|
48
53
|
last_response.status.should == 401
|
@@ -83,9 +88,22 @@ describe "Server" do
|
|
83
88
|
last_response.should be_ok
|
84
89
|
end
|
85
90
|
|
86
|
-
it "should
|
91
|
+
it "should return 401 and LoginException messsage from authenticate" do
|
87
92
|
do_post "/application/clientlogin", "login" => @u.login, "password" => 'wrongpass'
|
88
93
|
last_response.status.should == 401
|
94
|
+
last_response.body.should == 'login exception'
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should return 500 and Exception messsage from authenticate" do
|
98
|
+
do_post "/application/clientlogin", "login" => @u.login, "password" => 'server error'
|
99
|
+
last_response.status.should == 500
|
100
|
+
last_response.body.should == 'server error'
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should return 401 and no messsage from authenticate if no exception raised" do
|
104
|
+
do_post "/application/clientlogin", "login" => @u.login, "password" => 'wrongpassnomsg'
|
105
|
+
last_response.status.should == 401
|
106
|
+
last_response.body.should == ''
|
89
107
|
end
|
90
108
|
|
91
109
|
it "should create unknown user through delegated authentication" do
|
@@ -286,9 +304,10 @@ describe "Server" do
|
|
286
304
|
BulkDataJob.perform("data_name" => bulk_data_docname(@a.id,@u.id))
|
287
305
|
get "/application/bulk_data", :partition => :user, :client_id => @c.id
|
288
306
|
last_response.should be_ok
|
307
|
+
data = BulkData.load(bulk_data_docname(@a.id,@u.id))
|
289
308
|
last_response.body.should == {:result => :url,
|
290
|
-
:url =>
|
291
|
-
validate_db_by_name(
|
309
|
+
:url => data.url}.to_json
|
310
|
+
validate_db_by_name(data.dbfile,@data)
|
292
311
|
end
|
293
312
|
|
294
313
|
it "should download bulk data file" do
|
@@ -296,7 +315,7 @@ describe "Server" do
|
|
296
315
|
get "/application/bulk_data", :partition => :user, :client_id => @c.id
|
297
316
|
BulkDataJob.perform("data_name" => bulk_data_docname(@a.id,@u.id))
|
298
317
|
get "/application/bulk_data", :partition => :user, :client_id => @c.id
|
299
|
-
get
|
318
|
+
get JSON.parse(last_response.body)["url"]
|
300
319
|
last_response.should be_ok
|
301
320
|
File.open('test.data','wb') {|f| f.puts last_response.body}
|
302
321
|
validate_db_by_name('test.data',@data)
|
data/spec/source_adapter_spec.rb
CHANGED
@@ -4,6 +4,11 @@ class Rhosync::SourceAdapter
|
|
4
4
|
def inject_result(result)
|
5
5
|
@result = result
|
6
6
|
end
|
7
|
+
|
8
|
+
def inject_tmpdoc(docname)
|
9
|
+
@tmp_docname = docname
|
10
|
+
@stash_size = 0
|
11
|
+
end
|
7
12
|
end
|
8
13
|
|
9
14
|
describe "SourceAdapter" do
|
@@ -50,12 +55,6 @@ describe "SourceAdapter" do
|
|
50
55
|
@sa.query.should == expected
|
51
56
|
end
|
52
57
|
|
53
|
-
it "should execute SourceAdapter query method" do
|
54
|
-
expected = {'1'=>@product1,'2'=>@product2}
|
55
|
-
@sa.inject_result expected
|
56
|
-
@sa.query.should == expected
|
57
|
-
end
|
58
|
-
|
59
58
|
it "should execute SourceAdapter search method and modify params" do
|
60
59
|
params = {:hello => 'world'}
|
61
60
|
expected = {'1'=>@product1,'2'=>@product2}
|
@@ -72,8 +71,7 @@ describe "SourceAdapter" do
|
|
72
71
|
it "should execute SourceAdapter sync method" do
|
73
72
|
expected = {'1'=>@product1,'2'=>@product2}
|
74
73
|
@sa.inject_result expected
|
75
|
-
@sa.
|
76
|
-
@sa.sync
|
74
|
+
@sa.do_query
|
77
75
|
Store.get_data(@s.docname(:md)).should == expected
|
78
76
|
Store.get_value(@s.docname(:md_size)).to_i.should == 2
|
79
77
|
end
|
@@ -85,10 +83,10 @@ describe "SourceAdapter" do
|
|
85
83
|
|
86
84
|
it "should reset count if @result is empty" do
|
87
85
|
@sa.inject_result({'1'=>@product1,'2'=>@product2})
|
88
|
-
@sa.
|
86
|
+
@sa.do_query
|
89
87
|
Store.get_value(@s.docname(:md_size)).to_i.should == 2
|
90
88
|
@sa.inject_result({})
|
91
|
-
@sa.
|
89
|
+
@sa.do_query
|
92
90
|
Store.get_value(@s.docname(:md_size)).to_i.should == 0
|
93
91
|
end
|
94
92
|
|
@@ -96,10 +94,12 @@ describe "SourceAdapter" do
|
|
96
94
|
@sa.create(@product4).should == 'obj4'
|
97
95
|
end
|
98
96
|
|
99
|
-
it "should
|
100
|
-
|
101
|
-
@sa.inject_result
|
102
|
-
@sa.
|
97
|
+
it "should stash @result in store and set it to nil" do
|
98
|
+
expected = {'1'=>@product1,'2'=>@product2}
|
99
|
+
@sa.inject_result(expected)
|
100
|
+
@sa.inject_tmpdoc('tmpdoc')
|
101
|
+
@sa.stash_result
|
102
|
+
Store.get_data('tmpdoc').should == expected
|
103
103
|
end
|
104
104
|
|
105
105
|
describe "SourceAdapter metadata method" do
|
data/spec/source_sync_spec.rb
CHANGED
@@ -72,6 +72,15 @@ describe "SourceSync" do
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
+
it "should process source adapter with stash" do
|
76
|
+
expected = {'1'=>@product1,'2'=>@product2}
|
77
|
+
set_state('test_db_storage' => expected)
|
78
|
+
#@ss.adapter.should_receive(:stash_result).once
|
79
|
+
@ss.process_query('stash_result' => true)
|
80
|
+
verify_result(@s.docname(:md) => expected,
|
81
|
+
@s.docname(:md_size) => expected.size.to_s)
|
82
|
+
end
|
83
|
+
|
75
84
|
it "should call methods in source adapter" do
|
76
85
|
mock_metadata_method([SampleAdapter, SimpleAdapter]) do
|
77
86
|
expected = {'1'=>@product1,'2'=>@product2}
|
data/spec/spec_helper.rb
CHANGED
@@ -2,94 +2,12 @@ require 'rubygems'
|
|
2
2
|
require 'rhosync'
|
3
3
|
include Rhosync
|
4
4
|
|
5
|
-
|
6
|
-
before(:each) do
|
7
|
-
Store.create
|
8
|
-
Store.db.flushdb
|
9
|
-
end
|
10
|
-
end
|
5
|
+
ERROR = '0_broken_object_id' unless defined? ERROR
|
11
6
|
|
12
|
-
|
13
|
-
before(:all) do
|
14
|
-
@test_app_name = 'application'
|
15
|
-
end
|
7
|
+
module TestHelpers
|
16
8
|
def get_testapp_path
|
17
9
|
File.expand_path(File.join(File.dirname(__FILE__),'apps','rhotestapp'))
|
18
10
|
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "RhosyncDataHelper", :shared => true do
|
22
|
-
it_should_behave_like "RhosyncHelper"
|
23
|
-
it_should_behave_like "TestappHelper"
|
24
|
-
|
25
|
-
before(:each) do
|
26
|
-
@source = 'Product'
|
27
|
-
@user_id = 5
|
28
|
-
@client_id = 1
|
29
|
-
|
30
|
-
@product1 = {
|
31
|
-
'name' => 'iPhone',
|
32
|
-
'brand' => 'Apple',
|
33
|
-
'price' => '199.99'
|
34
|
-
}
|
35
|
-
|
36
|
-
@product2 = {
|
37
|
-
'name' => 'G2',
|
38
|
-
'brand' => 'Android',
|
39
|
-
'price' => '99.99'
|
40
|
-
}
|
41
|
-
|
42
|
-
@product3 = {
|
43
|
-
'name' => 'Fuze',
|
44
|
-
'brand' => 'HTC',
|
45
|
-
'price' => '299.99'
|
46
|
-
}
|
47
|
-
|
48
|
-
@product4 = {
|
49
|
-
'name' => 'Droid',
|
50
|
-
'brand' => 'Android',
|
51
|
-
'price' => '249.99'
|
52
|
-
}
|
53
|
-
|
54
|
-
@data = {'1'=>@product1,'2'=>@product2,'3'=>@product3}
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe "DBObjectsHelper", :shared => true do
|
59
|
-
|
60
|
-
ERROR = '0_broken_object_id' unless defined? ERROR
|
61
|
-
|
62
|
-
before(:each) do
|
63
|
-
@a_fields = { :name => @test_app_name }
|
64
|
-
# @a = App.create(@a_fields)
|
65
|
-
@a = (App.load(@test_app_name) || App.create(@a_fields))
|
66
|
-
@u_fields = {:login => 'testuser'}
|
67
|
-
@u = User.create(@u_fields)
|
68
|
-
@u.password = 'testpass'
|
69
|
-
@c_fields = {
|
70
|
-
:device_type => 'iPhone',
|
71
|
-
:device_pin => 'abcd',
|
72
|
-
:device_port => '3333',
|
73
|
-
:user_id => @u.id,
|
74
|
-
:app_id => @a.id
|
75
|
-
}
|
76
|
-
@s_fields = {
|
77
|
-
:name => 'SampleAdapter',
|
78
|
-
:url => 'http://example.com',
|
79
|
-
:login => 'testuser',
|
80
|
-
:password => 'testpass',
|
81
|
-
}
|
82
|
-
@s_params = {
|
83
|
-
:user_id => @u.id,
|
84
|
-
:app_id => @a.id
|
85
|
-
}
|
86
|
-
@c = Client.create(@c_fields,{:source_name => @s_fields[:name]})
|
87
|
-
@s = Source.load(@s_fields[:name],@s_params)
|
88
|
-
@s = Source.create(@s_fields,@s_params) if @s.nil?
|
89
|
-
@r = @s.read_state
|
90
|
-
@a.sources << @s.id
|
91
|
-
@a.users << @u.id
|
92
|
-
end
|
93
11
|
|
94
12
|
def do_post(url,params)
|
95
13
|
post url, params.to_json, {'CONTENT_TYPE'=>'application/json'}
|
@@ -184,8 +102,14 @@ describe "DBObjectsHelper", :shared => true do
|
|
184
102
|
|
185
103
|
def validate_db_by_name(name,data)
|
186
104
|
db = SQLite3::Database.new(name)
|
187
|
-
db.execute("select
|
188
|
-
return false if row
|
105
|
+
db.execute("select source_id,name,sync_priority,partition,sync_type,source_attribs,metadata from sources").each do |row|
|
106
|
+
return false if row[0] != @s.source_id.to_s
|
107
|
+
return false if row[1] != @s.name
|
108
|
+
return false if row[2] != @s.priority.to_s
|
109
|
+
return false if row[3] != @s.partition_type.to_s
|
110
|
+
return false if row[4] != @s.sync_type.to_s
|
111
|
+
return false if row[5] != get_attrib_counter(data)
|
112
|
+
return false if row[6] != @s.get_value(:metadata)
|
189
113
|
end
|
190
114
|
db.execute("select * from object_values").each do |row|
|
191
115
|
object = data[row[2]]
|
@@ -215,6 +139,103 @@ describe "DBObjectsHelper", :shared => true do
|
|
215
139
|
klass.class_eval "def metadata; end"
|
216
140
|
end
|
217
141
|
end
|
142
|
+
|
143
|
+
def unzip_file(file,file_dir)
|
144
|
+
Zip::ZipFile.open(file) do |zip_file|
|
145
|
+
zip_file.each do |f|
|
146
|
+
f_path = File.join(file_dir,f.name)
|
147
|
+
FileUtils.mkdir_p(File.dirname(f_path))
|
148
|
+
zip_file.extract(f, f_path) { true }
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end #TestHelpers
|
153
|
+
|
154
|
+
describe "RhosyncHelper", :shared => true do
|
155
|
+
before(:each) do
|
156
|
+
Store.create
|
157
|
+
Store.db.flushdb
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
describe "TestappHelper", :shared => true do
|
162
|
+
include TestHelpers
|
163
|
+
before(:all) do
|
164
|
+
@test_app_name = 'application'
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
describe "RhosyncDataHelper", :shared => true do
|
169
|
+
it_should_behave_like "RhosyncHelper"
|
170
|
+
it_should_behave_like "TestappHelper"
|
171
|
+
|
172
|
+
before(:each) do
|
173
|
+
@source = 'Product'
|
174
|
+
@user_id = 5
|
175
|
+
@client_id = 1
|
176
|
+
|
177
|
+
@product1 = {
|
178
|
+
'name' => 'iPhone',
|
179
|
+
'brand' => 'Apple',
|
180
|
+
'price' => '199.99'
|
181
|
+
}
|
182
|
+
|
183
|
+
@product2 = {
|
184
|
+
'name' => 'G2',
|
185
|
+
'brand' => 'Android',
|
186
|
+
'price' => '99.99'
|
187
|
+
}
|
188
|
+
|
189
|
+
@product3 = {
|
190
|
+
'name' => 'Fuze',
|
191
|
+
'brand' => 'HTC',
|
192
|
+
'price' => '299.99'
|
193
|
+
}
|
194
|
+
|
195
|
+
@product4 = {
|
196
|
+
'name' => 'Droid',
|
197
|
+
'brand' => 'Android',
|
198
|
+
'price' => '249.99'
|
199
|
+
}
|
200
|
+
|
201
|
+
@data = {'1'=>@product1,'2'=>@product2,'3'=>@product3}
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
describe "DBObjectsHelper", :shared => true do
|
206
|
+
include TestHelpers
|
207
|
+
|
208
|
+
before(:each) do
|
209
|
+
@a_fields = { :name => @test_app_name }
|
210
|
+
# @a = App.create(@a_fields)
|
211
|
+
@a = (App.load(@test_app_name) || App.create(@a_fields))
|
212
|
+
@u_fields = {:login => 'testuser'}
|
213
|
+
@u = User.create(@u_fields)
|
214
|
+
@u.password = 'testpass'
|
215
|
+
@c_fields = {
|
216
|
+
:device_type => 'iPhone',
|
217
|
+
:device_pin => 'abcd',
|
218
|
+
:device_port => '3333',
|
219
|
+
:user_id => @u.id,
|
220
|
+
:app_id => @a.id
|
221
|
+
}
|
222
|
+
@s_fields = {
|
223
|
+
:name => 'SampleAdapter',
|
224
|
+
:url => 'http://example.com',
|
225
|
+
:login => 'testuser',
|
226
|
+
:password => 'testpass',
|
227
|
+
}
|
228
|
+
@s_params = {
|
229
|
+
:user_id => @u.id,
|
230
|
+
:app_id => @a.id
|
231
|
+
}
|
232
|
+
@c = Client.create(@c_fields,{:source_name => @s_fields[:name]})
|
233
|
+
@s = Source.load(@s_fields[:name],@s_params)
|
234
|
+
@s = Source.create(@s_fields,@s_params) if @s.nil?
|
235
|
+
@r = @s.read_state
|
236
|
+
@a.sources << @s.id
|
237
|
+
@a.users << @u.id
|
238
|
+
end
|
218
239
|
end
|
219
240
|
|
220
241
|
describe "SourceAdapterHelper", :shared => true do
|
data/spec/store_spec.rb
CHANGED
@@ -18,6 +18,17 @@ describe "Store" do
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
+
it "should create default redis connection" do
|
22
|
+
Store.db = nil
|
23
|
+
Store.db.class.name.should match(/Redis/)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should create Redis::Distributed if redis array is provided" do
|
27
|
+
Store.db = ['localhost:5555','localhost:5556']
|
28
|
+
Store.db.class.should == Redis::Distributed
|
29
|
+
Store.db = ''
|
30
|
+
end
|
31
|
+
|
21
32
|
it "should add simple data to new set" do
|
22
33
|
Store.put_data(@s.docname(:md),@data).should == true
|
23
34
|
Store.get_data(@s.docname(:md)).should == @data
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'rhosync/test_methods'
|
2
|
+
require File.join(File.dirname(__FILE__),'spec_helper')
|
3
|
+
|
4
|
+
describe "TestMethods" do
|
5
|
+
include TestHelpers
|
6
|
+
|
7
|
+
it_should_behave_like "RhosyncHelper"
|
8
|
+
it_should_behave_like "RhosyncDataHelper"
|
9
|
+
|
10
|
+
# The module we're testing
|
11
|
+
include Rhosync::TestMethods
|
12
|
+
|
13
|
+
before(:each) do
|
14
|
+
Rhosync.bootstrap(get_testapp_path)
|
15
|
+
setup_test_for(SampleAdapter,'user1')
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should setup_test_for an adapter and user" do
|
19
|
+
@u.is_a?(User).should == true
|
20
|
+
@s.is_a?(Source).should == true
|
21
|
+
@ss.is_a?(SourceSync).should == true
|
22
|
+
@ss.adapter.is_a?(SampleAdapter).should == true
|
23
|
+
@u.login.should == 'user1'
|
24
|
+
@s.name.should == 'SampleAdapter'
|
25
|
+
@c.id.size.should == 32
|
26
|
+
@c.device_pin.should == 'abcd'
|
27
|
+
@c.device_port.should == '3333'
|
28
|
+
@c.device_type.should == 'iPhone'
|
29
|
+
@c.user_id.should == 'user1'
|
30
|
+
@c.app_id.should == 'application'
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should include test_query helper" do
|
34
|
+
expected = {'1'=>@product1,'2'=>@product2}
|
35
|
+
set_state('test_db_storage' => expected)
|
36
|
+
test_query.should == expected
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should include query_errors helper" do
|
40
|
+
expected = {"query-error"=>{'message'=>'failed'}}
|
41
|
+
set_state(@s.docname(:errors) => expected)
|
42
|
+
query_errors.should == expected
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should include test_create helper" do
|
46
|
+
@product4['link'] = 'test link'
|
47
|
+
test_create(@product4).should == 'backend_id'
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should include create_errors helper" do
|
51
|
+
expected = {"create-error"=>{'message'=>'failed'}}
|
52
|
+
set_state(@c.docname(:create_errors) => expected)
|
53
|
+
create_errors.should == expected
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should include test_update helper" do
|
57
|
+
record = {'4'=> { 'price' => '199.99' }}
|
58
|
+
test_update(record)
|
59
|
+
verify_result(@c.docname(:update) => {})
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should include update_errors helper" do
|
63
|
+
expected = {"update-error"=>{'message'=>'failed'}}
|
64
|
+
set_state(@c.docname(:update_errors) => expected)
|
65
|
+
update_errors.should == expected
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should include test_delete helper" do
|
69
|
+
record = {'4'=> { 'price' => '199.99' }}
|
70
|
+
test_delete(record)
|
71
|
+
verify_result(@c.docname(:delete) => {})
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should include delete_errors helper" do
|
75
|
+
expected = {"delete-error"=>{'message'=>'failed'}}
|
76
|
+
set_state(@c.docname(:delete_errors) => expected)
|
77
|
+
delete_errors.should == expected
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should include md helper" do
|
81
|
+
set_state(@s.docname(:md) => @data)
|
82
|
+
md.should == @data
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should include cd helper" do
|
86
|
+
set_state(@c.docname(:cd) => @data)
|
87
|
+
cd.should == @data
|
88
|
+
end
|
89
|
+
end
|