rhoconnect 4.0.4 → 5.1.1
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.
- 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/jobs/ping_job_spec.rb
CHANGED
|
@@ -1,190 +1,189 @@
|
|
|
1
1
|
require File.join(File.dirname(__FILE__),'..','spec_helper')
|
|
2
2
|
|
|
3
3
|
describe "PingJob" do
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
before(:each) do
|
|
7
|
-
@u1_fields = {:login => 'testuser1'}
|
|
8
|
-
@u1 = User.create(@u1_fields)
|
|
9
|
-
@u1.password = 'testpass1'
|
|
10
|
-
@c1_fields = {
|
|
11
|
-
:device_type => 'Apple',
|
|
12
|
-
:device_pin => 'abcde',
|
|
13
|
-
:device_port => '3333',
|
|
14
|
-
:user_id => @u1.id,
|
|
15
|
-
:app_id => @a.id
|
|
16
|
-
}
|
|
17
|
-
@c1 = Client.create(@c1_fields,{:source_name => @s_fields[:name]})
|
|
18
|
-
@a.users << @u1.id
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
it "should perform apple ping with integer parameters" do
|
|
22
|
-
params = {"user_id" => @u.id, "api_token" => @api_token,
|
|
23
|
-
"sources" => [@s.name], "message" => 'hello world',
|
|
24
|
-
"vibrate" => 5, "badge" => '5', "sound" => 'hello.mp3',"phone_id"=>nil}
|
|
4
|
+
include_examples "SharedRhoconnectHelper", :rhoconnect_data => true
|
|
25
5
|
|
|
26
|
-
|
|
27
|
-
|
|
6
|
+
before(:each) do
|
|
7
|
+
@u1_fields = {:login => 'testuser1'}
|
|
8
|
+
@u1 = User.create(@u1_fields)
|
|
9
|
+
@u1.password = 'testpass1'
|
|
10
|
+
@c1_fields = {
|
|
11
|
+
:device_type => 'Apple',
|
|
12
|
+
:device_pin => 'abcde',
|
|
13
|
+
:device_port => '3333',
|
|
14
|
+
:user_id => @u1.id,
|
|
15
|
+
:app_id => @a.id
|
|
16
|
+
}
|
|
17
|
+
@c1 = Client.create(@c1_fields,{:source_name => @s_fields[:name]})
|
|
18
|
+
@a.users << @u1.id
|
|
19
|
+
end
|
|
28
20
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
21
|
+
it "should perform apple ping with integer parameters" do
|
|
22
|
+
params = {"user_id" => @u.id, "api_token" => @api_token,
|
|
23
|
+
"sources" => [@s.name], "message" => 'hello world',
|
|
24
|
+
"vibrate" => 5, "badge" => '5', "sound" => 'hello.mp3',"phone_id"=>nil}
|
|
33
25
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"sources" => [@s.name], "message" => 'hello world',
|
|
37
|
-
"vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3',"phone_id"=>nil}
|
|
38
|
-
Apple.should_receive(:ping).once.with({'device_pin' => @c.device_pin,
|
|
39
|
-
'device_port' => @c.device_port}.merge!(params))
|
|
40
|
-
PingJob.perform(params)
|
|
41
|
-
end
|
|
26
|
+
scrubbed_params = params.dup
|
|
27
|
+
scrubbed_params['vibrate'] = '5'
|
|
42
28
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
@c.device_type = 'unknown_device_type'
|
|
48
|
-
PingJob.should_receive(:log).once.with("Dropping ping request for unsupported platform '#{@c.device_type}'")
|
|
49
|
-
PingJob.perform(params)
|
|
50
|
-
end
|
|
29
|
+
Apple.should_receive(:ping).once.with({'device_pin' => @c.device_pin,
|
|
30
|
+
'device_port' => @c.device_port}.merge!(scrubbed_params))
|
|
31
|
+
PingJob.perform(params)
|
|
32
|
+
end
|
|
51
33
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
34
|
+
it "should perform apple ping" do
|
|
35
|
+
params = {"user_id" => @u.id, "api_token" => @api_token,
|
|
36
|
+
"sources" => [@s.name], "message" => 'hello world',
|
|
37
|
+
"vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3',"phone_id"=>nil}
|
|
38
|
+
Apple.should_receive(:ping).once.with({'device_pin' => @c.device_pin,
|
|
39
|
+
'device_port' => @c.device_port}.merge!(params))
|
|
40
|
+
PingJob.perform(params)
|
|
41
|
+
end
|
|
60
42
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
it "should drop ping if it's already in user's device pin list" do
|
|
72
|
-
params = {"user_id" => @u.id, "api_token" => @api_token,
|
|
73
|
-
"sources" => [@s.name], "message" => 'hello world',
|
|
74
|
-
"vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3',"phone_id"=>nil}
|
|
75
|
-
# another client with the same device pin ...
|
|
76
|
-
@c_fields.delete(:id)
|
|
77
|
-
@c1 = Client.create(@c_fields,{:source_name => @s_fields[:name]})
|
|
78
|
-
# and yet another one ...
|
|
79
|
-
@c_fields.delete(:id)
|
|
80
|
-
@c2 = Client.create(@c_fields,{:source_name => @s_fields[:name]})
|
|
81
|
-
|
|
82
|
-
Apple.should_receive(:ping).with({'device_pin' => @c.device_pin, 'device_port' => @c.device_port}.merge!(params))
|
|
83
|
-
PingJob.should_receive(:log).twice.with(/Dropping ping request for client/)
|
|
84
|
-
lambda { PingJob.perform(params) }.should_not raise_error
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
it "should drop ping if it's already in user's phone id list and device pin is different" do
|
|
88
|
-
params = {"user_id" => @u.id, "api_token" => @api_token,
|
|
89
|
-
"sources" => [@s.name], "message" => 'hello world',
|
|
90
|
-
"vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3'}
|
|
91
|
-
@c.phone_id = '3'
|
|
92
|
-
@c_fields.merge!(:phone_id => '3')
|
|
93
|
-
# another client with the same phone id..
|
|
94
|
-
@c_fields.delete(:id)
|
|
95
|
-
@c1 = Client.create(@c_fields,{:source_name => @s_fields[:name]})
|
|
96
|
-
# yet another...
|
|
97
|
-
@c_fields.delete(:id)
|
|
98
|
-
@c2 = Client.create(@c_fields,{:source_name => @s_fields[:name]})
|
|
99
|
-
|
|
100
|
-
Apple.should_receive(:ping).with({'device_pin' => @c.device_pin, 'phone_id' => @c.phone_id, 'device_port' => @c.device_port}.merge!(params))
|
|
101
|
-
PingJob.should_receive(:log).twice.with(/Dropping ping request for client/)
|
|
102
|
-
lambda { PingJob.perform(params) }.should_not raise_error
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
it "should ping two different users from two different devices - Apple and GCM" do
|
|
106
|
-
params = {"user_id" => [ @u.id, @u1.id], "api_token" => @api_token,
|
|
107
|
-
"sources" => [@s.name], "message" => 'hello world',
|
|
108
|
-
"vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3', 'phone_id' => nil }
|
|
109
|
-
@c.phone_id = '3'
|
|
110
|
-
|
|
111
|
-
scrubbed_params = params.dup
|
|
112
|
-
scrubbed_params['vibrate'] = '5'
|
|
113
|
-
@c1.device_push_type = 'Gcm'
|
|
114
|
-
|
|
115
|
-
Apple.should_receive(:ping).with(params.merge!({'device_pin' => @c.device_pin, 'phone_id' => @c.phone_id, 'device_port' => @c.device_port}))
|
|
116
|
-
Gcm.should_receive(:ping).with({'device_pin' => @c1.device_pin, 'device_port' => @c1.device_port}.merge!(scrubbed_params))
|
|
117
|
-
PingJob.perform(params)
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
it "should drop ping with two different users from the same device" do
|
|
121
|
-
params = {"user_id" => [ @u.id, @u1.id], "api_token" => @api_token,
|
|
122
|
-
"sources" => [@s.name], "message" => 'hello world',
|
|
123
|
-
"vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3'}
|
|
124
|
-
@c.phone_id = '3'
|
|
125
|
-
@c1.phone_id = '3'
|
|
126
|
-
|
|
127
|
-
Apple.should_receive(:ping).with({'device_pin' => @c.device_pin, 'phone_id' => @c.phone_id, 'device_port' => @c.device_port}.merge!(params))
|
|
128
|
-
PingJob.should_receive(:log).once.with(/Dropping ping request for client/)
|
|
129
|
-
lambda { PingJob.perform(params) }.should_not raise_error
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
it "should drop ping with two different users with the same pin" do
|
|
133
|
-
params = {"user_id" => [ @u.id, @u1.id], "api_token" => @api_token,
|
|
134
|
-
"sources" => [@s.name], "message" => 'hello world', "phone_id" => nil,
|
|
135
|
-
"vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3'}
|
|
136
|
-
@c1.device_pin = @c.device_pin
|
|
137
|
-
|
|
138
|
-
Apple.should_receive(:ping).with({'device_pin' => @c.device_pin, 'device_port' => @c.device_port}.merge!(params))
|
|
139
|
-
PingJob.should_receive(:log).once.with(/Dropping ping request for client/)
|
|
140
|
-
lambda { PingJob.perform(params) }.should_not raise_error
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
it "should process all pings even if some of them are failing" do
|
|
144
|
-
params = {"user_id" => [ @u.id, @u1.id], "api_token" => @api_token,
|
|
145
|
-
"sources" => [@s.name], "message" => 'hello world',
|
|
146
|
-
"vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3', 'phone_id' => nil }
|
|
147
|
-
@c.phone_id = '3'
|
|
148
|
-
|
|
149
|
-
scrubbed_params = params.dup
|
|
150
|
-
scrubbed_params['vibrate'] = '5'
|
|
151
|
-
@c1.device_push_type = 'Gcm'
|
|
152
|
-
|
|
153
|
-
Apple.should_receive(:ping).with(params.merge!({'device_pin' => @c.device_pin, 'phone_id' => @c.phone_id, 'device_port' => @c.device_port})).and_return { raise SocketError.new("Socket failure") }
|
|
154
|
-
Gcm.should_receive(:ping).with({'device_pin' => @c1.device_pin, 'device_port' => @c1.device_port}.merge!(scrubbed_params))
|
|
155
|
-
exception_raised = false
|
|
156
|
-
begin
|
|
157
|
-
PingJob.perform(params)
|
|
158
|
-
rescue Exception => e
|
|
159
|
-
exception_raised = true
|
|
160
|
-
end
|
|
161
|
-
exception_raised.should == true
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
it "should skip ping for unknown user or user with no clients" do
|
|
165
|
-
params = {"user_id" => [ 'fake_user' ], "api_token" => @api_token,
|
|
166
|
-
"sources" => [@s.name], "message" => 'hello world',
|
|
167
|
-
"vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3', 'phone_id' => nil }
|
|
168
|
-
PingJob.should_receive(:log).once.with(/Skipping ping for unknown user 'fake_user' or 'fake_user' has no registered clients.../)
|
|
169
|
-
PingJob.perform(params)
|
|
170
|
-
end
|
|
43
|
+
it "should skip ping for the unknown platform" do
|
|
44
|
+
params = {"user_id" => @u.id, "api_token" => @api_token,
|
|
45
|
+
"sources" => [@s.name], "message" => 'hello world',
|
|
46
|
+
"vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3',"phone_id"=>nil}
|
|
47
|
+
@c.device_type = 'unknown_device_type'
|
|
48
|
+
PingJob.should_receive(:log).once.with("Dropping ping request for unsupported platform '#{@c.device_type}'")
|
|
49
|
+
PingJob.perform(params)
|
|
50
|
+
end
|
|
171
51
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
@
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
52
|
+
it "should skip ping for empty device_type" do
|
|
53
|
+
params = {"user_id" => @u.id, "api_token" => @api_token,
|
|
54
|
+
"sources" => [@s.name], "message" => 'hello world',
|
|
55
|
+
"vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3'}
|
|
56
|
+
@c.device_type = nil
|
|
57
|
+
PingJob.should_receive(:log).once.with("Skipping ping for non-registered client_id '#{@c.id}'...")
|
|
58
|
+
lambda { PingJob.perform(params) }.should_not raise_error
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it "should skip ping for empty device_pin" do
|
|
62
|
+
params = {"user_id" => @u.id, "api_token" => @api_token,
|
|
63
|
+
"sources" => [@s.name], "message" => 'hello world',
|
|
64
|
+
"vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3'}
|
|
65
|
+
@c.device_type = 'Android'
|
|
66
|
+
@c.device_pin = nil
|
|
67
|
+
PingJob.should_receive(:log).once.with("Skipping ping for non-registered client_id '#{@c.id}'...")
|
|
68
|
+
lambda { PingJob.perform(params) }.should_not raise_error
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "should drop ping if it's already in user's device pin list" do
|
|
72
|
+
params = {"user_id" => @u.id, "api_token" => @api_token,
|
|
73
|
+
"sources" => [@s.name], "message" => 'hello world',
|
|
74
|
+
"vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3',"phone_id"=>nil}
|
|
75
|
+
# another client with the same device pin ...
|
|
76
|
+
@c_fields.delete(:id)
|
|
77
|
+
@c1 = Client.create(@c_fields,{:source_name => @s_fields[:name]})
|
|
78
|
+
# and yet another one ...
|
|
79
|
+
@c_fields.delete(:id)
|
|
80
|
+
@c2 = Client.create(@c_fields,{:source_name => @s_fields[:name]})
|
|
81
|
+
|
|
82
|
+
Apple.should_receive(:ping).with({'device_pin' => @c.device_pin, 'device_port' => @c.device_port}.merge!(params))
|
|
83
|
+
PingJob.should_receive(:log).twice.with(/Dropping ping request for client/)
|
|
84
|
+
lambda { PingJob.perform(params) }.should_not raise_error
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it "should drop ping if it's already in user's phone id list and device pin is different" do
|
|
88
|
+
params = {"user_id" => @u.id, "api_token" => @api_token,
|
|
89
|
+
"sources" => [@s.name], "message" => 'hello world',
|
|
90
|
+
"vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3'}
|
|
91
|
+
@c.phone_id = '3'
|
|
92
|
+
@c_fields.merge!(:phone_id => '3')
|
|
93
|
+
# another client with the same phone id..
|
|
94
|
+
@c_fields.delete(:id)
|
|
95
|
+
@c1 = Client.create(@c_fields,{:source_name => @s_fields[:name]})
|
|
96
|
+
# yet another...
|
|
97
|
+
@c_fields.delete(:id)
|
|
98
|
+
@c2 = Client.create(@c_fields,{:source_name => @s_fields[:name]})
|
|
99
|
+
|
|
100
|
+
Apple.should_receive(:ping).with({'device_pin' => @c.device_pin, 'phone_id' => @c.phone_id, 'device_port' => @c.device_port}.merge!(params))
|
|
101
|
+
PingJob.should_receive(:log).twice.with(/Dropping ping request for client/)
|
|
102
|
+
lambda { PingJob.perform(params) }.should_not raise_error
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it "should ping two different users from two different devices - Apple and GCM" do
|
|
106
|
+
params = {"user_id" => [ @u.id, @u1.id], "api_token" => @api_token,
|
|
107
|
+
"sources" => [@s.name], "message" => 'hello world',
|
|
108
|
+
"vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3', 'phone_id' => nil }
|
|
109
|
+
@c.phone_id = '3'
|
|
110
|
+
|
|
111
|
+
scrubbed_params = params.dup
|
|
112
|
+
scrubbed_params['vibrate'] = '5'
|
|
113
|
+
@c1.device_push_type = 'Gcm'
|
|
114
|
+
|
|
115
|
+
Apple.should_receive(:ping).with(params.merge!({'device_pin' => @c.device_pin, 'phone_id' => @c.phone_id, 'device_port' => @c.device_port}))
|
|
116
|
+
Gcm.should_receive(:ping).with({'device_pin' => @c1.device_pin, 'device_port' => @c1.device_port}.merge!(scrubbed_params))
|
|
117
|
+
PingJob.perform(params)
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
it "should drop ping with two different users from the same device" do
|
|
121
|
+
params = {"user_id" => [ @u.id, @u1.id], "api_token" => @api_token,
|
|
122
|
+
"sources" => [@s.name], "message" => 'hello world',
|
|
123
|
+
"vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3'}
|
|
124
|
+
@c.phone_id = '3'
|
|
125
|
+
@c1.phone_id = '3'
|
|
126
|
+
|
|
127
|
+
Apple.should_receive(:ping).with({'device_pin' => @c.device_pin, 'phone_id' => @c.phone_id, 'device_port' => @c.device_port}.merge!(params))
|
|
128
|
+
PingJob.should_receive(:log).once.with(/Dropping ping request for client/)
|
|
129
|
+
lambda { PingJob.perform(params) }.should_not raise_error
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
it "should drop ping with two different users with the same pin" do
|
|
133
|
+
params = {"user_id" => [ @u.id, @u1.id], "api_token" => @api_token,
|
|
134
|
+
"sources" => [@s.name], "message" => 'hello world', "phone_id" => nil,
|
|
135
|
+
"vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3'}
|
|
136
|
+
@c1.device_pin = @c.device_pin
|
|
137
|
+
|
|
138
|
+
Apple.should_receive(:ping).with({'device_pin' => @c.device_pin, 'device_port' => @c.device_port}.merge!(params))
|
|
139
|
+
PingJob.should_receive(:log).once.with(/Dropping ping request for client/)
|
|
140
|
+
lambda { PingJob.perform(params) }.should_not raise_error
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
it "should process all pings even if some of them are failing" do
|
|
144
|
+
params = {"user_id" => [ @u.id, @u1.id], "api_token" => @api_token,
|
|
145
|
+
"sources" => [@s.name], "message" => 'hello world',
|
|
146
|
+
"vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3', 'phone_id' => nil }
|
|
147
|
+
@c.phone_id = '3'
|
|
148
|
+
|
|
149
|
+
scrubbed_params = params.dup
|
|
150
|
+
scrubbed_params['vibrate'] = '5'
|
|
151
|
+
@c1.device_push_type = 'Gcm'
|
|
152
|
+
|
|
153
|
+
Apple.should_receive(:ping).with(params.merge!({'device_pin' => @c.device_pin, 'phone_id' => @c.phone_id, 'device_port' => @c.device_port})).and_return { raise SocketError.new("Socket failure") }
|
|
154
|
+
Gcm.should_receive(:ping).with({'device_pin' => @c1.device_pin, 'device_port' => @c1.device_port}.merge!(scrubbed_params))
|
|
155
|
+
exception_raised = false
|
|
156
|
+
begin
|
|
187
157
|
PingJob.perform(params)
|
|
158
|
+
rescue Exception => e
|
|
159
|
+
exception_raised = true
|
|
188
160
|
end
|
|
189
|
-
|
|
161
|
+
exception_raised.should == true
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
it "should skip ping for unknown user or user with no clients" do
|
|
165
|
+
params = {"user_id" => [ 'fake_user' ], "api_token" => @api_token,
|
|
166
|
+
"sources" => [@s.name], "message" => 'hello world',
|
|
167
|
+
"vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3', 'phone_id' => nil }
|
|
168
|
+
PingJob.should_receive(:log).once.with(/Skipping ping for unknown user 'fake_user' or 'fake_user' has no registered clients.../)
|
|
169
|
+
PingJob.perform(params)
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
it "should process ping for device_push_type if available" do
|
|
173
|
+
@c.device_push_type = 'rhoconnect_push'
|
|
174
|
+
@c.device_port = nil
|
|
175
|
+
params = {
|
|
176
|
+
'user_id' => @u.id,
|
|
177
|
+
'message' => 'hello world',
|
|
178
|
+
'device_port' => '',
|
|
179
|
+
'vibrate' => '',
|
|
180
|
+
'phone_id' => nil
|
|
181
|
+
}
|
|
182
|
+
scrubbed_params = params.dup
|
|
183
|
+
|
|
184
|
+
RhoconnectPush.should_receive(:ping).once.with(
|
|
185
|
+
{'device_pin' => @c.device_pin}.merge!(scrubbed_params)
|
|
186
|
+
)
|
|
187
|
+
PingJob.perform(params)
|
|
188
|
+
end
|
|
190
189
|
end
|
|
@@ -1,30 +1,29 @@
|
|
|
1
1
|
require File.join(File.dirname(__FILE__),'..','spec_helper')
|
|
2
2
|
|
|
3
3
|
describe "SourceJob" do
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
it "should perform process_query" do
|
|
12
|
-
set_state('test_db_storage' => @data)
|
|
13
|
-
SourceJob.perform('query',@s.id,@s.app_id,@s.user_id,nil)
|
|
14
|
-
verify_doc_result(@s, {:md => @data,
|
|
15
|
-
:md_size => @data.size.to_s})
|
|
16
|
-
end
|
|
4
|
+
include_examples "SharedRhoconnectHelper", :rhoconnect_data => true
|
|
5
|
+
before(:each) do
|
|
6
|
+
@s = Source.load(@s_fields[:name],@s_params)
|
|
7
|
+
@s.query_queue = 'query'
|
|
8
|
+
@s.cud_queue = 'cud'
|
|
9
|
+
end
|
|
17
10
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
11
|
+
it "should perform process_query" do
|
|
12
|
+
set_state('test_db_storage' => @data)
|
|
13
|
+
SourceJob.perform('query',@s.id,@s.app_id,@s.user_id,nil)
|
|
14
|
+
verify_doc_result(@s, {:md => @data,
|
|
15
|
+
:md_size => @data.size.to_s})
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "should perform process_cud" do
|
|
19
|
+
expected = {'backend_id'=>@product1}
|
|
20
|
+
@product1['link'] = 'abc'
|
|
21
|
+
@s.push_queue(:create, @c.id, [[@s.name, [['1', @product1]]]])
|
|
22
|
+
SourceJob.perform('cud',@s.id,@s.app_id,@s.user_id,nil)
|
|
23
|
+
verify_source_queue_data(@s, :create => [])
|
|
24
|
+
verify_doc_result(@s, {:md => expected,
|
|
25
|
+
:md_size => expected.size.to_s})
|
|
26
|
+
verify_doc_result(@c, {:cd => expected,
|
|
27
|
+
:cd_size => expected.size.to_s})
|
|
28
|
+
end
|
|
30
29
|
end
|
data/spec/license_spec.rb
CHANGED
|
@@ -1,68 +1,67 @@
|
|
|
1
1
|
require File.join(File.dirname(__FILE__),'spec_helper')
|
|
2
2
|
|
|
3
3
|
describe "License" do
|
|
4
|
-
|
|
5
|
-
before(:each) do
|
|
6
|
-
Store.put_value(License::CLIENT_DOCKEY,nil)
|
|
7
|
-
end
|
|
4
|
+
include_examples "SharedRhoconnectHelper", :rhoconnect_data => false
|
|
8
5
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
license.licensee.should == 'Rhomobile'
|
|
13
|
-
license.seats.should == 10
|
|
14
|
-
license.issued.should == 'Fri Apr 23 17:20:13 -0700 2010'
|
|
15
|
-
end
|
|
6
|
+
before(:each) do
|
|
7
|
+
Store.put_value(License::CLIENT_DOCKEY,nil)
|
|
8
|
+
end
|
|
16
9
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
10
|
+
it "should decrypt license" do
|
|
11
|
+
license = License.new
|
|
12
|
+
license.rhoconnect_version.should == 'Version 1'
|
|
13
|
+
license.licensee.should == 'Rhomobile'
|
|
14
|
+
license.seats.should == 10
|
|
15
|
+
license.issued.should == 'Fri Apr 23 17:20:13 -0700 2010'
|
|
16
|
+
end
|
|
24
17
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
18
|
+
it "should use generator license file when there is license load error" do
|
|
19
|
+
path_to_license = File.join(File.dirname(__FILE__), '..', 'generators', 'templates', 'application', 'settings', 'license.key')
|
|
20
|
+
license = IO.read(path_to_license).strip
|
|
21
|
+
Rhoconnect.stub(:get_config).and_return({Rhoconnect.environment.to_sym => {}})
|
|
22
|
+
License.new.license.should == license
|
|
23
|
+
# lambda { License.new }.should raise_error(LicenseException, "Error verifying license.")
|
|
24
|
+
end
|
|
29
25
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
)
|
|
35
|
-
end
|
|
26
|
+
it "should verify # of seats before adding" do
|
|
27
|
+
License.new.check_and_use_seat
|
|
28
|
+
Store.get_value(License::CLIENT_DOCKEY).to_i.should == 1
|
|
29
|
+
end
|
|
36
30
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
31
|
+
it "should raise exception when seats are exceeded" do
|
|
32
|
+
Store.put_value(License::CLIENT_DOCKEY,10)
|
|
33
|
+
lambda { License.new.check_and_use_seat }.should raise_error(
|
|
34
|
+
LicenseSeatsExceededException, "WARNING: Maximum # of devices exceeded for this license."
|
|
35
|
+
)
|
|
36
|
+
end
|
|
42
37
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
38
|
+
it "should free license seat" do
|
|
39
|
+
Store.put_value(License::CLIENT_DOCKEY,5)
|
|
40
|
+
License.new.free_seat
|
|
41
|
+
Store.get_value(License::CLIENT_DOCKEY).to_i.should == 4
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it "should get # of available seats" do
|
|
45
|
+
license = License.new
|
|
46
|
+
license.check_and_use_seat
|
|
47
|
+
license.available.should == 9
|
|
48
|
+
end
|
|
48
49
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
it "should use RHOSYNC_LICENSE env var" do
|
|
59
|
-
ENV['RHOSYNC_LICENSE'] = 'b749cbe6e029400e688360468624388e2cb7f6a1e72c91d4686a1b8c9d37b72c3e1872ec9f369d481220e10759c18e16'
|
|
60
|
-
license = License.new
|
|
61
|
-
license.licensee.should == 'Rhohub'
|
|
62
|
-
license.seats.should == 5
|
|
63
|
-
license.issued.should == 'Tue Aug 10 16:14:24 -0700 2010'
|
|
64
|
-
ENV.delete('RHOSYNC_LICENSE')
|
|
65
|
-
end
|
|
50
|
+
it "should use RHOCONNECT_LICENSE env var" do
|
|
51
|
+
ENV['RHOCONNECT_LICENSE'] = 'b749cbe6e029400e688360468624388e2cb7f6a1e72c91d4686a1b8c9d37b72c3e1872ec9f369d481220e10759c18e16'
|
|
52
|
+
license = License.new
|
|
53
|
+
license.licensee.should == 'Rhohub'
|
|
54
|
+
license.seats.should == 5
|
|
55
|
+
license.issued.should == 'Tue Aug 10 16:14:24 -0700 2010'
|
|
56
|
+
ENV.delete('RHOCONNECT_LICENSE')
|
|
66
57
|
end
|
|
67
58
|
|
|
59
|
+
it "should use RHOSYNC_LICENSE env var" do
|
|
60
|
+
ENV['RHOSYNC_LICENSE'] = 'b749cbe6e029400e688360468624388e2cb7f6a1e72c91d4686a1b8c9d37b72c3e1872ec9f369d481220e10759c18e16'
|
|
61
|
+
license = License.new
|
|
62
|
+
license.licensee.should == 'Rhohub'
|
|
63
|
+
license.seats.should == 5
|
|
64
|
+
license.issued.should == 'Tue Aug 10 16:14:24 -0700 2010'
|
|
65
|
+
ENV.delete('RHOSYNC_LICENSE')
|
|
66
|
+
end
|
|
68
67
|
end
|