rhoconnect 3.2.1 → 3.3.1.beta2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +24 -5
- data/Gemfile +2 -2
- data/Gemfile.lock +20 -20
- data/bench/benchapp/Gemfile +17 -20
- data/bench/benchapp/config.ru +2 -2
- data/bench/benchapp/settings/settings.yml +3 -3
- data/bench/blobapp/Gemfile +16 -13
- data/bench/blobapp/config.ru +2 -2
- data/bench/blobapp/settings/settings.yml +5 -3
- data/bench/lib/bench.rb +35 -32
- data/bench/lib/bench/session.rb +9 -1
- data/bench/scripts/blob_cud_script.rb +13 -17
- data/bench/scripts/cud_script.rb +11 -12
- data/bench/scripts/helpers.rb +5 -7
- data/bench/scripts/query_md_script.rb +18 -12
- data/bench/scripts/query_only_script.rb +19 -11
- data/bench/scripts/query_script.rb +17 -13
- data/bench/scripts/test_query_script.rb +46 -17
- data/bench/scripts/test_source_script.rb +7 -7
- data/commands/commands/dtach_commands/dtach_install.rb +44 -16
- data/commands/commands/rhoconnect/spec.rb +13 -9
- data/commands/commands/rhoconnect/version.rb +6 -0
- data/commands/execute.rb +10 -6
- data/doc/deploying.txt +75 -13
- data/doc/install.txt +3 -3
- data/doc/push-client-setup.txt +1 -1
- data/doc/rest-api.txt +4 -23
- data/doc/rhoconnect-redis-stack.txt +26 -7
- data/doc/settings.txt +9 -3
- data/examples/simple/Gemfile +3 -1
- data/examples/simple/application.rb +5 -0
- data/examples/simple/config.ru +3 -2
- data/examples/simple/my_server.rb +14 -0
- data/examples/simple/settings/settings.yml +1 -0
- data/generators/templates/application/Gemfile +4 -4
- data/generators/templates/application/application.rb +4 -0
- data/generators/templates/application/settings/settings.yml +4 -1
- data/installer/unix-like/create_texts.rb +39 -1
- data/installer/unix-like/rho_connect_install_constants.rb +1 -1
- data/installer/utils/package_upload/repos.rake +7 -5
- data/lib/rhoconnect.rb +3 -2
- data/lib/rhoconnect/api/app/ans_login.rb +3 -0
- data/lib/rhoconnect/api/app/bulk_data.rb +6 -0
- data/lib/rhoconnect/api/{source → app}/fast_delete.rb +1 -1
- data/lib/rhoconnect/api/{source → app}/fast_insert.rb +2 -2
- data/lib/rhoconnect/api/{source → app}/fast_update.rb +2 -2
- data/lib/rhoconnect/api/app/login.rb +5 -0
- data/lib/rhoconnect/api/{source → app}/push_deletes.rb +1 -1
- data/lib/rhoconnect/api/{source → app}/push_objects.rb +1 -1
- data/lib/rhoconnect/api/app/query.rb +4 -0
- data/lib/rhoconnect/api/app/queue_updates.rb +94 -0
- data/lib/rhoconnect/api/app/search.rb +4 -0
- data/lib/rhoconnect/api/client/client_get_db_doc.rb +5 -0
- data/lib/rhoconnect/api/client/client_set_db_doc.rb +8 -0
- data/lib/rhoconnect/api/client/create.rb +7 -0
- data/lib/rhoconnect/api/client/get_client_params.rb +2 -1
- data/lib/rhoconnect/api/client/list_client_docs.rb +2 -1
- data/lib/rhoconnect/api/client/register.rb +12 -0
- data/lib/rhoconnect/api/client/reset.rb +5 -0
- data/lib/rhoconnect/api/{source → readstate}/set_refresh_time.rb +2 -1
- data/lib/rhoconnect/api/source/get_source_params.rb +3 -2
- data/lib/rhoconnect/api/source/list_sources.rb +2 -1
- data/lib/rhoconnect/api/source/update_source_params.rb +3 -3
- data/lib/rhoconnect/api/store/get_db_doc.rb +4 -0
- data/lib/rhoconnect/api/store/set_db_doc.rb +7 -0
- data/lib/rhoconnect/api/system/get_adapter.rb +4 -0
- data/lib/rhoconnect/api/{admin → system}/get_license_info.rb +2 -1
- data/lib/rhoconnect/api/system/login.rb +15 -0
- data/lib/rhoconnect/api/{admin → system}/reset.rb +3 -2
- data/lib/rhoconnect/api/system/save_adapter.rb +4 -0
- data/lib/rhoconnect/api/{admin → system}/stats.rb +2 -1
- data/lib/rhoconnect/api/user/create_user.rb +2 -2
- data/lib/rhoconnect/api/user/delete_client.rb +6 -0
- data/lib/rhoconnect/api/user/delete_user.rb +2 -1
- data/lib/rhoconnect/api/user/list_clients.rb +4 -0
- data/lib/rhoconnect/api/user/list_source_docs.rb +11 -0
- data/lib/rhoconnect/api/user/list_users.rb +1 -1
- data/lib/rhoconnect/api/user/ping.rb +7 -0
- data/lib/rhoconnect/api/user/show_user.rb +3 -0
- data/lib/rhoconnect/api/user/update_user.rb +3 -2
- data/lib/rhoconnect/api/user/user_get_db_doc.rb +5 -0
- data/lib/rhoconnect/api/user/user_set_db_doc.rb +10 -0
- data/lib/rhoconnect/app.rb +12 -2
- data/lib/rhoconnect/async.rb +6 -10
- data/lib/rhoconnect/bulk_data/bulk_data.rb +4 -4
- data/lib/rhoconnect/client.rb +10 -9
- data/lib/rhoconnect/client_sync.rb +24 -19
- data/lib/rhoconnect/document.rb +18 -4
- data/lib/rhoconnect/graph_helper.rb +4 -2
- data/lib/rhoconnect/jobs/bulk_data_job.rb +1 -1
- data/lib/rhoconnect/jobs/ping_job.rb +39 -29
- data/lib/rhoconnect/middleware/admin_user.rb +23 -0
- data/lib/rhoconnect/middleware/body_content_type_parser.rb +35 -0
- data/lib/rhoconnect/{cors.rb → middleware/cors.rb} +1 -0
- data/lib/rhoconnect/middleware/current_app.rb +16 -0
- data/lib/rhoconnect/middleware/current_request.rb +16 -0
- data/lib/rhoconnect/middleware/current_user.rb +17 -0
- data/lib/rhoconnect/middleware/helpers.rb +105 -0
- data/lib/rhoconnect/middleware/login_required.rb +22 -0
- data/lib/rhoconnect/{stats/middleware.rb → middleware/stats.rb} +5 -3
- data/lib/rhoconnect/middleware/x_domain_session_wrapper.rb +58 -0
- data/lib/rhoconnect/ping.rb +1 -0
- data/lib/rhoconnect/ping/apple.rb +18 -16
- data/lib/rhoconnect/ping/blackberry.rb +9 -9
- data/lib/rhoconnect/ping/rhoconnect_push.rb +45 -0
- data/lib/rhoconnect/server.rb +98 -91
- data/lib/rhoconnect/source.rb +5 -1
- data/lib/rhoconnect/source_sync.rb +4 -3
- data/lib/rhoconnect/stats/record.rb +15 -15
- data/lib/rhoconnect/store.rb +253 -75
- data/lib/rhoconnect/tasks.rb +3 -3
- data/lib/rhoconnect/version.rb +1 -1
- data/lib/rhoconnect/web-console/controllers/admins.js +1 -14
- data/lib/rhoconnect/web-console/models/adapter.js +18 -8
- data/lib/rhoconnect/web-console/models/client.js +15 -9
- data/lib/rhoconnect/web-console/models/doc.js +7 -11
- data/lib/rhoconnect/web-console/models/session.js +5 -2
- data/lib/rhoconnect/web-console/models/source.js +55 -36
- data/lib/rhoconnect/web-console/models/user.js +20 -11
- data/lib/rhoconnect/web-console/public/backbone.js +8 -2
- data/lib/rhoconnect/web-console/templates/index.erb +11 -5
- data/lib/rhoconnect/web-console/views/doc.js +6 -8
- data/lib/rhoconnect/web-console/views/edit_user.js +6 -3
- data/lib/rhoconnect/web-console/views/home.js +98 -25
- data/lib/rhoconnect/web-console/views/index.js +1 -1
- data/lib/rhoconnect/web-console/views/new_ping.js +6 -3
- data/lib/rhoconnect/web-console/views/server_doc.js +12 -4
- data/lib/rhoconnect/web-console/views/show_device.js +6 -3
- data/rhoconnect.gemspec +1 -2
- data/spec/api/{source → app}/fast_delete_spec.rb +4 -4
- data/spec/api/{source → app}/fast_insert_spec.rb +4 -4
- data/spec/api/{source → app}/fast_update_spec.rb +22 -6
- data/spec/api/{source → app}/push_deletes_spec.rb +2 -2
- data/spec/api/app/push_objects_spec.rb +45 -0
- data/spec/api/client/client_get_db_doc_spec.rb +31 -0
- data/spec/api/client/client_set_db_doc_spec.rb +14 -0
- data/spec/api/client/get_client_params_spec.rb +3 -2
- data/spec/api/client/list_client_docs_spec.rb +2 -2
- data/spec/api/{source → readstate}/set_refresh_time_spec.rb +15 -9
- data/spec/api/source/get_source_params_spec.rb +3 -2
- data/spec/api/source/list_sources_spec.rb +3 -9
- data/spec/api/source/update_source_params_spec.rb +4 -4
- data/spec/api/store/get_db_doc_spec.rb +32 -0
- data/spec/api/store/set_db_doc_spec.rb +43 -0
- data/spec/api/system/adapter_spec.rb +33 -0
- data/spec/api/{admin → system}/get_license_info_spec.rb +2 -5
- data/spec/api/{admin/get_api_token_spec.rb → system/login_spec.rb} +4 -11
- data/spec/api/{admin → system}/reset_spec.rb +2 -2
- data/spec/api/{admin → system}/stats_spec.rb +19 -13
- data/spec/api/user/create_user_spec.rb +15 -8
- data/spec/api/{client → user}/delete_client_spec.rb +3 -4
- data/spec/api/user/delete_user_spec.rb +33 -4
- data/spec/api/user/list_clients_spec.rb +30 -0
- data/spec/api/user/list_source_docs_spec.rb +35 -0
- data/spec/api/user/list_users_spec.rb +5 -6
- data/spec/api/{client → user}/ping_spec.rb +4 -6
- data/spec/api/user/show_user_spec.rb +14 -0
- data/spec/api/user/update_user_spec.rb +28 -10
- data/spec/api/user/user_get_db_doc_spec.rb +16 -0
- data/spec/api/user/user_set_db_doc_spec.rb +41 -0
- data/spec/apps/rhotestapp/application.rb +4 -0
- data/spec/apps/rhotestapp/settings/settings.yml +3 -1
- data/spec/bulk_data/bulk_data_spec.rb +13 -0
- data/spec/client_sync_spec.rb +41 -59
- data/spec/document_spec.rb +23 -0
- data/spec/javascripts/doc_view_spec.js +1 -1
- data/spec/javascripts/home_view_spec.js +10 -5
- data/spec/javascripts/index_view_spec.js +1 -1
- data/spec/jobs/ping_job_spec.rb +26 -0
- data/spec/perf/store_perf_spec.rb +1 -1
- data/spec/ping/android_spec.rb +0 -7
- data/spec/ping/apple_spec.rb +7 -0
- data/spec/ping/blackberry_spec.rb +10 -0
- data/spec/ping/rhoconnect_push_spec.rb +58 -0
- data/spec/server/cors_spec.rb +1 -1
- data/spec/server/server_spec.rb +152 -104
- data/spec/{stats/middleware_spec.rb → server/stats_spec.rb} +4 -5
- data/spec/server/x_domain_session_wrapper_spec.rb +3 -3
- data/spec/source_spec.rb +2 -2
- data/spec/source_sync_spec.rb +2 -0
- data/spec/spec_helper.rb +17 -3
- data/spec/stats/record_spec.rb +18 -19
- data/spec/store_spec.rb +51 -26
- data/spec/support/shared_examples.rb +4 -0
- data/spec/sync_states_spec.rb +2 -2
- metadata +104 -88
- data/bench/benchapp/Gemfile.lock +0 -87
- data/bench/blobapp/Gemfile.lock +0 -107
- data/bench/lib/testdata/5-data.txt +0 -8
- data/doc/release.txt +0 -41
- data/lib/rhoconnect/api/admin/get_api_token.rb +0 -14
- data/lib/rhoconnect/api/admin/login.rb +0 -6
- data/lib/rhoconnect/api/application/bulk_data.rb +0 -7
- data/lib/rhoconnect/api/application/clientcreate.rb +0 -8
- data/lib/rhoconnect/api/application/clientlogin.rb +0 -6
- data/lib/rhoconnect/api/application/clientregister.rb +0 -13
- data/lib/rhoconnect/api/application/clientreset.rb +0 -6
- data/lib/rhoconnect/api/application/query.rb +0 -7
- data/lib/rhoconnect/api/application/queue_updates.rb +0 -20
- data/lib/rhoconnect/api/application/search.rb +0 -6
- data/lib/rhoconnect/api/client/create_client.rb +0 -3
- data/lib/rhoconnect/api/client/delete_client.rb +0 -5
- data/lib/rhoconnect/api/client/list_clients.rb +0 -3
- data/lib/rhoconnect/api/client/ping.rb +0 -7
- data/lib/rhoconnect/api/source/get_adapter.rb +0 -3
- data/lib/rhoconnect/api/source/get_db_doc.rb +0 -7
- data/lib/rhoconnect/api/source/list_source_docs.rb +0 -10
- data/lib/rhoconnect/api/source/save_adapter.rb +0 -3
- data/lib/rhoconnect/api/source/set_db_doc.rb +0 -10
- data/lib/rhoconnect/api/source/upload_file.rb +0 -4
- data/lib/rhoconnect/body_content_type_parser.rb +0 -32
- data/lib/rhoconnect/x_domain_session_wrapper.rb +0 -53
- data/spec/api/admin/api_token_spec.rb +0 -13
- data/spec/api/client/create_client_spec.rb +0 -13
- data/spec/api/client/list_clients_spec.rb +0 -22
- data/spec/api/source/adapter_spec.rb +0 -29
- data/spec/api/source/get_db_doc_spec.rb +0 -21
- data/spec/api/source/list_source_docs_spec.rb +0 -25
- data/spec/api/source/push_objects_spec.rb +0 -27
- data/spec/api/source/set_db_doc_spec.rb +0 -32
- data/spec/api/source/upload_file_spec.rb +0 -26
data/spec/document_spec.rb
CHANGED
@@ -16,15 +16,38 @@ describe "Document" do
|
|
16
16
|
|
17
17
|
it "should flash_data for docname" do
|
18
18
|
@c.put_data(:foo1,{'1'=>@product1})
|
19
|
+
docname = @c.docname(:foo1)
|
20
|
+
bucket_index = get_sha1('1')[0..1]
|
21
|
+
Store.db.keys(@c.docname('*')).sort.should == ["#{docname}:#{bucket_index}", "#{docname}:indices"].sort
|
22
|
+
@c.flash_data('*')
|
23
|
+
Store.db.keys(@c.docname(:foo)).should == []
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should flash_data for arrays" do
|
27
|
+
@c.put_list(:foo1,['1', '2', '3'])
|
19
28
|
Store.db.keys(@c.docname('*')).should == [@c.docname(:foo1)]
|
20
29
|
@c.flash_data('*')
|
21
30
|
Store.db.keys(@c.docname(:foo)).should == []
|
22
31
|
end
|
32
|
+
|
33
|
+
it "should get_data for arrays" do
|
34
|
+
@c.put_list(:foo1,['1', '2', '3'])
|
35
|
+
Store.db.keys(@c.docname('*')).should == [@c.docname(:foo1)]
|
36
|
+
@c.get_data(:foo1, Array).should == ['1', '2', '3']
|
37
|
+
end
|
23
38
|
|
24
39
|
it "should rename doc" do
|
25
40
|
set_state(@c.docname(:key1) => @data)
|
26
41
|
@c.rename(:key1,:key2)
|
27
42
|
verify_result(@c.docname(:key1) => {}, @c.docname(:key2) => @data)
|
28
43
|
end
|
44
|
+
|
45
|
+
it "should operate with individual object" do
|
46
|
+
key = '1'
|
47
|
+
data = {'foo' => 'bar'}
|
48
|
+
@c.put_object(:md, key, data)
|
49
|
+
obj = @c.get_object(:md, key)
|
50
|
+
obj.should == data
|
51
|
+
end
|
29
52
|
end
|
30
53
|
end
|
@@ -30,7 +30,7 @@ describe("DocView", function(){
|
|
30
30
|
var title = this.docView.el.innerHTML.search('testkey');
|
31
31
|
expect(title).toBeGreaterThan(0);
|
32
32
|
|
33
|
-
var change_btn = this.docView.el.innerHTML.search('Upload
|
33
|
+
var change_btn = this.docView.el.innerHTML.search('Upload string');
|
34
34
|
expect(change_btn).toBeGreaterThan(0);
|
35
35
|
})
|
36
36
|
});
|
@@ -5,13 +5,18 @@ describe("Home", function(){
|
|
5
5
|
session.setAuthenticated('true');
|
6
6
|
session.setApiKey('testtoken');
|
7
7
|
source = new Source();
|
8
|
-
|
9
|
-
sinon.stub(source,'fetch')
|
8
|
+
|
9
|
+
sinon.stub(source,'fetch');
|
10
10
|
sinon.stub(source,'save');
|
11
|
+
|
12
|
+
adapter = new Adapter();
|
13
|
+
sinon.stub(adapter, 'set_adapter');
|
14
|
+
sinon.stub(adapter, 'get_adapter');
|
15
|
+
|
11
16
|
confirmStub = sinon.stub(window, 'confirm');
|
12
17
|
confirmStub.returns(true);
|
13
|
-
|
14
|
-
this.homeView = new App.Views.Home({model : source});
|
18
|
+
sinon.stub(jQuery,'ajax');
|
19
|
+
this.homeView = new App.Views.Home({model : source, model2 : adapter});
|
15
20
|
});
|
16
21
|
|
17
22
|
afterEach(function(){
|
@@ -19,6 +24,7 @@ describe("Home", function(){
|
|
19
24
|
session.setAuthenticated('false');
|
20
25
|
session.setApiKey(null);
|
21
26
|
confirmStub.restore();
|
27
|
+
jQuery.ajax.restore();
|
22
28
|
});
|
23
29
|
|
24
30
|
it("should have render initial html",function(){
|
@@ -34,6 +40,5 @@ describe("Home", function(){
|
|
34
40
|
|
35
41
|
var reset = this.homeView.el.innerHTML.search('Sync Server URL');
|
36
42
|
expect(reset).toBeGreaterThan(0);
|
37
|
-
|
38
43
|
})
|
39
44
|
});
|
data/spec/jobs/ping_job_spec.rb
CHANGED
@@ -175,5 +175,31 @@ describe "PingJob" do
|
|
175
175
|
end
|
176
176
|
exception_raised.should == true
|
177
177
|
end
|
178
|
+
|
179
|
+
it "should skip ping for unknown user or user with no clients" do
|
180
|
+
params = {"user_id" => [ 'fake_user' ], "api_token" => @api_token,
|
181
|
+
"sources" => [@s.name], "message" => 'hello world',
|
182
|
+
"vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3', 'phone_id' => nil }
|
183
|
+
PingJob.should_receive(:log).once.with(/Skipping ping for unknown user 'fake_user' or 'fake_user' has no registered clients.../)
|
184
|
+
PingJob.perform(params)
|
185
|
+
end
|
186
|
+
|
187
|
+
it "should process ping for device_push_type if available" do
|
188
|
+
@c.device_push_type = 'rhoconnect_push'
|
189
|
+
@c.device_port = nil
|
190
|
+
params = {
|
191
|
+
'user_id' => @u.id,
|
192
|
+
'message' => 'hello world',
|
193
|
+
'device_port' => '',
|
194
|
+
'vibrate' => '',
|
195
|
+
'phone_id' => nil
|
196
|
+
}
|
197
|
+
scrubbed_params = params.dup
|
198
|
+
|
199
|
+
RhoconnectPush.should_receive(:ping).once.with(
|
200
|
+
{'device_pin' => @c.device_pin}.merge!(scrubbed_params)
|
201
|
+
)
|
202
|
+
PingJob.perform(params)
|
203
|
+
end
|
178
204
|
end
|
179
205
|
end
|
@@ -19,7 +19,7 @@ describe "Rhoconnect Performance" do
|
|
19
19
|
Store.put_data('mdoc',@data).should == true
|
20
20
|
Store.put_data('cdoc',@data1).should == true
|
21
21
|
start = start_timer
|
22
|
-
Store.get_diff_data('mdoc','cdoc').should ==
|
22
|
+
Store.get_diff_data('mdoc','cdoc').should == expected
|
23
23
|
lap_timer('get_diff_data duration', start)
|
24
24
|
end
|
25
25
|
end
|
data/spec/ping/android_spec.rb
CHANGED
@@ -2,13 +2,6 @@ require File.join(File.dirname(__FILE__),'..','spec_helper')
|
|
2
2
|
|
3
3
|
describe "Ping Android" do
|
4
4
|
it_behaves_like "SharedRhoconnectHelper", :rhoconnect_data => false do
|
5
|
-
def setup_post_yield(response)
|
6
|
-
if RUBY_VERSION =~ /1.9/ or defined?(JRUBY_VERSION)
|
7
|
-
RestClient.stub!(:post).and_yield(response, nil, nil)
|
8
|
-
else
|
9
|
-
RestClient.stub!(:post).and_yield(response)
|
10
|
-
end
|
11
|
-
end
|
12
5
|
|
13
6
|
before do
|
14
7
|
@params = {"device_pin" => @c.device_pin,
|
data/spec/ping/apple_spec.rb
CHANGED
@@ -65,5 +65,12 @@ describe "Ping Apple" do
|
|
65
65
|
Apple.should_receive(:log).once.with("Error while sending ping: #{error}")
|
66
66
|
lambda { Apple.ping(@params) }.should raise_error(SocketError,error)
|
67
67
|
end
|
68
|
+
|
69
|
+
it "should do nothing if no cert or host or port" do
|
70
|
+
Rhoconnect::Apple.stub!(:get_config).and_return({:test => {:iphonecertfile=>"none"}})
|
71
|
+
Rhoconnect::Apple.should_receive(:get_config).once
|
72
|
+
OpenSSL::SSL::SSLContext.should_receive(:new).exactly(0).times
|
73
|
+
Apple.ping(@params)
|
74
|
+
end
|
68
75
|
end
|
69
76
|
end
|
@@ -24,10 +24,20 @@ describe "Ping Blackberry" do
|
|
24
24
|
|
25
25
|
it "should ping blackberry with connection error" do
|
26
26
|
error = 'Connection refused'
|
27
|
+
Rhoconnect::Blackberry.stub!(:get_config).and_return({:test => {:mdsserver=>'testserver',:mdsserverport=>'testport'}})
|
28
|
+
Rhoconnect::Blackberry.should_receive(:get_config).once
|
27
29
|
@http.stub!(:request).and_return { raise SocketError.new(error) }
|
28
30
|
Blackberry.should_receive(:log).once.with("Error while sending ping: #{error}")
|
29
31
|
lambda { Blackberry.ping(@params) }.should raise_error(SocketError,error)
|
30
32
|
end
|
33
|
+
|
34
|
+
it "should do nothing if no host and port" do
|
35
|
+
error = 'Connection refused'
|
36
|
+
Rhoconnect::Blackberry.stub!(:get_config).and_return({:test => {}})
|
37
|
+
Rhoconnect::Blackberry.should_receive(:get_config).once
|
38
|
+
Net::HTTP.should_receive(:new).exactly(0).times
|
39
|
+
Blackberry.ping(@params)
|
40
|
+
end
|
31
41
|
|
32
42
|
it "should compute pap_message" do
|
33
43
|
expected = <<PAP
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__),'..','spec_helper')
|
2
|
+
|
3
|
+
describe "Ping using RhoConnect push" do
|
4
|
+
it_behaves_like "SharedRhoconnectHelper", :rhoconnect_data => false do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@params = {"device_pin" => @c.device_pin,
|
8
|
+
"sources" => [@s.name], "message" => 'hello world',
|
9
|
+
"vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3'}
|
10
|
+
@response = mock('response')
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should ping rhoconnect push successfully" do
|
15
|
+
result = ''
|
16
|
+
@response.stub!(:code).and_return(204)
|
17
|
+
@response.stub!(:body).and_return(result)
|
18
|
+
@response.stub!(:return!).and_return(@response)
|
19
|
+
RestClient.stub!(:post).and_return(@response)
|
20
|
+
res = RhoconnectPush.ping(@params)
|
21
|
+
res.body.should == result
|
22
|
+
res.code.should == 204
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should ping rhoconnect push with missing push_server property" do
|
26
|
+
RhoconnectPush.stub!(:get_config).and_return({:test => {}})
|
27
|
+
lambda { RhoconnectPush.ping(@params) }.should raise_error(
|
28
|
+
RhoconnectPush::InvalidPushServer, "Missing or invalid `:push_server` in settings/settings.yml."
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
it "should ping rhoconnect push with 400 response" do
|
34
|
+
result = ''
|
35
|
+
@response.stub!(:code).and_return(400)
|
36
|
+
@response.stub!(:body).and_return(result)
|
37
|
+
@response.stub!(:return!).and_return(@response)
|
38
|
+
setup_post_yield(@response)
|
39
|
+
lambda { RhoconnectPush.ping(@params) }.should raise_error(
|
40
|
+
RhoconnectPush::InvalidPushRequest, "Invalid push request."
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should compute push_message" do
|
45
|
+
expected = {
|
46
|
+
'collapseId' => 5,
|
47
|
+
'data' => {
|
48
|
+
'do_sync' => [@s.name],
|
49
|
+
'message' => "hello world",
|
50
|
+
'vibrate' => '5',
|
51
|
+
'sound' => "hello.mp3"
|
52
|
+
}
|
53
|
+
}
|
54
|
+
actual = RhoconnectPush.push_message(@params)
|
55
|
+
JSON.parse(actual).should == expected
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/spec/server/cors_spec.rb
CHANGED
data/spec/server/server_spec.rb
CHANGED
@@ -31,22 +31,46 @@ describe "Server" do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should login if content-type contains extra parameters" do
|
34
|
-
post "/
|
34
|
+
post "/rc/#{Rhoconnect::API_VERSION}/system/login", {"login" => 'rhoadmin', "password" => ''}.to_json, {'CONTENT_TYPE'=>'application/json; charset=UTF-8'}
|
35
35
|
last_response.should be_ok
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should fail to login if wrong content-type" do
|
39
|
-
post "/
|
39
|
+
post "/rc/#{Rhoconnect::API_VERSION}/system/login", {"login" => 'rhoadmin', "password" => ''}.to_json, {'CONTENT_TYPE'=>'application/x-www-form-urlencoded'}
|
40
40
|
last_response.should_not be_ok
|
41
41
|
end
|
42
42
|
|
43
43
|
it "should login as rhoadmin user" do
|
44
|
-
post "/
|
44
|
+
post "/rc/#{Rhoconnect::API_VERSION}/system/login", "login" => 'rhoadmin', "password" => ''
|
45
45
|
last_response.should be_ok
|
46
46
|
end
|
47
|
+
|
48
|
+
it "should extract api token from the header" do
|
49
|
+
post "/rc/#{Rhoconnect::API_VERSION}/system/login", "login" => 'rhoadmin', "password" => ''
|
50
|
+
last_response.should be_ok
|
51
|
+
api_token = last_response.body
|
52
|
+
|
53
|
+
get "/rc/#{Rhoconnect::API_VERSION}/system/license", {}, {Rhoconnect::API_TOKEN_HEADER => api_token}
|
54
|
+
last_response.should be_ok
|
55
|
+
JSON.parse(last_response.body).should == {
|
56
|
+
"available" => 9,
|
57
|
+
"issued" => "Fri Apr 23 17:20:13 -0700 2010",
|
58
|
+
"seats" => 10,
|
59
|
+
"rhoconnect_version" => "Version 1",
|
60
|
+
"licensee" => "Rhomobile" }
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should register custom_route and process it" do
|
64
|
+
Rhoconnect::Server.api4 :my_custom_route, :get, "/my_custom_route", false, nil do |params,user,server|
|
65
|
+
"Hello World!"
|
66
|
+
end
|
67
|
+
|
68
|
+
get "/my_custom_route", {}
|
69
|
+
last_response.body.should == "Hello World!"
|
70
|
+
end
|
47
71
|
|
48
|
-
it "should respond with 401
|
49
|
-
get "/
|
72
|
+
it "should respond with 401 if controller name is not specified" do
|
73
|
+
get "/app/"
|
50
74
|
last_response.status.should == 401
|
51
75
|
end
|
52
76
|
|
@@ -70,67 +94,95 @@ describe "Server" do
|
|
70
94
|
|
71
95
|
describe "helpers" do
|
72
96
|
before(:each) do
|
73
|
-
do_post "/
|
97
|
+
do_post "/rc/#{Rhoconnect::API_VERSION}/app/login", "login" => @u.login, "password" => 'testpass'
|
74
98
|
end
|
75
99
|
|
76
100
|
it "should return nil if params[:source_name] is missing" do
|
77
|
-
get "/
|
101
|
+
get "/application"
|
78
102
|
last_response.status.should == 500
|
79
103
|
end
|
80
104
|
end
|
81
105
|
|
82
106
|
describe "auth routes" do
|
83
107
|
it "should login user with correct username,password" do
|
84
|
-
do_post "/
|
108
|
+
do_post "/rc/#{Rhoconnect::API_VERSION}/app/login", "login" => @u.login, "password" => 'testpass'
|
85
109
|
last_response.should be_ok
|
86
110
|
end
|
87
111
|
|
88
|
-
it "should login user with correct username,password
|
112
|
+
it "should login user with correct username,password old route and deprecation warning" do
|
113
|
+
do_post "/application/clientlogin", "login" => @u.login, "password" => 'testpass'
|
114
|
+
last_response.should be_ok
|
115
|
+
last_response.headers["Warning"].index('deprecated').should_not == nil
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should login user with correct username,password if backend service defined" do
|
89
119
|
stub_request(:post, "http://test.com/rhoconnect/authenticate").to_return(:body => "lucas")
|
90
120
|
Rhoconnect.appserver = 'http://test.com'
|
91
|
-
do_post "/
|
121
|
+
do_post "/rc/#{Rhoconnect::API_VERSION}/app/login", "login" => 'lucas', "password" => 'testpass'
|
92
122
|
last_response.should be_ok
|
93
123
|
end
|
94
124
|
|
95
125
|
it "should return 401 and LoginException messsage from authenticate" do
|
96
|
-
do_post "/
|
126
|
+
do_post "/rc/#{Rhoconnect::API_VERSION}/app/login", "login" => @u.login, "password" => 'wrongpass'
|
97
127
|
last_response.status.should == 401
|
98
128
|
last_response.body.should == 'login exception'
|
99
129
|
end
|
100
130
|
|
101
131
|
it "should return 500 and Exception messsage from authenticate" do
|
102
|
-
do_post "/
|
132
|
+
do_post "/rc/#{Rhoconnect::API_VERSION}/app/login", "login" => @u.login, "password" => 'server error'
|
103
133
|
last_response.status.should == 500
|
104
134
|
last_response.body.should == 'server error'
|
105
135
|
end
|
106
136
|
|
107
137
|
it "should return 401 and no messsage from authenticate if no exception raised" do
|
108
|
-
do_post "/
|
138
|
+
do_post "/rc/#{Rhoconnect::API_VERSION}/app/login", "login" => @u.login, "password" => 'wrongpassnomsg'
|
109
139
|
last_response.status.should == 401
|
110
|
-
last_response.body.should == ''
|
140
|
+
last_response.body.should == "Unable to authenticate '#{@u.login}'"
|
111
141
|
end
|
112
142
|
|
113
143
|
it "should create unknown user through delegated authentication" do
|
114
|
-
do_post "/
|
144
|
+
do_post "/rc/#{Rhoconnect::API_VERSION}/app/login", "login" => 'newuser', "password" => 'testpass'
|
115
145
|
User.is_exist?('newuser').should == true
|
116
146
|
@a.users.members.sort.should == ['newuser','testuser']
|
117
147
|
end
|
118
148
|
|
119
149
|
it "should create a different username through delegated authentication" do
|
120
|
-
do_post "/
|
150
|
+
do_post "/rc/#{Rhoconnect::API_VERSION}/app/login", "login" => 'newuser', "password" => 'diffuser'
|
121
151
|
User.is_exist?('different').should == true
|
122
152
|
@a.users.members.sort.should == ['different','testuser']
|
123
153
|
end
|
154
|
+
|
155
|
+
context "ans authenticate" do
|
156
|
+
it "should authenticate user with ans route" do
|
157
|
+
authorize 'ansuser', 'secret'
|
158
|
+
get "/rc/#{Rhoconnect::API_VERSION}/app/ans_login", {}
|
159
|
+
last_response.status.should == 204
|
160
|
+
end
|
161
|
+
end
|
124
162
|
end
|
125
163
|
|
126
164
|
describe "client management routes" do
|
127
165
|
before(:each) do
|
128
|
-
do_post "/
|
166
|
+
do_post "/rc/#{Rhoconnect::API_VERSION}/app/login", "login" => @u.login, "password" => 'testpass'
|
129
167
|
end
|
130
168
|
|
131
169
|
it "should respond to clientcreate" do
|
132
|
-
|
170
|
+
do_post "/rc/#{Rhoconnect::API_VERSION}/clients", 'device_type' => 'blackberry'
|
171
|
+
last_response.should be_ok
|
172
|
+
last_response.content_type.should =~ /application\/json/
|
173
|
+
id = JSON.parse(last_response.body)['client']['client_id']
|
174
|
+
id.length.should == 32
|
175
|
+
JSON.parse(last_response.body).should ==
|
176
|
+
{"client"=>{"client_id"=>id}}
|
177
|
+
c = Client.load(id,{:source_name => '*'})
|
178
|
+
c.user_id.should == 'testuser'
|
179
|
+
c.device_type.should == 'blackberry'
|
180
|
+
end
|
181
|
+
|
182
|
+
it "should respond to clientcreate with old route and deprecation warning" do
|
183
|
+
get "/application/clientcreate?device_type=blackberry"
|
133
184
|
last_response.should be_ok
|
185
|
+
last_response.headers["Warning"].index('deprecated').should_not == nil
|
134
186
|
last_response.content_type.should =~ /application\/json/
|
135
187
|
id = JSON.parse(last_response.body)['client']['client_id']
|
136
188
|
id.length.should == 32
|
@@ -142,8 +194,8 @@ describe "Server" do
|
|
142
194
|
end
|
143
195
|
|
144
196
|
it "should respond to clientregister" do
|
145
|
-
do_post "/
|
146
|
-
"device_type" => "iPhone", "device_pin" => 'abcd'
|
197
|
+
do_post "/rc/#{Rhoconnect::API_VERSION}/clients/#{@c.id}/register",
|
198
|
+
"device_type" => "iPhone", "device_pin" => 'abcd'
|
147
199
|
last_response.should be_ok
|
148
200
|
@c.device_type.should == 'Apple'
|
149
201
|
@c.device_pin.should == 'abcd'
|
@@ -154,8 +206,8 @@ describe "Server" do
|
|
154
206
|
Store.flash_data("client*")
|
155
207
|
client_id = @c.id.clone
|
156
208
|
@c = nil
|
157
|
-
do_post "/
|
158
|
-
"device_type" => "iPhone", "device_pin" => 'abcd'
|
209
|
+
do_post "/rc/#{Rhoconnect::API_VERSION}/clients/#{client_id}/register",
|
210
|
+
"device_type" => "iPhone", "device_pin" => 'abcd'
|
159
211
|
last_response.should be_ok
|
160
212
|
@c = Client.load(client_id, {:source_name => '*'})
|
161
213
|
@c.device_type.should == 'iPhone'
|
@@ -165,7 +217,14 @@ describe "Server" do
|
|
165
217
|
|
166
218
|
it "should respond to clientreset" do
|
167
219
|
set_state(@c.docname(:cd) => @data)
|
168
|
-
|
220
|
+
do_post "/rc/#{Rhoconnect::API_VERSION}/clients/#{@c.id}/reset", {}
|
221
|
+
verify_result(@c.docname(:cd) => {})
|
222
|
+
end
|
223
|
+
|
224
|
+
it "should respond to clientreset with old route and deprecation warning" do
|
225
|
+
set_state(@c.docname(:cd) => @data)
|
226
|
+
get "/application/clientreset", 'client_id' => @c.id
|
227
|
+
last_response.headers["Warning"].index('deprecated').should_not == nil
|
169
228
|
verify_result(@c.docname(:cd) => {})
|
170
229
|
end
|
171
230
|
|
@@ -175,7 +234,7 @@ describe "Server" do
|
|
175
234
|
@c.source_name = 'SampleAdapter'
|
176
235
|
set_state(@c.docname(:cd) => @data)
|
177
236
|
sources = [{'name' => 'SimpleAdapter'}]
|
178
|
-
|
237
|
+
do_post "/rc/#{Rhoconnect::API_VERSION}/clients/#{@c.id}/reset", 'sources' => sources
|
179
238
|
last_response.should be_ok
|
180
239
|
@c.source_name = 'SampleAdapter'
|
181
240
|
verify_result(@c.docname(:cd) => @data)
|
@@ -185,17 +244,17 @@ describe "Server" do
|
|
185
244
|
|
186
245
|
it "should switch client user if client user_id doesn't match session user" do
|
187
246
|
set_test_data('test_db_storage',@data)
|
188
|
-
get "/
|
247
|
+
get "/app/#{Rhoconnect::API_VERSION}/#{@s.name}", {}, {Rhoconnect::CLIENT_ID_HEADER => @c.id}
|
189
248
|
JSON.parse(last_response.body).last['insert'].should == @data
|
190
|
-
do_post "/
|
249
|
+
do_post "/rc/#{Rhoconnect::API_VERSION}/app/login", "login" => 'user2', "password" => 'testpass'
|
191
250
|
data = {'1'=>@product1,'2'=>@product2}
|
192
251
|
set_test_data('test_db_storage',data)
|
193
|
-
get "/
|
252
|
+
get "/app/#{Rhoconnect::API_VERSION}/#{@s.name}", {}, {Rhoconnect::CLIENT_ID_HEADER => @c.id}
|
194
253
|
JSON.parse(last_response.body).last['insert'].should == data
|
195
254
|
end
|
196
255
|
|
197
256
|
it "should return error on routes if client doesn't exist" do
|
198
|
-
get "/
|
257
|
+
get "/app/#{Rhoconnect::API_VERSION}/#{@s.name}",{}, {Rhoconnect::CLIENT_ID_HEADER => "BrokenClient"}
|
199
258
|
last_response.body.should == "Unknown client"
|
200
259
|
last_response.status.should == 500
|
201
260
|
end
|
@@ -203,29 +262,21 @@ describe "Server" do
|
|
203
262
|
|
204
263
|
describe "source routes" do
|
205
264
|
before(:each) do
|
206
|
-
|
207
|
-
end
|
208
|
-
|
209
|
-
it "should return 404 message with version < 3" do
|
210
|
-
get "/api/application/query",:source_name => @s.name,:version => 2
|
211
|
-
last_response.status.should == 404
|
212
|
-
last_response.body.should == "Server supports version 3 or higher of the protocol."
|
265
|
+
do_post "/rc/#{Rhoconnect::API_VERSION}/app/login", "login" => @u.login, "password" => 'testpass'
|
213
266
|
end
|
214
267
|
|
215
268
|
it "should post records for create" do
|
216
269
|
@product1['_id'] = '1'
|
217
|
-
params = {'create'=>{'1'=>@product1}
|
218
|
-
|
219
|
-
do_post "/api/application/queue_updates", params
|
270
|
+
params = {'create'=>{'1'=>@product1}}
|
271
|
+
do_post "/app/#{Rhoconnect::API_VERSION}/#{@s.name}", params, {Rhoconnect::CLIENT_ID_HEADER => @c.id}
|
220
272
|
last_response.should be_ok
|
221
273
|
last_response.body.should == ''
|
222
274
|
verify_result("test_create_storage" => {'1'=>@product1})
|
223
275
|
end
|
224
276
|
|
225
277
|
it "should post records for update" do
|
226
|
-
params = {'update'
|
227
|
-
|
228
|
-
do_post "/api/application/queue_updates", params
|
278
|
+
params = {'update' => @product1}
|
279
|
+
do_put "/app/#{Rhoconnect::API_VERSION}/#{@s.name}/1", params, {Rhoconnect::CLIENT_ID_HEADER => @c.id}
|
229
280
|
last_response.should be_ok
|
230
281
|
last_response.body.should == ''
|
231
282
|
verify_result("test_update_storage" => {'1'=>@product1})
|
@@ -241,47 +292,46 @@ describe "Server" do
|
|
241
292
|
verify_result("test_update_storage" => {'1'=>@product1})
|
242
293
|
end
|
243
294
|
|
244
|
-
it "should post records for
|
245
|
-
|
246
|
-
|
247
|
-
do_post "/api/application", params
|
295
|
+
it "should post records for delete" do
|
296
|
+
set_state(@c.docname(:cd) => @data)
|
297
|
+
delete "/app/#{Rhoconnect::API_VERSION}/#{@s.name}/1", {}, { Rhoconnect::CLIENT_ID_HEADER => @c.id }
|
248
298
|
last_response.should be_ok
|
249
299
|
last_response.body.should == ''
|
250
|
-
|
251
|
-
verify_result("test_update_storage" => {'1'=>@product1})
|
300
|
+
verify_result("test_delete_storage" => {'1'=>@product1})
|
252
301
|
end
|
253
302
|
|
254
|
-
it "should post records for delete" do
|
303
|
+
it "should post records for delete using the old route with deprecation warning" do
|
255
304
|
params = {'delete'=>{'1'=>@product1},:client_id => @c.id,:source_name => @s.name,
|
256
305
|
:version => ClientSync::VERSION}
|
257
306
|
do_post "/api/application/queue_updates", params
|
258
307
|
last_response.should be_ok
|
308
|
+
last_response.headers["Warning"].index('deprecated').should_not == nil
|
259
309
|
last_response.body.should == ''
|
260
310
|
verify_result("test_delete_storage" => {'1'=>@product1})
|
261
311
|
end
|
262
312
|
|
263
313
|
it "should handle client posting broken json" do
|
264
314
|
broken_json = "{\"foo\":\"bar\"\"}"
|
265
|
-
|
315
|
+
do_post "/app/#{Rhoconnect::API_VERSION}/#{@s.name}", broken_json, {Rhoconnect::CLIENT_ID_HEADER => @c.id}
|
266
316
|
last_response.status.should == 500
|
267
317
|
last_response.body.should == "Server error while processing client data"
|
268
318
|
end
|
269
319
|
|
270
320
|
it "should not login if login is empty" do
|
271
|
-
post "/
|
321
|
+
post "/rc/#{Rhoconnect::API_VERSION}/app/login", ''
|
272
322
|
last_response.status.should == 401
|
273
|
-
last_response.body.should == ""
|
323
|
+
last_response.body.should == "Unable to authenticate ''"
|
274
324
|
end
|
275
325
|
|
276
326
|
it "should get inserts json" do
|
277
327
|
cs = ClientSync.new(@s,@c,1)
|
278
328
|
data = {'1'=>@product1,'2'=>@product2}
|
279
329
|
set_test_data('test_db_storage',data)
|
280
|
-
get "/
|
330
|
+
get "/app/#{Rhoconnect::API_VERSION}/#{@s.name}", {}, {Rhoconnect::CLIENT_ID_HEADER => @c.id}
|
281
331
|
last_response.should be_ok
|
282
332
|
last_response.content_type.should =~ /application\/json/
|
283
333
|
token = @c.get_value(:page_token)
|
284
|
-
JSON.parse(last_response.body).should == [{
|
334
|
+
JSON.parse(last_response.body).should == [{'version'=>ClientSync::SYNC_VERSION}, {"token"=>token},
|
285
335
|
{"count"=>2}, {"progress_count"=>0},{"total_count"=>2},{'insert'=>data}]
|
286
336
|
end
|
287
337
|
|
@@ -289,46 +339,37 @@ describe "Server" do
|
|
289
339
|
cs = ClientSync.new(@s,@c,1)
|
290
340
|
data = {'1'=>@product1,'2'=>@product2}
|
291
341
|
set_test_data('test_db_storage',data)
|
292
|
-
get "/application",:client_id => @c.id,:source_name => @s.name,:version => ClientSync::
|
342
|
+
get "/application",:client_id => @c.id,:source_name => @s.name,:version => ClientSync::SYNC_VERSION
|
293
343
|
last_response.should be_ok
|
294
344
|
last_response.headers["Warning"].index('deprecated').should_not == nil
|
295
345
|
last_response.content_type.should =~ /application\/json/
|
296
346
|
token = @c.get_value(:page_token)
|
297
|
-
JSON.parse(last_response.body).should == [{
|
347
|
+
JSON.parse(last_response.body).should == [{'version'=>ClientSync::SYNC_VERSION},{"token"=>token},
|
298
348
|
{"count"=>2}, {"progress_count"=>0},{"total_count"=>2},{'insert'=>data}]
|
299
349
|
end
|
300
350
|
|
301
|
-
it "should get inserts json with the /api/application route and show deprecation warning" do
|
302
|
-
cs = ClientSync.new(@s,@c,1)
|
303
|
-
data = {'1'=>@product1,'2'=>@product2}
|
304
|
-
set_test_data('test_db_storage',data)
|
305
|
-
get "/api/application",:client_id => @c.id,:source_name => @s.name,:version => ClientSync::VERSION
|
306
|
-
last_response.should be_ok
|
307
|
-
last_response.headers["Warning"].index('deprecated').should_not == nil
|
308
|
-
last_response.content_type.should =~ /application\/json/
|
309
|
-
token = @c.get_value(:page_token)
|
310
|
-
JSON.parse(last_response.body).should == [{"version"=>ClientSync::VERSION},{"token"=>token},
|
311
|
-
{"count"=>2}, {"progress_count"=>0},{"total_count"=>2},{'insert'=>data}]
|
312
|
-
end
|
313
|
-
|
314
351
|
it "should get inserts json and confirm token" do
|
315
352
|
cs = ClientSync.new(@s,@c,1)
|
316
353
|
data = {'1'=>@product1,'2'=>@product2}
|
317
354
|
set_test_data('test_db_storage',data)
|
318
|
-
get "/
|
355
|
+
get "/app/#{Rhoconnect::API_VERSION}/#{@s.name}", {}, {Rhoconnect::CLIENT_ID_HEADER => @c.id}
|
319
356
|
last_response.should be_ok
|
320
357
|
token = @c.get_value(:page_token)
|
321
|
-
JSON.parse(last_response.body).should == [{
|
358
|
+
JSON.parse(last_response.body).should == [{'version'=>ClientSync::SYNC_VERSION},{"token"=>token},
|
322
359
|
{"count"=>2}, {"progress_count"=>0}, {"total_count"=>2},{'insert'=>data}]
|
323
|
-
get "/
|
324
|
-
:version => ClientSync::VERSION
|
360
|
+
get "/app/#{Rhoconnect::API_VERSION}/#{@s.name}", {:token => token}, {Rhoconnect::CLIENT_ID_HEADER => @c.id}
|
325
361
|
last_response.should be_ok
|
326
|
-
JSON.parse(last_response.body).should == [{
|
327
|
-
{"count"=>0}, {"progress_count"=>
|
362
|
+
JSON.parse(last_response.body).should == [{'version'=>ClientSync::SYNC_VERSION},{"token"=>''},
|
363
|
+
{"count"=>0}, {"progress_count"=>0}, {"total_count"=>2},{}]
|
328
364
|
end
|
329
365
|
|
330
366
|
it "should create source for dynamic adapter if source_name is unknown" do
|
331
|
-
get "/
|
367
|
+
get "/app/#{Rhoconnect::API_VERSION}/Broken", {}, {Rhoconnect::CLIENT_ID_HEADER => @c.id}
|
368
|
+
last_response.status.should == 200
|
369
|
+
end
|
370
|
+
|
371
|
+
it "should create source for dynamic adapter if source_name is unknown using the old route" do
|
372
|
+
get "/api/application/query", {:source_name => @s_fields[:name], :client_id => @c.id}
|
332
373
|
last_response.status.should == 200
|
333
374
|
end
|
334
375
|
|
@@ -338,24 +379,23 @@ describe "Server" do
|
|
338
379
|
data = {'1'=>@product1,'2'=>@product2}
|
339
380
|
set_test_data('test_db_storage',data)
|
340
381
|
|
341
|
-
get "/
|
382
|
+
get "/app/#{Rhoconnect::API_VERSION}/#{@s.name}", {}, {Rhoconnect::CLIENT_ID_HEADER => @c.id}
|
342
383
|
last_response.should be_ok
|
343
384
|
token = @c.get_value(:page_token)
|
344
|
-
JSON.parse(last_response.body).should == [{
|
385
|
+
JSON.parse(last_response.body).should == [{'version'=>ClientSync::SYNC_VERSION},{"token"=>token},
|
345
386
|
{"count"=>2}, {"progress_count"=>0}, {"total_count"=>2},{'insert'=>data}]
|
346
387
|
|
347
388
|
Store.flash_data('test_db_storage')
|
348
389
|
@s.read_state.refresh_time = Time.now.to_i
|
349
390
|
|
350
|
-
get "/
|
351
|
-
:version => ClientSync::VERSION
|
391
|
+
get "/app/#{Rhoconnect::API_VERSION}/#{@s.name}",{:token => token}, {Rhoconnect::CLIENT_ID_HEADER => @c.id}
|
352
392
|
last_response.should be_ok
|
353
393
|
token = @c.get_value(:page_token)
|
354
|
-
JSON.parse(last_response.body).should == [{
|
394
|
+
JSON.parse(last_response.body).should == [{'version'=>ClientSync::SYNC_VERSION},{"token"=>token},
|
355
395
|
{"count"=>2}, {"progress_count"=>0}, {"total_count"=>0},{'delete'=>data}]
|
356
396
|
end
|
357
397
|
|
358
|
-
it "should get search results" do
|
398
|
+
it "should get search results using the old route with deprecation warning" do
|
359
399
|
sources = [{:name=>'SampleAdapter'}]
|
360
400
|
cs = ClientSync.new(@s,@c,1)
|
361
401
|
Store.put_data('test_db_storage',@data)
|
@@ -364,7 +404,19 @@ describe "Server" do
|
|
364
404
|
get "/api/application/search",params
|
365
405
|
last_response.content_type.should =~ /application\/json/
|
366
406
|
token = @c.get_value(:search_token)
|
367
|
-
JSON.parse(last_response.body).should == [[{'version'=>ClientSync::
|
407
|
+
JSON.parse(last_response.body).should == [[{'version'=>ClientSync::SYNC_VERSION},{'token'=>token},
|
408
|
+
{'source'=>sources[0][:name]},{'count'=>1},{'insert'=>{'1'=>@product1}}]]
|
409
|
+
end
|
410
|
+
|
411
|
+
it "should get search results" do
|
412
|
+
sources = [{:name=>'SampleAdapter'}]
|
413
|
+
cs = ClientSync.new(@s,@c,1)
|
414
|
+
Store.put_data('test_db_storage',@data)
|
415
|
+
params = {:sources => sources,:search => {'name' => 'iPhone'}}
|
416
|
+
do_post "/rc/#{Rhoconnect::API_VERSION}/app/search",params, {Rhoconnect::CLIENT_ID_HEADER => @c.id}
|
417
|
+
last_response.content_type.should =~ /application\/json/
|
418
|
+
token = @c.get_value(:search_token)
|
419
|
+
JSON.parse(last_response.body).should == [[{'version'=>ClientSync::SYNC_VERSION},{'token'=>token},
|
368
420
|
{'source'=>sources[0][:name]},{'count'=>1},{'insert'=>{'1'=>@product1}}]]
|
369
421
|
end
|
370
422
|
|
@@ -372,34 +424,32 @@ describe "Server" do
|
|
372
424
|
sources = [{:name=>'SampleAdapter'}]
|
373
425
|
msg = "Error during search"
|
374
426
|
error = set_test_data('test_db_storage',@data,msg,'search error')
|
375
|
-
params = {:
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
{'source'=>sources[0][:name]},{'search-error'=>{'search-error'=>{'message'=>msg}}}]]
|
427
|
+
params = {:sources => sources,:search => {'name' => 'iPhone'}}
|
428
|
+
do_post "/rc/#{Rhoconnect::API_VERSION}/app/search", params, {Rhoconnect::CLIENT_ID_HEADER => @c.id}
|
429
|
+
JSON.parse(last_response.body).should == [[{'version'=>ClientSync::SYNC_VERSION},{'source'=>sources[0][:name]},
|
430
|
+
{'search-error'=>{'search-error'=>{'message'=>msg}}}]]
|
380
431
|
end
|
381
432
|
|
382
433
|
it "should get multiple source search results" do
|
383
434
|
Store.put_data('test_db_storage',@data)
|
384
435
|
sources = [{:name=>'SimpleAdapter'},{:name=>'SampleAdapter'}]
|
385
|
-
params = {:
|
386
|
-
|
387
|
-
get "/api/application/search",params
|
436
|
+
params = {:sources => sources,:search => {'search' => 'bar'}}
|
437
|
+
do_post "/rc/#{Rhoconnect::API_VERSION}/app/search", params, {Rhoconnect::CLIENT_ID_HEADER => @c.id}
|
388
438
|
@c.source_name = 'SimpleAdapter'
|
389
439
|
token1 = @c.get_value(:search_token)
|
390
440
|
@c.source_name = 'SampleAdapter'
|
391
441
|
token = @c.get_value(:search_token)
|
392
442
|
JSON.parse(last_response.body).should == [
|
393
|
-
[{
|
443
|
+
[{'version'=>ClientSync::SYNC_VERSION},{'token'=>token1},{"source"=>"SimpleAdapter"},
|
394
444
|
{"count"=>1}, {"insert"=>{'obj'=>{'foo'=>'bar'}}}],
|
395
|
-
[{
|
445
|
+
[{'version'=>ClientSync::SYNC_VERSION},{'token'=>token},{"source"=>"SampleAdapter"},
|
396
446
|
{"count"=>1}, {"insert"=>{'1'=>@product1}}]]
|
397
447
|
end
|
398
448
|
end
|
399
449
|
|
400
450
|
describe "bulk data routes" do
|
401
451
|
before(:each) do
|
402
|
-
do_post "/
|
452
|
+
do_post "/rc/#{Rhoconnect::API_VERSION}/app/login", "login" => @u.login, "password" => 'testpass'
|
403
453
|
end
|
404
454
|
|
405
455
|
after(:each) do
|
@@ -408,7 +458,7 @@ describe "Server" do
|
|
408
458
|
|
409
459
|
it "should make initial bulk data request and receive wait (and no deprecation warning)" do
|
410
460
|
set_state('test_db_storage' => @data)
|
411
|
-
|
461
|
+
post "/rc/#{Rhoconnect::API_VERSION}/app/bulk_data", {:partition => :user}, {Rhoconnect::CLIENT_ID_HEADER => @c.id}
|
412
462
|
last_response.should be_ok
|
413
463
|
last_response.body.should == {:result => :wait}.to_json
|
414
464
|
warning_header = last_response.headers['Warning']
|
@@ -425,9 +475,9 @@ describe "Server" do
|
|
425
475
|
|
426
476
|
it "should receive url when bulk data is available" do
|
427
477
|
set_state('test_db_storage' => @data)
|
428
|
-
|
478
|
+
post "/rc/#{Rhoconnect::API_VERSION}/app/bulk_data", {:partition => :user}, {Rhoconnect::CLIENT_ID_HEADER => @c.id}
|
429
479
|
do_bulk_data_job("data_name" => bulk_data_docname(@a.id,@u.id))
|
430
|
-
|
480
|
+
post "/rc/#{Rhoconnect::API_VERSION}/app/bulk_data", {:partition => :user}, {Rhoconnect::CLIENT_ID_HEADER => @c.id}
|
431
481
|
last_response.should be_ok
|
432
482
|
data = BulkData.load(bulk_data_docname(@a.id,@u.id))
|
433
483
|
last_response.body.should == {:result => :url,
|
@@ -437,9 +487,9 @@ describe "Server" do
|
|
437
487
|
|
438
488
|
it "should download bulk data file" do
|
439
489
|
set_state('test_db_storage' => @data)
|
440
|
-
|
490
|
+
post "/rc/#{Rhoconnect::API_VERSION}/app/bulk_data", {:partition => :user}, {Rhoconnect::CLIENT_ID_HEADER => @c.id}
|
441
491
|
do_bulk_data_job("data_name" => bulk_data_docname(@a.id,@u.id))
|
442
|
-
|
492
|
+
post "/rc/#{Rhoconnect::API_VERSION}/app/bulk_data", {:partition => :user}, {Rhoconnect::CLIENT_ID_HEADER => @c.id}
|
443
493
|
get JSON.parse(last_response.body)["url"]
|
444
494
|
last_response.should be_ok
|
445
495
|
File.open('test.data','wb') {|f| f.puts last_response.body}
|
@@ -451,7 +501,7 @@ describe "Server" do
|
|
451
501
|
set_state('test_db_storage' => @data)
|
452
502
|
Source.load('SimpleAdapter',@s_params).partition = :user
|
453
503
|
@a.sources.delete('OtherAdapter')
|
454
|
-
|
504
|
+
post "/rc/#{Rhoconnect::API_VERSION}/app/bulk_data", {:partition => :app}, {Rhoconnect::CLIENT_ID_HEADER => @c.id}
|
455
505
|
last_response.should be_ok
|
456
506
|
last_response.body.should == {:result => :nop}.to_json
|
457
507
|
end
|
@@ -459,7 +509,7 @@ describe "Server" do
|
|
459
509
|
|
460
510
|
describe "blob sync" do
|
461
511
|
before(:each) do
|
462
|
-
do_post "/
|
512
|
+
do_post "/rc/#{Rhoconnect::API_VERSION}/app/login", "login" => @u.login, "password" => 'testpass'
|
463
513
|
end
|
464
514
|
it "should upload blob in multipart post" do
|
465
515
|
file1,file2 = 'upload1.txt','upload2.txt'
|
@@ -468,14 +518,12 @@ describe "Server" do
|
|
468
518
|
@product2['txtfile-rhoblob'] = file2
|
469
519
|
@product2['_id'] = 'tempobj2'
|
470
520
|
cud = {'create'=>{'1'=>@product1,'2'=>@product2},
|
471
|
-
:client_id => @c.id,:source_name => @s.name,
|
472
|
-
:version => ClientSync::VERSION,
|
473
521
|
:blob_fields => ['txtfile-rhoblob']}.to_json
|
474
|
-
post "/
|
522
|
+
post "/app/#{Rhoconnect::API_VERSION}/#{@s.name}",
|
475
523
|
{:cud => cud,'txtfile-rhoblob-1' =>
|
476
524
|
Rack::Test::UploadedFile.new(File.join(File.dirname(__FILE__),'..','testdata',file1), "application/octet-stream"),
|
477
525
|
'txtfile-rhoblob-2' =>
|
478
|
-
Rack::Test::UploadedFile.new(File.join(File.dirname(__FILE__),'..','testdata',file2), "application/octet-stream")}
|
526
|
+
Rack::Test::UploadedFile.new(File.join(File.dirname(__FILE__),'..','testdata',file2), "application/octet-stream")}, {Rhoconnect::CLIENT_ID_HEADER => @c.id}
|
479
527
|
last_response.should be_ok
|
480
528
|
data = Store.get_data('test_create_storage')
|
481
529
|
data.size.should == 2
|