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.
Files changed (151) hide show
  1. checksums.yaml +5 -13
  2. data/CHANGELOG.md +54 -5
  3. data/CREDITS +219 -219
  4. data/Gemfile +2 -2
  5. data/Gemfile.lock +68 -79
  6. data/Rakefile +1 -2
  7. data/bench/benchapp/spec/models/ruby/mock_adapter_spec.rb +17 -17
  8. data/bench/benchapp/spec/models/ruby/queue_mock_adapter_spec.rb +17 -17
  9. data/bench/benchapp/spec/spec_helper.rb +3 -3
  10. data/bench/blobapp/spec/models/ruby/blob_adapter_spec.rb +17 -17
  11. data/bench/blobapp/spec/spec_helper.rb +3 -3
  12. data/bench/lib/bench/runner.rb +1 -69
  13. data/bench/lib/bench.rb +18 -18
  14. data/bench/spec/mock_adapter_spec.rb +54 -55
  15. data/bench/spec/mock_client_spec.rb +47 -48
  16. data/bench/spec/result_spec.rb +41 -44
  17. data/bench/spec/utils_spec.rb +24 -25
  18. data/commands/generators/app.rb +7 -5
  19. data/commands/generators/controller.rb +7 -5
  20. data/commands/generators/model.rb +7 -5
  21. data/commands/generators/source.rb +7 -5
  22. data/commands/parser.rb +1 -1
  23. data/commands/redis/redis_download.rb +1 -1
  24. data/doc/async-jobs.txt +9 -9
  25. data/doc/supported-platforms.txt +0 -2
  26. data/generators/rhoconnect.rb +92 -212
  27. data/generators/templates/application/rcgemfile +3 -3
  28. data/generators/templates/application/spec/application_controller_spec.rb +14 -16
  29. data/generators/templates/application/spec/js_spec.rb +20 -20
  30. data/generators/templates/application/spec/spec_helper.rb +1 -1
  31. data/generators/templates/source/controllers/ruby/controller_spec.rb +18 -19
  32. data/generators/templates/source/models/ruby/model_spec.rb +17 -17
  33. data/install.sh +10 -21
  34. data/installer/unix-like/rho_connect_install_constants.rb +5 -5
  35. data/installer/unix-like/rho_connect_install_installers.rb +4 -4
  36. data/installer/utils/constants.rb +6 -6
  37. data/installer/utils/nix_install_test.rb +29 -29
  38. data/installer/utils/package_upload/repos.rake +16 -26
  39. data/js-adapters/node.rb +4 -4
  40. data/js-adapters/node_channel.rb +4 -8
  41. data/lib/rhoconnect/db_adapter.rb +13 -13
  42. data/lib/rhoconnect/handler/changes/engine.rb +1 -1
  43. data/lib/rhoconnect/jobs/bulk_data_job.rb +29 -29
  44. data/lib/rhoconnect/license.rb +7 -7
  45. data/lib/rhoconnect/model/helpers/find_duplicates_on_update.rb +13 -13
  46. data/lib/rhoconnect/ping/apple.rb +4 -4
  47. data/lib/rhoconnect/server.rb +2 -2
  48. data/lib/rhoconnect/source.rb +2 -2
  49. data/lib/rhoconnect/store.rb +12 -6
  50. data/lib/rhoconnect/utilities.rb +2 -2
  51. data/lib/rhoconnect/version.rb +1 -1
  52. data/lib/rhoconnect.rb +6 -4
  53. data/rhoconnect.gemspec +5 -6
  54. data/spec/api/api_helper.rb +1 -1
  55. data/spec/api/app/fast_delete_spec.rb +22 -22
  56. data/spec/api/app/fast_insert_spec.rb +23 -23
  57. data/spec/api/app/fast_update_spec.rb +63 -63
  58. data/spec/api/app/push_deletes_spec.rb +11 -13
  59. data/spec/api/app/push_objects_spec.rb +39 -39
  60. data/spec/api/client/client_get_db_doc_spec.rb +29 -29
  61. data/spec/api/client/client_set_db_doc_spec.rb +11 -11
  62. data/spec/api/client/get_client_params_spec.rb +29 -29
  63. data/spec/api/client/list_client_docs_spec.rb +32 -34
  64. data/spec/api/client/reset_spec.rb +30 -30
  65. data/spec/api/readstate/set_refresh_time_spec.rb +43 -43
  66. data/spec/api/source/get_source_params_spec.rb +32 -34
  67. data/spec/api/source/list_sources_spec.rb +13 -13
  68. data/spec/api/source/update_source_params_spec.rb +19 -19
  69. data/spec/api/store/get_db_doc_spec.rb +27 -27
  70. data/spec/api/store/set_db_doc_spec.rb +38 -38
  71. data/spec/api/system/adapter_spec.rb +27 -29
  72. data/spec/api/system/get_license_info_spec.rb +11 -11
  73. data/spec/api/system/login_spec.rb +37 -37
  74. data/spec/api/system/reset_spec.rb +15 -15
  75. data/spec/api/system/stats_spec.rb +70 -71
  76. data/spec/api/user/create_user_spec.rb +37 -37
  77. data/spec/api/user/delete_client_spec.rb +7 -7
  78. data/spec/api/user/delete_user_spec.rb +62 -62
  79. data/spec/api/user/list_clients_spec.rb +24 -24
  80. data/spec/api/user/list_source_docs_spec.rb +29 -29
  81. data/spec/api/user/list_users_spec.rb +22 -22
  82. data/spec/api/user/ping_spec.rb +18 -18
  83. data/spec/api/user/show_user_spec.rb +10 -10
  84. data/spec/api/user/update_user_spec.rb +43 -43
  85. data/spec/api/user/user_get_db_doc_spec.rb +12 -12
  86. data/spec/api/user/user_set_db_doc_spec.rb +37 -37
  87. data/spec/api_token_spec.rb +8 -8
  88. data/spec/app_spec.rb +18 -17
  89. data/spec/apps/jstestapp/settings/settings.yml +2 -0
  90. data/spec/async_spec.rb +9 -11
  91. data/spec/bulk_data/bulk_data_spec.rb +120 -120
  92. data/spec/cli/cli_spec.rb +50 -53
  93. data/spec/client_spec.rb +105 -105
  94. data/spec/client_sync_spec.rb +529 -528
  95. data/spec/controllers/js_base_spec.rb +147 -141
  96. data/spec/doc/doc_spec.rb +51 -52
  97. data/spec/document_spec.rb +58 -58
  98. data/spec/dynamic_adapter_spec.rb +33 -36
  99. data/spec/generator/generator_spec.rb +76 -42
  100. data/spec/jobs/bulk_data_job_spec.rb +101 -102
  101. data/spec/jobs/ping_job_spec.rb +176 -177
  102. data/spec/jobs/source_job_spec.rb +24 -25
  103. data/spec/license_spec.rb +54 -55
  104. data/spec/models/js_base_spec.rb +121 -120
  105. data/spec/perf/bulk_data_perf_spec.rb +23 -24
  106. data/spec/perf/perf_spec_helper.rb +7 -7
  107. data/spec/perf/store_perf_spec.rb +139 -140
  108. data/spec/ping/apple_spec.rb +65 -65
  109. data/spec/ping/gcm_spec.rb +83 -84
  110. data/spec/ping/rhoconnect_push_spec.rb +52 -53
  111. data/spec/predefined_adapters/rho_internal_bench_adapter_controller_js_spec.rb +100 -101
  112. data/spec/predefined_adapters/rho_internal_js_bench_adapter_js_spec.rb +29 -31
  113. data/spec/read_state_spec.rb +24 -25
  114. data/spec/rhoconnect_spec.rb +7 -7
  115. data/spec/server/server_spec.rb +664 -662
  116. data/spec/server/stats_spec.rb +12 -12
  117. data/spec/source_adapter_spec.rb +124 -125
  118. data/spec/source_spec.rb +148 -149
  119. data/spec/source_sync_spec.rb +736 -736
  120. data/spec/spec_helper.rb +4 -5
  121. data/spec/stats/record_spec.rb +22 -21
  122. data/spec/store_orm_spec.rb +48 -48
  123. data/spec/store_spec.rb +428 -426
  124. data/spec/support/shared_examples.rb +5 -7
  125. data/spec/sync_states_spec.rb +67 -67
  126. data/spec/test_methods_spec.rb +121 -123
  127. data/spec/testdata/10000-data.txt +0 -0
  128. data/spec/testdata/5000-data.txt +0 -0
  129. data/spec/user_spec.rb +102 -102
  130. data/tasks/redis.rake +3 -3
  131. metadata +154 -195
  132. data/bench/benchapp/tmp/pids/passenger.9292.pid.lock +0 -0
  133. data/bench/benchapp/tmp/restart.txt +0 -0
  134. data/bench/blobapp/settings/license.key.bak +0 -2
  135. data/bench/blobapp/tmp/restart.txt +0 -0
  136. data/bench/lib/testdata/1-data.txt +0 -0
  137. data/bench/lib/testdata/10-data.txt +0 -0
  138. data/bench/lib/testdata/2-data.txt +0 -0
  139. data/bench/lib/testdata/250-data.txt +0 -0
  140. data/bench/lib/testdata/5-blob_data.txt +0 -0
  141. data/bench/lib/testdata/5-data.txt +0 -0
  142. data/bench/lib/testdata/50-data.txt +0 -0
  143. data/bench/lib/testdata/500-data.txt +0 -0
  144. data/doc/protocol.html +0 -1993
  145. data/spec/coverage/rcov/assets/0.2.3/jquery-1.3.2.min.js +0 -19
  146. data/spec/coverage/rcov/assets/0.2.3/jquery.tablesorter.min.js +0 -15
  147. data/spec/coverage/rcov/assets/0.2.3/print.css +0 -12
  148. data/spec/coverage/rcov/assets/0.2.3/rcov.js +0 -42
  149. data/spec/coverage/rcov/assets/0.2.3/screen.css +0 -270
  150. data/spec/coverage/rcov/index.html +0 -88
  151. data/spec/generator/generator_spec_helper.rb +0 -9
