rhoconnect 4.0.4 → 5.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/CHANGELOG.md +54 -5
- data/CREDITS +219 -219
- data/Gemfile +2 -2
- data/Gemfile.lock +68 -79
- data/Rakefile +1 -2
- data/bench/benchapp/spec/models/ruby/mock_adapter_spec.rb +17 -17
- data/bench/benchapp/spec/models/ruby/queue_mock_adapter_spec.rb +17 -17
- data/bench/benchapp/spec/spec_helper.rb +3 -3
- data/bench/blobapp/spec/models/ruby/blob_adapter_spec.rb +17 -17
- data/bench/blobapp/spec/spec_helper.rb +3 -3
- data/bench/lib/bench/runner.rb +1 -69
- data/bench/lib/bench.rb +18 -18
- data/bench/spec/mock_adapter_spec.rb +54 -55
- data/bench/spec/mock_client_spec.rb +47 -48
- data/bench/spec/result_spec.rb +41 -44
- data/bench/spec/utils_spec.rb +24 -25
- data/commands/generators/app.rb +7 -5
- data/commands/generators/controller.rb +7 -5
- data/commands/generators/model.rb +7 -5
- data/commands/generators/source.rb +7 -5
- data/commands/parser.rb +1 -1
- data/commands/redis/redis_download.rb +1 -1
- data/doc/async-jobs.txt +9 -9
- data/doc/supported-platforms.txt +0 -2
- data/generators/rhoconnect.rb +92 -212
- data/generators/templates/application/rcgemfile +3 -3
- data/generators/templates/application/spec/application_controller_spec.rb +14 -16
- data/generators/templates/application/spec/js_spec.rb +20 -20
- data/generators/templates/application/spec/spec_helper.rb +1 -1
- data/generators/templates/source/controllers/ruby/controller_spec.rb +18 -19
- data/generators/templates/source/models/ruby/model_spec.rb +17 -17
- data/install.sh +10 -21
- data/installer/unix-like/rho_connect_install_constants.rb +5 -5
- data/installer/unix-like/rho_connect_install_installers.rb +4 -4
- data/installer/utils/constants.rb +6 -6
- data/installer/utils/nix_install_test.rb +29 -29
- data/installer/utils/package_upload/repos.rake +16 -26
- data/js-adapters/node.rb +4 -4
- data/js-adapters/node_channel.rb +4 -8
- data/lib/rhoconnect/db_adapter.rb +13 -13
- data/lib/rhoconnect/handler/changes/engine.rb +1 -1
- data/lib/rhoconnect/jobs/bulk_data_job.rb +29 -29
- data/lib/rhoconnect/license.rb +7 -7
- data/lib/rhoconnect/model/helpers/find_duplicates_on_update.rb +13 -13
- data/lib/rhoconnect/ping/apple.rb +4 -4
- data/lib/rhoconnect/server.rb +2 -2
- data/lib/rhoconnect/source.rb +2 -2
- data/lib/rhoconnect/store.rb +12 -6
- data/lib/rhoconnect/utilities.rb +2 -2
- data/lib/rhoconnect/version.rb +1 -1
- data/lib/rhoconnect.rb +6 -4
- data/rhoconnect.gemspec +5 -6
- data/spec/api/api_helper.rb +1 -1
- data/spec/api/app/fast_delete_spec.rb +22 -22
- data/spec/api/app/fast_insert_spec.rb +23 -23
- data/spec/api/app/fast_update_spec.rb +63 -63
- data/spec/api/app/push_deletes_spec.rb +11 -13
- data/spec/api/app/push_objects_spec.rb +39 -39
- data/spec/api/client/client_get_db_doc_spec.rb +29 -29
- data/spec/api/client/client_set_db_doc_spec.rb +11 -11
- data/spec/api/client/get_client_params_spec.rb +29 -29
- data/spec/api/client/list_client_docs_spec.rb +32 -34
- data/spec/api/client/reset_spec.rb +30 -30
- data/spec/api/readstate/set_refresh_time_spec.rb +43 -43
- data/spec/api/source/get_source_params_spec.rb +32 -34
- data/spec/api/source/list_sources_spec.rb +13 -13
- data/spec/api/source/update_source_params_spec.rb +19 -19
- data/spec/api/store/get_db_doc_spec.rb +27 -27
- data/spec/api/store/set_db_doc_spec.rb +38 -38
- data/spec/api/system/adapter_spec.rb +27 -29
- data/spec/api/system/get_license_info_spec.rb +11 -11
- data/spec/api/system/login_spec.rb +37 -37
- data/spec/api/system/reset_spec.rb +15 -15
- data/spec/api/system/stats_spec.rb +70 -71
- data/spec/api/user/create_user_spec.rb +37 -37
- data/spec/api/user/delete_client_spec.rb +7 -7
- data/spec/api/user/delete_user_spec.rb +62 -62
- data/spec/api/user/list_clients_spec.rb +24 -24
- data/spec/api/user/list_source_docs_spec.rb +29 -29
- data/spec/api/user/list_users_spec.rb +22 -22
- data/spec/api/user/ping_spec.rb +18 -18
- data/spec/api/user/show_user_spec.rb +10 -10
- data/spec/api/user/update_user_spec.rb +43 -43
- data/spec/api/user/user_get_db_doc_spec.rb +12 -12
- data/spec/api/user/user_set_db_doc_spec.rb +37 -37
- data/spec/api_token_spec.rb +8 -8
- data/spec/app_spec.rb +18 -17
- data/spec/apps/jstestapp/settings/settings.yml +2 -0
- data/spec/async_spec.rb +9 -11
- data/spec/bulk_data/bulk_data_spec.rb +120 -120
- data/spec/cli/cli_spec.rb +50 -53
- data/spec/client_spec.rb +105 -105
- data/spec/client_sync_spec.rb +529 -528
- data/spec/controllers/js_base_spec.rb +147 -141
- data/spec/doc/doc_spec.rb +51 -52
- data/spec/document_spec.rb +58 -58
- data/spec/dynamic_adapter_spec.rb +33 -36
- data/spec/generator/generator_spec.rb +76 -42
- data/spec/jobs/bulk_data_job_spec.rb +101 -102
- data/spec/jobs/ping_job_spec.rb +176 -177
- data/spec/jobs/source_job_spec.rb +24 -25
- data/spec/license_spec.rb +54 -55
- data/spec/models/js_base_spec.rb +121 -120
- data/spec/perf/bulk_data_perf_spec.rb +23 -24
- data/spec/perf/perf_spec_helper.rb +7 -7
- data/spec/perf/store_perf_spec.rb +139 -140
- data/spec/ping/apple_spec.rb +65 -65
- data/spec/ping/gcm_spec.rb +83 -84
- data/spec/ping/rhoconnect_push_spec.rb +52 -53
- data/spec/predefined_adapters/rho_internal_bench_adapter_controller_js_spec.rb +100 -101
- data/spec/predefined_adapters/rho_internal_js_bench_adapter_js_spec.rb +29 -31
- data/spec/read_state_spec.rb +24 -25
- data/spec/rhoconnect_spec.rb +7 -7
- data/spec/server/server_spec.rb +664 -662
- data/spec/server/stats_spec.rb +12 -12
- data/spec/source_adapter_spec.rb +124 -125
- data/spec/source_spec.rb +148 -149
- data/spec/source_sync_spec.rb +736 -736
- data/spec/spec_helper.rb +4 -5
- data/spec/stats/record_spec.rb +22 -21
- data/spec/store_orm_spec.rb +48 -48
- data/spec/store_spec.rb +428 -426
- data/spec/support/shared_examples.rb +5 -7
- data/spec/sync_states_spec.rb +67 -67
- data/spec/test_methods_spec.rb +121 -123
- data/spec/testdata/10000-data.txt +0 -0
- data/spec/testdata/5000-data.txt +0 -0
- data/spec/user_spec.rb +102 -102
- data/tasks/redis.rake +3 -3
- metadata +154 -195
- data/bench/benchapp/tmp/pids/passenger.9292.pid.lock +0 -0
- data/bench/benchapp/tmp/restart.txt +0 -0
- data/bench/blobapp/settings/license.key.bak +0 -2
- data/bench/blobapp/tmp/restart.txt +0 -0
- data/bench/lib/testdata/1-data.txt +0 -0
- data/bench/lib/testdata/10-data.txt +0 -0
- data/bench/lib/testdata/2-data.txt +0 -0
- data/bench/lib/testdata/250-data.txt +0 -0
- data/bench/lib/testdata/5-blob_data.txt +0 -0
- data/bench/lib/testdata/5-data.txt +0 -0
- data/bench/lib/testdata/50-data.txt +0 -0
- data/bench/lib/testdata/500-data.txt +0 -0
- data/doc/protocol.html +0 -1993
- data/spec/coverage/rcov/assets/0.2.3/jquery-1.3.2.min.js +0 -19
- data/spec/coverage/rcov/assets/0.2.3/jquery.tablesorter.min.js +0 -15
- data/spec/coverage/rcov/assets/0.2.3/print.css +0 -12
- data/spec/coverage/rcov/assets/0.2.3/rcov.js +0 -42
- data/spec/coverage/rcov/assets/0.2.3/screen.css +0 -270
- data/spec/coverage/rcov/index.html +0 -88
- data/spec/generator/generator_spec_helper.rb +0 -9
data/spec/ping/apple_spec.rb
CHANGED
@@ -1,76 +1,76 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__),'..','spec_helper')
|
2
2
|
|
3
3
|
describe "Ping Apple" do
|
4
|
-
|
5
|
-
before do
|
6
|
-
@params = {"user_id" => @u.id, "api_token" => @api_token,
|
7
|
-
"sources" => [@s.name], "message" => 'hello world',
|
8
|
-
"vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3',
|
9
|
-
"device_pin" => @c.device_pin, "device_port" => @c.device_port}
|
10
|
-
ssl_ctx = mock("ssl_ctx")
|
11
|
-
ssl_ctx.stub!(:key=).and_return('key')
|
12
|
-
ssl_ctx.stub!(:cert=).and_return('cert')
|
13
|
-
OpenSSL::SSL::SSLContext.stub!(:new).and_return(ssl_ctx)
|
14
|
-
OpenSSL::PKey::RSA.stub!(:new)
|
15
|
-
OpenSSL::X509::Certificate.stub!(:new)
|
4
|
+
include_examples "SharedRhoconnectHelper", :rhoconnect_data => false
|
16
5
|
|
17
|
-
|
18
|
-
|
19
|
-
|
6
|
+
before do
|
7
|
+
@params = {"user_id" => @u.id, "api_token" => @api_token,
|
8
|
+
"sources" => [@s.name], "message" => 'hello world',
|
9
|
+
"vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3',
|
10
|
+
"device_pin" => @c.device_pin, "device_port" => @c.device_port}
|
11
|
+
ssl_ctx = double("ssl_ctx")
|
12
|
+
ssl_ctx.stub(:key=).and_return('key')
|
13
|
+
ssl_ctx.stub(:cert=).and_return('cert')
|
14
|
+
OpenSSL::SSL::SSLContext.stub(:new).and_return(ssl_ctx)
|
15
|
+
OpenSSL::PKey::RSA.stub(:new)
|
16
|
+
OpenSSL::X509::Certificate.stub(:new)
|
20
17
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
@ssl_socket.stub!(:write)
|
25
|
-
@ssl_socket.stub!(:close)
|
26
|
-
OpenSSL::SSL::SSLSocket.stub!(:new).and_return(@ssl_socket)
|
27
|
-
end
|
18
|
+
tcp_socket = double("tcp_socket")
|
19
|
+
tcp_socket.stub(:close)
|
20
|
+
TCPSocket.stub(:new).and_return(tcp_socket)
|
28
21
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
22
|
+
@ssl_socket = double("ssl_socket")
|
23
|
+
@ssl_socket.stub(:sync=)
|
24
|
+
@ssl_socket.stub(:connect)
|
25
|
+
@ssl_socket.stub(:write)
|
26
|
+
@ssl_socket.stub(:close)
|
27
|
+
OpenSSL::SSL::SSLSocket.stub(:new).and_return(@ssl_socket)
|
28
|
+
end
|
33
29
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
Iphone.ping(@params)
|
39
|
-
end
|
30
|
+
# TODO: This should really test SSLSocket.write
|
31
|
+
it "should ping apple" do
|
32
|
+
Apple.ping(@params)
|
33
|
+
end
|
40
34
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
apn_message.start_with?("\000\000 \253\315\000g").should be_true
|
48
|
-
JSON.parse(apn_message.sub("\000\000 \253\315\000g","")).should == expected_hash
|
49
|
-
end
|
35
|
+
it "should log deprecation on iphone ping" do
|
36
|
+
Iphone.should_receive(
|
37
|
+
:log
|
38
|
+
).once.with("DEPRECATION WARNING: 'iphone' is a deprecated device_type, use 'apple' instead")
|
39
|
+
Iphone.ping(@params)
|
40
|
+
end
|
50
41
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
end
|
42
|
+
it "should compute apn_message" do
|
43
|
+
expected_hash = {
|
44
|
+
"aps"=>{"vibrate"=>"5", "badge"=>5, "alert"=>"hello world", "sound"=>"hello.mp3"},
|
45
|
+
"do_sync"=>["SampleAdapter"]
|
46
|
+
}
|
47
|
+
apn_message = Apple.apn_message(@params)
|
48
|
+
apn_message[0, 7].inspect.gsub("\"", "").should == "\\x00\\x00 \\xAB\\xCD\\x00g"
|
49
|
+
JSON.parse(apn_message[7, apn_message.length]).should == expected_hash
|
50
|
+
end
|
61
51
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
52
|
+
it "should compute apn_message with source array" do
|
53
|
+
@params['sources'] << 'SimpleAdapter'
|
54
|
+
expected_hash = {
|
55
|
+
"aps"=>{"vibrate"=>"5", "badge"=>5, "alert"=>"hello world", "sound"=>"hello.mp3"},
|
56
|
+
"do_sync"=>["SampleAdapter", "SimpleAdapter"]
|
57
|
+
}
|
58
|
+
apn_message = Apple.apn_message(@params)
|
59
|
+
apn_message[0, 7].inspect.gsub("\"", "").should == "\\x00\\x00 \\xAB\\xCD\\x00w"
|
60
|
+
JSON.parse(apn_message[7, apn_message.length]).should == expected_hash
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should raise SocketError if socket fails" do
|
64
|
+
error = 'socket error'
|
65
|
+
@ssl_socket.stub(:write).and_return { raise SocketError.new(error) }
|
66
|
+
Apple.should_receive(:log).once.with("Error while sending ping: #{error}")
|
67
|
+
lambda { Apple.ping(@params) }.should raise_error(SocketError,error)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should do nothing if no cert or host or port" do
|
71
|
+
Rhoconnect::Apple.stub(:get_config).and_return({:test => {:iphonecertfile=>"none"}})
|
72
|
+
Rhoconnect::Apple.should_receive(:get_config).once
|
73
|
+
OpenSSL::SSL::SSLContext.should_receive(:new).exactly(0).times
|
74
|
+
Apple.ping(@params)
|
75
|
+
end
|
76
76
|
end
|
data/spec/ping/gcm_spec.rb
CHANGED
@@ -1,99 +1,98 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__),'..','spec_helper')
|
2
2
|
|
3
3
|
describe "Ping Android GCM" do
|
4
|
-
|
4
|
+
include_examples "SharedRhoconnectHelper", :rhoconnect_data => false
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
6
|
+
before(:each) 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 = double('response')
|
11
|
+
Rhoconnect.settings[:gcm_api_key] = 'validkey'
|
12
|
+
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
14
|
+
it "should ping gcm successfully" do
|
15
|
+
result = 'id=0:34234234134254%abc123\n'
|
16
|
+
@response.stub(:code).and_return(200)
|
17
|
+
@response.stub(:body).and_return(result)
|
18
|
+
@response.stub(:headers).and_return({})
|
19
|
+
@response.stub(:return!).and_return(@response)
|
20
|
+
setup_post_yield(@response)
|
21
|
+
Gcm.ping(@params).body.should == result
|
22
|
+
end
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
24
|
+
it "should raise error on missing gcm_api_key setting" do
|
25
|
+
key = Rhoconnect.settings[:gcm_api_key].dup
|
26
|
+
Rhoconnect.settings[:gcm_api_key] = nil
|
27
|
+
lambda { Gcm.ping(@params) }.should raise_error(
|
28
|
+
Gcm::InvalidApiKey, 'Missing `:gcm_api_key:` option in settings/settings.yml'
|
29
|
+
)
|
30
|
+
Rhoconnect.settings[:gcm_api_key] = key
|
31
|
+
end
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
33
|
+
it "should ping gcm with 503 connection error" do
|
34
|
+
error = 'Connection refused'
|
35
|
+
@response.stub(:body).and_return(error)
|
36
|
+
RestClient.stub(:post).and_return { raise RestClient::Exception.new(@response,503) }
|
37
|
+
Gcm.should_receive(:log).twice
|
38
|
+
lambda { Gcm.ping(@params) }.should raise_error(RestClient::Exception)
|
39
|
+
end
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
41
|
+
it "should ping gcm with 200 error message" do
|
42
|
+
error = 'Error=QuotaExceeded'
|
43
|
+
@response.stub(:code).and_return(200)
|
44
|
+
@response.stub(:body).and_return(error)
|
45
|
+
@response.stub(:headers).and_return(nil)
|
46
|
+
setup_post_yield(@response)
|
47
|
+
Gcm.should_receive(:log).twice
|
48
|
+
lambda { Gcm.ping(@params) }.should raise_error(Gcm::GCMPingError, "GCM ping error: QuotaExceeded")
|
49
|
+
end
|
50
50
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
51
|
+
it "should fail to ping with bad authentication" do
|
52
|
+
error = 'Error=BadAuthentication'
|
53
|
+
@response.stub(:code).and_return(403)
|
54
|
+
@response.stub(:body).and_return(error)
|
55
|
+
@response.stub(:headers).and_return({})
|
56
|
+
setup_post_yield(@response)
|
57
|
+
Gcm.should_receive(:log).twice
|
58
|
+
lambda { Gcm.ping(@params) }.should raise_error(
|
59
|
+
Gcm::InvalidApiKey, "Invalid GCM api key. Obtain new api key from GCM service."
|
60
|
+
)
|
61
|
+
end
|
62
62
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
63
|
+
it "should ping gcm with 401 error message" do
|
64
|
+
@response.stub(:code).and_return(401)
|
65
|
+
@response.stub(:body).and_return('')
|
66
|
+
setup_post_yield(@response)
|
67
|
+
Gcm.should_receive(:log).twice
|
68
|
+
lambda { Gcm.ping(@params) }.should raise_error(
|
69
|
+
Gcm::InvalidApiKey, "Invalid GCM api key. Obtain new api key from GCM service."
|
70
|
+
)
|
71
|
+
end
|
72
72
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
}
|
73
|
+
it "should compute gcm_message" do
|
74
|
+
expected = {
|
75
|
+
'registration_ids' => [@c.device_pin],
|
76
|
+
'collapse_key' => "RAND_KEY",
|
77
|
+
'data' => {
|
78
|
+
'do_sync' => @s.name,
|
79
|
+
'alert' => "hello world",
|
80
|
+
'vibrate' => '5',
|
81
|
+
'sound' => "hello.mp3"
|
83
82
|
}
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
83
|
+
}
|
84
|
+
actual = Gcm.gcm_message(@params)
|
85
|
+
actual['collapse_key'] = "RAND_KEY" unless actual['collapse_key'].nil?
|
86
|
+
actual.should == expected
|
87
|
+
end
|
88
88
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
end
|
89
|
+
it "should trim empty or nil params from gcm_message" do
|
90
|
+
expected = {'registration_ids' => [@c.device_pin], 'collapse_key' => "RAND_KEY",
|
91
|
+
'data' => {'vibrate' => '5', 'do_sync' => '', 'sound' => "hello.mp3"} }
|
92
|
+
params = {"device_pin" => @c.device_pin,
|
93
|
+
"sources" => [], "message" => '', "vibrate" => '5', "sound" => 'hello.mp3'}
|
94
|
+
actual = Gcm.gcm_message(params)
|
95
|
+
actual['collapse_key'] = "RAND_KEY" unless actual['collapse_key'].nil?
|
96
|
+
actual.should == expected
|
98
97
|
end
|
99
98
|
end
|
@@ -1,58 +1,57 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__),'..','spec_helper')
|
2
2
|
|
3
3
|
describe "Ping using RhoConnect push" do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
}
|
4
|
+
include_examples "SharedRhoconnectHelper", :rhoconnect_data => false
|
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 = double('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
|
+
'alert' => "hello world",
|
50
|
+
'vibrate' => '5',
|
51
|
+
'sound' => "hello.mp3"
|
53
52
|
}
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
end
|
53
|
+
}
|
54
|
+
actual = RhoconnectPush.push_message(@params)
|
55
|
+
JSON.parse(actual).should == expected
|
56
|
+
end
|
58
57
|
end
|