rhoconnect 6.0.11 → 6.2.0
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 +4 -4
- data/Gemfile +14 -11
- data/Gemfile.lock +120 -87
- data/Rakefile +4 -3
- data/bin/rhoconnect +0 -0
- data/bin/rhoconnect-benchmark +0 -0
- data/commands/dtach/dtach_install.rb +29 -24
- data/commands/rhoconnect/start.rb +5 -4
- data/generators/templates/application/rcgemfile +1 -1
- data/lib/rhoconnect/model/helpers/find_duplicates_on_update.rb +1 -1
- data/lib/rhoconnect/store.rb +3 -3
- data/lib/rhoconnect/version.rb +1 -1
- data/rhoconnect.gemspec +11 -11
- data/spec/api/client/get_client_params_spec.rb +4 -0
- data/spec/apps/rhotestapp/models/ruby/sample_adapter.rb +1 -1
- data/spec/client_sync_spec.rb +7 -7
- data/spec/dynamic_adapter_spec.rb +13 -13
- data/spec/generator/generator_spec.rb +7 -7
- data/spec/jobs/ping_job_spec.rb +162 -79
- data/spec/perf/perf_spec_helper.rb +5 -5
- data/spec/ping/apple_spec.rb +24 -26
- data/spec/ping/gcm_spec.rb +26 -28
- data/spec/ping/rhoconnect_push_spec.rb +13 -13
- data/spec/rhoconnect_spec.rb +2 -2
- data/spec/server/cors_spec.rb +22 -22
- data/spec/server/server_spec.rb +308 -310
- data/spec/server/stats_spec.rb +7 -7
- data/spec/server/x_domain_session_wrapper_spec.rb +40 -40
- data/spec/source_adapter_spec.rb +2 -2
- data/spec/source_sync_spec.rb +4 -4
- data/spec/spec_helper.rb +8 -8
- data/spec/stats/record_spec.rb +7 -7
- data/spec/store_orm_spec.rb +97 -94
- data/spec/store_spec.rb +23 -23
- data/spec/user_spec.rb +3 -3
- metadata +32 -26
@@ -19,6 +19,7 @@ Execute.define_task do
|
|
19
19
|
settings = config(options[:config])
|
20
20
|
|
21
21
|
port = (params[:port]) ? params[:port] : URI.parse(settings[:syncserver]).port
|
22
|
+
host = (params[:host]) ? params[:host] : URI.parse(settings[:syncserver]).host
|
22
23
|
|
23
24
|
redis_url = (params[:redis]) ? params[:redis] : settings[:redis]
|
24
25
|
redis_url = [redis_url] if redis_url.is_a?(String)
|
@@ -63,17 +64,17 @@ Execute.define_task do
|
|
63
64
|
|
64
65
|
if jruby?
|
65
66
|
puts 'Starting rhoconnect in jruby environment...'
|
66
|
-
system(env, "#{command} --port #{port} -P #{rhoconnect_pid} #{rackup_config}")
|
67
|
+
system(env, "#{command} --host #{host} --port #{port} -P #{rhoconnect_pid} #{rackup_config}")
|
67
68
|
elsif windows?
|
68
69
|
puts 'Starting rhoconnect...'
|
69
|
-
system(env, "#{command} --port #{port} -P #{rhoconnect_pid} #{rackup_config}")
|
70
|
+
system(env, "#{command} --host #{host} --port #{port} -P #{rhoconnect_pid} #{rackup_config}")
|
70
71
|
else
|
71
72
|
if dtach_installed?
|
72
73
|
puts 'Detach with Ctrl+\ Re-attach with rhoconnect attach'
|
73
74
|
sleep 2
|
74
|
-
system(env, "dtach -A #{rhoconnect_socket} #{command} --port #{port} -P #{rhoconnect_pid} #{rackup_config}")
|
75
|
+
system(env, "dtach -A #{rhoconnect_socket} #{command} --host #{host} --port #{port} -P #{rhoconnect_pid} #{rackup_config}")
|
75
76
|
else
|
76
|
-
system(env, "#{command} --port #{port} -P #{rhoconnect_pid} #{rackup_config}")
|
77
|
+
system(env, "#{command} --host #{host} --port #{port} -P #{rhoconnect_pid} #{rackup_config}")
|
77
78
|
end
|
78
79
|
end
|
79
80
|
end
|
@@ -37,7 +37,7 @@ module Rhoconnect
|
|
37
37
|
invalid_meta[index] ||= {}
|
38
38
|
invalid_meta[index][source_id] ||= {}
|
39
39
|
invalid_meta[index][source_id][objindex] ||= {}
|
40
|
-
invalid_meta[index][source_id][objindex][:error] = "Error during #{operation}: object
|
40
|
+
invalid_meta[index][source_id][objindex][:error] = "Error during #{operation}: object conflict detected"
|
41
41
|
else
|
42
42
|
invalid_meta[index] ||= {}
|
43
43
|
invalid_meta[index][source_id] ||= {}
|
data/lib/rhoconnect/store.rb
CHANGED
@@ -879,7 +879,7 @@ module Rhoconnect
|
|
879
879
|
Rhoconnect.redis_url = url
|
880
880
|
ConnectionPool::Wrapper.new(:size => Rhoconnect.connection_pool_size,
|
881
881
|
:timeout => Rhoconnect.connection_pool_timeout) do
|
882
|
-
Redis.
|
882
|
+
Redis.new(:url => url, :timeout => Rhoconnect.redis_timeout, :thread_safe => true)
|
883
883
|
end
|
884
884
|
elsif server and server.is_a?(String)
|
885
885
|
Rhoconnect.redis_url = "redis://#{server}"
|
@@ -887,7 +887,7 @@ module Rhoconnect
|
|
887
887
|
ConnectionPool::Wrapper.new(:size => Rhoconnect.connection_pool_size,
|
888
888
|
:timeout => Rhoconnect.connection_pool_timeout) do
|
889
889
|
host = '127.0.0.1' if host == 'localhost'
|
890
|
-
Redis.
|
890
|
+
Redis.new(
|
891
891
|
:thread_safe => true,
|
892
892
|
:host => host,
|
893
893
|
:port => port,
|
@@ -901,7 +901,7 @@ module Rhoconnect
|
|
901
901
|
else
|
902
902
|
Rhoconnect.redis_url = "redis://localhost:6379"
|
903
903
|
ConnectionPool::Wrapper.new(:size => 5, :timeout => 30) do
|
904
|
-
Redis.
|
904
|
+
Redis.new(:timeout => 30, :thread_safe => true)
|
905
905
|
end
|
906
906
|
end
|
907
907
|
end
|
data/lib/rhoconnect/version.rb
CHANGED
data/rhoconnect.gemspec
CHANGED
@@ -39,15 +39,15 @@ Gem::Specification.new do |s|
|
|
39
39
|
'README.md'
|
40
40
|
]
|
41
41
|
|
42
|
-
s.add_dependency('bundler', '~> 1.
|
43
|
-
s.add_dependency('rack', '~>
|
44
|
-
s.add_dependency('sinatra', '~>
|
45
|
-
s.add_dependency('rake', '~>
|
46
|
-
s.add_dependency('json', '
|
47
|
-
s.add_dependency('rubyzip', '~> 1.
|
48
|
-
s.add_dependency('connection_pool', '~>
|
49
|
-
s.add_dependency('redis', '
|
50
|
-
s.add_dependency('resque', '>=
|
51
|
-
s.add_dependency('rest-client', '~>
|
52
|
-
s.add_dependency('thor', '~> 0.
|
42
|
+
s.add_dependency('bundler', '~> 1.17.3')
|
43
|
+
s.add_dependency('rack', '~> 2.0.6')
|
44
|
+
s.add_dependency('sinatra', '~> 2.0.5')
|
45
|
+
s.add_dependency('rake', '~> 12.3.2')
|
46
|
+
s.add_dependency('json', '>= 1.8', '< 2.0')
|
47
|
+
s.add_dependency('rubyzip', '~> 1.2.2')
|
48
|
+
s.add_dependency('connection_pool', '~> 2.2.2')
|
49
|
+
s.add_dependency('redis', '~> 4.1.0')
|
50
|
+
s.add_dependency('resque', '>= 2.0.0')
|
51
|
+
s.add_dependency('rest-client', '~> 2.0.2')
|
52
|
+
s.add_dependency('thor', '~> 0.20.3')
|
53
53
|
end
|
@@ -12,6 +12,8 @@ describe "RhoconnectApiGetClientParams" do
|
|
12
12
|
{"name"=>"device_pin", "value"=>"abcd", "type"=>"string"},
|
13
13
|
{"name"=>"device_port", "value"=>"3333", "type"=>"string"},
|
14
14
|
{"name"=>"device_push_type", "type"=>"string", "value"=>nil},
|
15
|
+
{"name"=>"device_app_id", "type"=>"string", "value"=>nil},
|
16
|
+
{"name"=>"device_app_version", "type"=>"string", "value"=>nil},
|
15
17
|
{"name"=>"user_id", "value"=>"testuser", "type"=>"string"},
|
16
18
|
{"name"=>"phone_id", "value"=>nil, "type"=>"string"},
|
17
19
|
{"name"=>"app_id", "value"=>"application", "type"=>"string"}].sort{|x,y| x['name']<=>y['name']}
|
@@ -26,6 +28,8 @@ describe "RhoconnectApiGetClientParams" do
|
|
26
28
|
{"name"=>"device_pin", "value"=>"abcd", "type"=>"string"},
|
27
29
|
{"name"=>"device_port", "value"=>"3333", "type"=>"string"},
|
28
30
|
{"name"=>"device_push_type", "type"=>"string", "value"=>nil},
|
31
|
+
{"name"=>"device_app_id", "type"=>"string", "value"=>nil},
|
32
|
+
{"name"=>"device_app_version", "type"=>"string", "value"=>nil},
|
29
33
|
{"name"=>"user_id", "value"=>"testuser", "type"=>"string"},
|
30
34
|
{"name"=>"phone_id", "value"=>nil, "type"=>"string"},
|
31
35
|
{"name"=>"app_id", "value"=>"application", "type"=>"string"}].sort{|x,y| x['name']<=>y['name']}
|
@@ -40,7 +40,7 @@ class SampleAdapter < SourceAdapter
|
|
40
40
|
invalid_meta[index] ||= {}
|
41
41
|
invalid_meta[index][source_id] ||= {}
|
42
42
|
invalid_meta[index][source_id][objindex] ||= {}
|
43
|
-
invalid_meta[index][source_id][objindex][:error] = "Error during #{operation}: object
|
43
|
+
invalid_meta[index][source_id][objindex][:error] = "Error during #{operation}: object conflict detected"
|
44
44
|
end
|
45
45
|
if objvalue['duplicate_of_cid']
|
46
46
|
invalid_meta[index] ||= {}
|
data/spec/client_sync_spec.rb
CHANGED
@@ -12,7 +12,7 @@ describe "ClientSync" do
|
|
12
12
|
@model = Rhoconnect::Model::Base.create(@s2)
|
13
13
|
@cs1 = Rhoconnect::Handler::Changes::Runner.new(['create'],@model,@c,lv,params)
|
14
14
|
stub_request(:post, "http://test.com/rhoconnect/authenticate")
|
15
|
-
stub_request(:post, "http://test.com/rhoconnect/create").with(:headers => {'Content-Type' => 'application/json'}).to_return(:body => {:id => 5})
|
15
|
+
stub_request(:post, "http://test.com/rhoconnect/create").with(:headers => {'Content-Type' => 'application/json'}).to_return(:body => {:id => 5}.to_json)
|
16
16
|
@cs1.run
|
17
17
|
verify_source_queue_data(@s2, {:create => [],
|
18
18
|
:update => [],
|
@@ -484,7 +484,7 @@ describe "ClientSync" do
|
|
484
484
|
@sync_handler.client.get_data(:cd).should == @data
|
485
485
|
end
|
486
486
|
|
487
|
-
|
487
|
+
xit "should resend page if page exists and no token provided" do
|
488
488
|
expected = {'1'=>@product1}
|
489
489
|
set_test_data('test_db_storage',{'1'=>@product1,'2'=>@product2,'4'=>@product4})
|
490
490
|
params = {'name' => 'iPhone'}
|
@@ -492,10 +492,10 @@ describe "ClientSync" do
|
|
492
492
|
@sync_handler.run
|
493
493
|
token = @c.get_value(:page_token)
|
494
494
|
@sync_handler.run.should == [{'version'=>Rhoconnect::SYNC_VERSION},{"token"=>token},
|
495
|
-
|
495
|
+
{"count"=>1}, {"progress_count"=>0},{"total_count"=>1},{'insert' => expected}]
|
496
496
|
@sync_handler.params[:token] = token
|
497
497
|
@sync_handler.run.should == [{'version'=>Rhoconnect::SYNC_VERSION},{"token"=>""},
|
498
|
-
|
498
|
+
{"count"=>0}, {"progress_count"=>0}, {"total_count"=>1}, {}]
|
499
499
|
@sync_handler.client.get_data(:page).should == {}
|
500
500
|
@c.get_value(:page_token).should be_nil
|
501
501
|
end
|
@@ -514,7 +514,7 @@ describe "ClientSync" do
|
|
514
514
|
end
|
515
515
|
end
|
516
516
|
|
517
|
-
|
517
|
+
xit "should send metadata with resend page" do
|
518
518
|
expected = {'1'=>@product1}
|
519
519
|
set_state('test_db_storage' => expected)
|
520
520
|
mock_metadata_method([SampleAdapter]) do
|
@@ -563,7 +563,7 @@ describe "ClientSync" do
|
|
563
563
|
end
|
564
564
|
end
|
565
565
|
|
566
|
-
|
566
|
+
xit "should re-send schema-changed if no token sent" do
|
567
567
|
mock_schema_method([SampleAdapter]) do
|
568
568
|
@c.put_value(:schema_sha1,'foo')
|
569
569
|
result = @sync_handler.run
|
@@ -629,4 +629,4 @@ describe "ClientSync" do
|
|
629
629
|
{"#{operation}-error"=>{"#{ERROR}-error"=>{"message"=>msg},ERROR=>op_data[operation][ERROR]}}]
|
630
630
|
end
|
631
631
|
end
|
632
|
-
end
|
632
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__),'spec_helper')
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
2
|
|
3
3
|
describe "Rhoconnect::Model::DynamicAdapterModel" do
|
4
4
|
include_examples "SharedRhoconnectHelper", :rhoconnect_data => true
|
@@ -6,33 +6,33 @@ describe "Rhoconnect::Model::DynamicAdapterModel" do
|
|
6
6
|
it "should return login when backend service defined" do
|
7
7
|
stub_request(:post, "http://test.com/rhoconnect/authenticate").to_return(:body => "lucas")
|
8
8
|
Rhoconnect.appserver = 'http://test.com'
|
9
|
-
Rhoconnect::Model::DynamicAdapterModel.authenticate('lucas','').should == 'lucas'
|
9
|
+
Rhoconnect::Model::DynamicAdapterModel.authenticate('lucas', '').should == 'lucas'
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should query dynamic adapter service" do
|
13
|
-
data = {'1'
|
13
|
+
data = {'1' => @product1}
|
14
14
|
stub_request(:post, "http://test.com/rhoconnect/query").with(:headers => {'Content-Type' => 'application/json'}).to_return(:status => 200, :body => data.to_json)
|
15
|
-
da = Rhoconnect::Model::DynamicAdapterModel.new(@s2,nil,'http://test.com')
|
15
|
+
da = Rhoconnect::Model::DynamicAdapterModel.new(@s2, nil, 'http://test.com')
|
16
16
|
da.query.should == data
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should create new object using dynamic adapter" do
|
20
|
-
stub_request(:post, "http://test.com/rhoconnect/create").with(:headers => {'Content-Type' => 'application/json'}).to_return(:body => {:id => 5})
|
21
|
-
da = Rhoconnect::Model::DynamicAdapterModel.new(@s2,nil,'http://test.com')
|
22
|
-
da.create(@product1).should == {:id => 5}
|
20
|
+
stub_request(:post, "http://test.com/rhoconnect/create").with(:headers => {'Content-Type' => 'application/json'}).to_return(:body => {:id => 5}.to_json)
|
21
|
+
da = Rhoconnect::Model::DynamicAdapterModel.new(@s2, nil, 'http://test.com')
|
22
|
+
da.create(@product1).should == {:id => 5}.to_json
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should update object using dynamic adapter" do
|
26
26
|
data = {'id' => 2}
|
27
|
-
stub_request(:post, "http://test.com/rhoconnect/update").with(:headers => {'Content-Type' => 'application/json'}).to_return(:body => {:id => 5})
|
28
|
-
da = Rhoconnect::Model::DynamicAdapterModel.new(@s2,nil,'http://test.com')
|
29
|
-
da.update(data).should == {:id => 5}
|
27
|
+
stub_request(:post, "http://test.com/rhoconnect/update").with(:headers => {'Content-Type' => 'application/json'}).to_return(:body => {:id => 5}.to_json)
|
28
|
+
da = Rhoconnect::Model::DynamicAdapterModel.new(@s2, nil, 'http://test.com')
|
29
|
+
da.update(data).should == {:id => 5}.to_json
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should delete object using dynamic adapter" do
|
33
33
|
data = {'id' => 2}
|
34
|
-
stub_request(:post, "http://test.com/rhoconnect/delete").with(:headers => {'Content-Type' => 'application/json'}).to_return(:body => {:id => 5})
|
35
|
-
da = Rhoconnect::Model::DynamicAdapterModel.new(@s2,nil,'http://test.com')
|
36
|
-
da.delete(data).should == {:id => 5}
|
34
|
+
stub_request(:post, "http://test.com/rhoconnect/delete").with(:headers => {'Content-Type' => 'application/json'}).to_return(:body => {:id => 5}.to_json)
|
35
|
+
da = Rhoconnect::Model::DynamicAdapterModel.new(@s2, nil, 'http://test.com')
|
36
|
+
da.delete(data).should == {:id => 5}.to_json
|
37
37
|
end
|
38
38
|
end
|
@@ -37,7 +37,7 @@ describe "Generator" do
|
|
37
37
|
'settings/settings.yml',
|
38
38
|
'spec/spec_helper.rb'
|
39
39
|
].each do |template|
|
40
|
-
File.exist?("/tmp/#{appname}/#{template}").should
|
40
|
+
File.exist?("/tmp/#{appname}/#{template}").should be true
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
@@ -61,7 +61,7 @@ describe "Generator" do
|
|
61
61
|
'public',
|
62
62
|
'settings/settings.yml'
|
63
63
|
].each do |template|
|
64
|
-
File.exist?("/tmp/#{appname}/#{template}").should
|
64
|
+
File.exist?("/tmp/#{appname}/#{template}").should be true
|
65
65
|
end
|
66
66
|
end
|
67
67
|
end
|
@@ -85,14 +85,14 @@ describe "Generator" do
|
|
85
85
|
Dir.chdir appname do
|
86
86
|
Rhoconnect::SourceGenerator.start([source])
|
87
87
|
|
88
|
-
File.exist?("/tmp/#{appname}/models/ruby/#{source}.rb").should
|
89
|
-
File.exist?("/tmp/#{appname}/controllers/ruby/#{source}_controller.rb").should
|
90
|
-
File.exist?("/tmp/#{appname}/spec/models/ruby/#{source}_spec.rb").should
|
91
|
-
File.exist?("/tmp/#{appname}/spec/controllers/ruby/#{source}_controller_spec.rb").should
|
88
|
+
File.exist?("/tmp/#{appname}/models/ruby/#{source}.rb").should be true
|
89
|
+
File.exist?("/tmp/#{appname}/controllers/ruby/#{source}_controller.rb").should be true
|
90
|
+
File.exist?("/tmp/#{appname}/spec/models/ruby/#{source}_spec.rb").should be true
|
91
|
+
File.exist?("/tmp/#{appname}/spec/controllers/ruby/#{source}_controller_spec.rb").should be true
|
92
92
|
end
|
93
93
|
end
|
94
94
|
end
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
|
-
end
|
98
|
+
end
|
data/spec/jobs/ping_job_spec.rb
CHANGED
@@ -1,111 +1,164 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__),'..','spec_helper')
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
2
|
|
3
|
-
describe
|
4
|
-
include_examples
|
3
|
+
describe 'PingJob' do
|
4
|
+
include_examples 'SharedRhoconnectHelper', :rhoconnect_data => true
|
5
5
|
|
6
6
|
before(:each) do
|
7
7
|
@u1_fields = {:login => 'testuser1'}
|
8
8
|
@u1 = User.create(@u1_fields)
|
9
9
|
@u1.password = 'testpass1'
|
10
10
|
@c1_fields = {
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
:device_type => 'Apple',
|
12
|
+
:device_pin => 'abcde',
|
13
|
+
:device_port => '3333',
|
14
|
+
:user_id => @u1.id,
|
15
|
+
:app_id => @a.id
|
16
16
|
}
|
17
|
-
@c1 = Client.create(@c1_fields,{:source_name => @s_fields[:name]})
|
17
|
+
@c1 = Client.create(@c1_fields, {:source_name => @s_fields[:name]})
|
18
18
|
@a.users << @u1.id
|
19
19
|
end
|
20
20
|
|
21
|
-
it
|
22
|
-
params = {
|
23
|
-
|
24
|
-
|
21
|
+
it 'should perform apple ping with integer parameters' do
|
22
|
+
params = {'user_id' => @u.id,
|
23
|
+
'api_token' => @api_token,
|
24
|
+
'sources' => [@s.name],
|
25
|
+
'message' => 'hello world',
|
26
|
+
'vibrate' => 5,
|
27
|
+
'badge' => '5',
|
28
|
+
'sound' => 'hello.mp3',
|
29
|
+
'phone_id' => nil,
|
30
|
+
'device_app_id' => nil,
|
31
|
+
'device_app_version' => nil, }
|
25
32
|
|
26
33
|
scrubbed_params = params.dup
|
27
34
|
scrubbed_params['vibrate'] = '5'
|
28
35
|
|
29
36
|
Apple.should_receive(:ping).once.with({'device_pin' => @c.device_pin,
|
30
|
-
|
37
|
+
'device_port' => @c.device_port}.merge!(scrubbed_params))
|
31
38
|
PingJob.perform(params)
|
32
39
|
end
|
33
40
|
|
34
|
-
it
|
35
|
-
params = {
|
36
|
-
|
37
|
-
|
41
|
+
it 'should perform apple ping' do
|
42
|
+
params = {'user_id' => @u.id,
|
43
|
+
'api_token' => @api_token,
|
44
|
+
'sources' => [@s.name],
|
45
|
+
'message' => 'hello world',
|
46
|
+
'vibrate' => '5',
|
47
|
+
'badge' => '5',
|
48
|
+
'sound' => 'hello.mp3',
|
49
|
+
'phone_id' => nil,
|
50
|
+
'device_app_id' => nil,
|
51
|
+
'device_app_version' => nil}
|
38
52
|
Apple.should_receive(:ping).once.with({'device_pin' => @c.device_pin,
|
39
|
-
|
53
|
+
'device_port' => @c.device_port}.merge!(params))
|
40
54
|
PingJob.perform(params)
|
41
55
|
end
|
42
56
|
|
43
|
-
it
|
44
|
-
params = {
|
45
|
-
|
46
|
-
|
57
|
+
it 'should skip ping for the unknown platform' do
|
58
|
+
params = {'user_id' => @u.id,
|
59
|
+
'api_token' => @api_token,
|
60
|
+
'sources' => [@s.name],
|
61
|
+
'message' => 'hello world',
|
62
|
+
'vibrate' => '5',
|
63
|
+
'badge' => '5',
|
64
|
+
'sound' => 'hello.mp3',
|
65
|
+
'phone_id' => nil,
|
66
|
+
'device_app_id' => nil,
|
67
|
+
'device_app_version' => nil}
|
47
68
|
@c.device_type = 'unknown_device_type'
|
48
69
|
PingJob.should_receive(:log).once.with("Dropping ping request for unsupported platform '#{@c.device_type}'")
|
49
70
|
PingJob.perform(params)
|
50
71
|
end
|
51
72
|
|
52
|
-
it
|
53
|
-
params = {
|
54
|
-
|
55
|
-
|
73
|
+
it 'should skip ping for empty device_type' do
|
74
|
+
params = {'user_id' => @u.id,
|
75
|
+
'api_token' => @api_token,
|
76
|
+
'sources' => [@s.name],
|
77
|
+
'message' => 'hello world',
|
78
|
+
'vibrate' => '5',
|
79
|
+
'badge' => '5',
|
80
|
+
'sound' => 'hello.mp3',
|
81
|
+
'device_app_id' => nil,
|
82
|
+
'device_app_version' => nil}
|
56
83
|
@c.device_type = nil
|
57
84
|
PingJob.should_receive(:log).once.with("Skipping ping for non-registered client_id '#{@c.id}'...")
|
58
|
-
lambda {
|
85
|
+
lambda {PingJob.perform(params)}.should_not raise_error
|
59
86
|
end
|
60
87
|
|
61
|
-
it
|
62
|
-
params = {
|
63
|
-
|
64
|
-
|
88
|
+
it 'should skip ping for empty device_pin' do
|
89
|
+
params = {'user_id' => @u.id,
|
90
|
+
'api_token' => @api_token,
|
91
|
+
'sources' => [@s.name],
|
92
|
+
'message' => 'hello world',
|
93
|
+
'vibrate' => '5',
|
94
|
+
'badge' => '5',
|
95
|
+
'sound' => 'hello.mp3',
|
96
|
+
'device_app_id' => nil,
|
97
|
+
'device_app_version' => nil, }
|
65
98
|
@c.device_type = 'Android'
|
66
99
|
@c.device_pin = nil
|
67
100
|
PingJob.should_receive(:log).once.with("Skipping ping for non-registered client_id '#{@c.id}'...")
|
68
|
-
lambda {
|
101
|
+
lambda {PingJob.perform(params)}.should_not raise_error
|
69
102
|
end
|
70
103
|
|
71
|
-
it
|
72
|
-
params = {
|
73
|
-
|
74
|
-
|
104
|
+
it 'should drop ping if it\'s already in user\'s device pin list' do
|
105
|
+
params = {'user_id' => @u.id,
|
106
|
+
'api_token' => @api_token,
|
107
|
+
'sources' => [@s.name],
|
108
|
+
'message' => 'hello world',
|
109
|
+
'vibrate' => '5',
|
110
|
+
'badge' => '5',
|
111
|
+
'sound' => 'hello.mp3',
|
112
|
+
'phone_id' => nil,
|
113
|
+
'device_app_id' => nil,
|
114
|
+
'device_app_version' => nil}
|
75
115
|
# another client with the same device pin ...
|
76
116
|
@c_fields.delete(:id)
|
77
|
-
@c1 = Client.create(@c_fields,{:source_name => @s_fields[:name]})
|
117
|
+
@c1 = Client.create(@c_fields, {:source_name => @s_fields[:name]})
|
78
118
|
# and yet another one ...
|
79
119
|
@c_fields.delete(:id)
|
80
|
-
@c2 = Client.create(@c_fields,{:source_name => @s_fields[:name]})
|
120
|
+
@c2 = Client.create(@c_fields, {:source_name => @s_fields[:name]})
|
81
121
|
|
82
122
|
Apple.should_receive(:ping).with({'device_pin' => @c.device_pin, 'device_port' => @c.device_port}.merge!(params))
|
83
123
|
PingJob.should_receive(:log).twice.with(/Dropping ping request for client/)
|
84
|
-
lambda {
|
124
|
+
lambda {PingJob.perform(params)}.should_not raise_error
|
85
125
|
end
|
86
126
|
|
87
|
-
it
|
88
|
-
params = {
|
89
|
-
|
90
|
-
|
127
|
+
it 'should drop ping if it\'s already in user\'s phone id list and device pin is different' do
|
128
|
+
params = {'user_id' => @u.id,
|
129
|
+
'api_token' => @api_token,
|
130
|
+
'sources' => [@s.name],
|
131
|
+
'message' => 'hello world',
|
132
|
+
'vibrate' => '5',
|
133
|
+
'badge' => '5',
|
134
|
+
'sound' => 'hello.mp3',
|
135
|
+
'device_app_id' => nil,
|
136
|
+
'device_app_version' => nil, }
|
91
137
|
@c.phone_id = '3'
|
92
138
|
@c_fields.merge!(:phone_id => '3')
|
93
139
|
# another client with the same phone id..
|
94
140
|
@c_fields.delete(:id)
|
95
|
-
@c1 = Client.create(@c_fields,{:source_name => @s_fields[:name]})
|
141
|
+
@c1 = Client.create(@c_fields, {:source_name => @s_fields[:name]})
|
96
142
|
# yet another...
|
97
143
|
@c_fields.delete(:id)
|
98
|
-
@c2 = Client.create(@c_fields,{:source_name => @s_fields[:name]})
|
144
|
+
@c2 = Client.create(@c_fields, {:source_name => @s_fields[:name]})
|
99
145
|
|
100
146
|
Apple.should_receive(:ping).with({'device_pin' => @c.device_pin, 'phone_id' => @c.phone_id, 'device_port' => @c.device_port}.merge!(params))
|
101
147
|
PingJob.should_receive(:log).twice.with(/Dropping ping request for client/)
|
102
|
-
lambda {
|
148
|
+
lambda {PingJob.perform(params)}.should_not raise_error
|
103
149
|
end
|
104
150
|
|
105
|
-
it
|
106
|
-
params = {
|
107
|
-
|
108
|
-
|
151
|
+
it 'should ping two different users from two different devices - Apple and GCM' do
|
152
|
+
params = {'user_id' => [@u.id, @u1.id],
|
153
|
+
'api_token' => @api_token,
|
154
|
+
'sources' => [@s.name],
|
155
|
+
'message' => 'hello world',
|
156
|
+
'vibrate' => '5',
|
157
|
+
'badge' => '5',
|
158
|
+
'sound' => 'hello.mp3',
|
159
|
+
'phone_id' => nil,
|
160
|
+
'device_app_id' => nil,
|
161
|
+
'device_app_version' => nil, }
|
109
162
|
@c.phone_id = '3'
|
110
163
|
|
111
164
|
scrubbed_params = params.dup
|
@@ -117,41 +170,62 @@ describe "PingJob" do
|
|
117
170
|
PingJob.perform(params)
|
118
171
|
end
|
119
172
|
|
120
|
-
it
|
121
|
-
params = {
|
122
|
-
|
123
|
-
|
173
|
+
it 'should drop ping with two different users from the same device' do
|
174
|
+
params = {'user_id' => [@u.id, @u1.id],
|
175
|
+
'api_token' => @api_token,
|
176
|
+
'sources' => [@s.name],
|
177
|
+
'message' => 'hello world',
|
178
|
+
'vibrate' => '5',
|
179
|
+
'badge' => '5',
|
180
|
+
'sound' => 'hello.mp3',
|
181
|
+
'device_app_id' => nil,
|
182
|
+
'device_app_version' => nil, }
|
124
183
|
@c.phone_id = '3'
|
125
184
|
@c1.phone_id = '3'
|
126
185
|
|
127
186
|
Apple.should_receive(:ping).with({'device_pin' => @c.device_pin, 'phone_id' => @c.phone_id, 'device_port' => @c.device_port}.merge!(params))
|
128
187
|
PingJob.should_receive(:log).once.with(/Dropping ping request for client/)
|
129
|
-
lambda {
|
188
|
+
lambda {PingJob.perform(params)}.should_not raise_error
|
130
189
|
end
|
131
190
|
|
132
|
-
it
|
133
|
-
params = {
|
134
|
-
|
135
|
-
|
191
|
+
it 'should drop ping with two different users with the same pin' do
|
192
|
+
params = {'user_id' => [@u.id, @u1.id],
|
193
|
+
'api_token' => @api_token,
|
194
|
+
'sources' => [@s.name],
|
195
|
+
'message' => 'hello world',
|
196
|
+
'phone_id' => nil,
|
197
|
+
'vibrate' => '5',
|
198
|
+
'badge' => '5',
|
199
|
+
'sound' => 'hello.mp3',
|
200
|
+
'device_app_id' => nil,
|
201
|
+
'device_app_version' => nil, }
|
136
202
|
@c1.device_pin = @c.device_pin
|
137
203
|
|
138
204
|
Apple.should_receive(:ping).with({'device_pin' => @c.device_pin, 'device_port' => @c.device_port}.merge!(params))
|
139
205
|
PingJob.should_receive(:log).once.with(/Dropping ping request for client/)
|
140
|
-
lambda {
|
206
|
+
lambda {PingJob.perform(params)}.should_not raise_error
|
141
207
|
end
|
142
208
|
|
143
|
-
it
|
144
|
-
params = {
|
145
|
-
|
146
|
-
|
209
|
+
it 'should process all pings even if some of them are failing' do
|
210
|
+
params = {'user_id' => [@u.id, @u1.id],
|
211
|
+
'api_token' => @api_token,
|
212
|
+
'sources' => [@s.name],
|
213
|
+
'message' => 'hello world',
|
214
|
+
'vibrate' => '5',
|
215
|
+
'badge' => '5',
|
216
|
+
'sound' => 'hello.mp3',
|
217
|
+
'phone_id' => nil,
|
218
|
+
'device_app_id' => nil,
|
219
|
+
'device_app_version' => nil, }
|
147
220
|
@c.phone_id = '3'
|
148
221
|
|
149
222
|
scrubbed_params = params.dup
|
150
223
|
scrubbed_params['vibrate'] = '5'
|
151
224
|
@c1.device_push_type = 'Gcm'
|
152
225
|
|
153
|
-
|
154
|
-
|
226
|
+
params.merge!({'device_pin' => @c.device_pin, 'phone_id' => @c.phone_id, 'device_port' => @c.device_port})
|
227
|
+
allow(Apple).to receive(:ping).with(params).and_raise(SocketError.new("Socket failure"))
|
228
|
+
allow(Gcm).to receive(:ping).with({'device_pin' => @c1.device_pin, 'device_port' => @c1.device_port}.merge!(scrubbed_params))
|
155
229
|
exception_raised = false
|
156
230
|
begin
|
157
231
|
PingJob.perform(params)
|
@@ -161,29 +235,38 @@ describe "PingJob" do
|
|
161
235
|
exception_raised.should == true
|
162
236
|
end
|
163
237
|
|
164
|
-
it
|
165
|
-
params = {
|
166
|
-
|
167
|
-
|
238
|
+
it 'should skip ping for unknown user or user with no clients' do
|
239
|
+
params = {'user_id' => ['fake_user'],
|
240
|
+
'api_token' => @api_token,
|
241
|
+
'sources' => [@s.name],
|
242
|
+
'message' => 'hello world',
|
243
|
+
'vibrate' => '5',
|
244
|
+
'badge' => '5',
|
245
|
+
'sound' => 'hello.mp3',
|
246
|
+
'phone_id' => nil,
|
247
|
+
'device_app_id' => nil,
|
248
|
+
'device_app_version' => nil, }
|
168
249
|
PingJob.should_receive(:log).once.with(/Skipping ping for unknown user 'fake_user' or 'fake_user' has no registered clients.../)
|
169
250
|
PingJob.perform(params)
|
170
251
|
end
|
171
252
|
|
172
|
-
it
|
253
|
+
it 'should process ping for device_push_type if available' do
|
173
254
|
@c.device_push_type = 'rhoconnect_push'
|
174
255
|
@c.device_port = nil
|
175
256
|
params = {
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
257
|
+
'user_id' => @u.id,
|
258
|
+
'message' => 'hello world',
|
259
|
+
'device_port' => '',
|
260
|
+
'vibrate' => '',
|
261
|
+
'phone_id' => nil,
|
262
|
+
'device_app_id' => nil,
|
263
|
+
'device_app_version' => nil,
|
181
264
|
}
|
182
265
|
scrubbed_params = params.dup
|
183
266
|
|
184
267
|
RhoconnectPush.should_receive(:ping).once.with(
|
185
|
-
|
268
|
+
{'device_pin' => @c.device_pin}.merge!(scrubbed_params)
|
186
269
|
)
|
187
270
|
PingJob.perform(params)
|
188
271
|
end
|
189
|
-
end
|
272
|
+
end
|