@@ -1,190 +1,189 @@
1
1
  require File.join(File.dirname(__FILE__),'..','spec_helper')
2
2
 
3
3
  describe "PingJob" do
4
- it_behaves_like "SharedRhoconnectHelper", :rhoconnect_data => true do
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
- scrubbed_params = params.dup
27
- scrubbed_params['vibrate'] = '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
28
20
 
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
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
- 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
26
+ scrubbed_params = params.dup
27
+ scrubbed_params['vibrate'] = '5'
42
28
 
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
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
- 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
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
- 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
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
- 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
- )
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
- 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
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
- it_behaves_like "SharedRhoconnectHelper", :rhoconnect_data => true do
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
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
- 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
29
- end
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
- it_behaves_like "SharedRhoconnectHelper", :rhoconnect_data => false do
5
- before(:each) do
6
- Store.put_value(License::CLIENT_DOCKEY,nil)
7
- end
4
+ include_examples "SharedRhoconnectHelper", :rhoconnect_data => false
8
5
 
9
- it "should decrypt license" do
10
- license = License.new
11
- license.rhoconnect_version.should == 'Version 1'
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
- it "should use generator license file when there is license load error" do
18
- path_to_license = File.join(File.dirname(__FILE__), '..', 'generators', 'templates', 'application', 'settings', 'license.key')
19
- license = IO.read(path_to_license).strip
20
- Rhoconnect.stub!(:get_config).and_return({Rhoconnect.environment.to_sym => {}})
21
- License.new.license.should == license
22
- # lambda { License.new }.should raise_error(LicenseException, "Error verifying license.")
23
- end
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
- it "should verify # of seats before adding" do
26
- License.new.check_and_use_seat
27
- Store.get_value(License::CLIENT_DOCKEY).to_i.should == 1
28
- end
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
- it "should raise exception when seats are exceeded" do
31
- Store.put_value(License::CLIENT_DOCKEY,10)
32
- lambda { License.new.check_and_use_seat }.should raise_error(
33
- LicenseSeatsExceededException, "WARNING: Maximum # of devices exceeded for this license."
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
- it "should free license seat" do
38
- Store.put_value(License::CLIENT_DOCKEY,5)
39
- License.new.free_seat
40
- Store.get_value(License::CLIENT_DOCKEY).to_i.should == 4
41
- end
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
- it "should get # of available seats" do
44
- license = License.new
45
- license.check_and_use_seat
46
- license.available.should == 9
47
- end
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
- it "should use RHOCONNECT_LICENSE env var" do
50
- ENV['RHOCONNECT_LICENSE'] = 'b749cbe6e029400e688360468624388e2cb7f6a1e72c91d4686a1b8c9d37b72c3e1872ec9f369d481220e10759c18e16'
51
- license = License.new
52
- license.licensee.should == 'Rhohub'
53
- license.seats.should == 5
54
- license.issued.should == 'Tue Aug 10 16:14:24 -0700 2010'
55
- ENV.delete('RHOCONNECT_LICENSE')
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