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.
@@ -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
@@ -13,7 +13,7 @@ platforms :ruby, :mingw do
13
13
  # for async framework
14
14
  # for Async, Eventful execution
15
15
  gem 'rack-fiber_pool'
16
- gem 'async-rack'
16
+ gem 'async-rack', :git => 'https://github.com/tauplatform/async-rack.git'
17
17
  end
18
18
 
19
19
  platforms :jruby do
@@ -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 confict detected"
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] ||= {}
@@ -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.connect(:url => url, :timeout => Rhoconnect.redis_timeout, :thread_safe => true)
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.connect(
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.connect(:timeout => 30, :thread_safe => true)
904
+ Redis.new(:timeout => 30, :thread_safe => true)
905
905
  end
906
906
  end
907
907
  end
@@ -1,3 +1,3 @@
1
1
  module Rhoconnect
2
- VERSION = '6.0.11'
2
+ VERSION = '6.2.0'
3
3
  end
@@ -39,15 +39,15 @@ Gem::Specification.new do |s|
39
39
  'README.md'
40
40
  ]
41
41
 
42
- s.add_dependency('bundler', '~> 1.0')
43
- s.add_dependency('rack', '~> 1.5.2')
44
- s.add_dependency('sinatra', '~> 1.4')
45
- s.add_dependency('rake', '~> 10.4.0')
46
- s.add_dependency('json', '~> 1.8')
47
- s.add_dependency('rubyzip', '~> 1.1')
48
- s.add_dependency('connection_pool', '~> 1.2.0')
49
- s.add_dependency('redis', '>= 3.0.1')
50
- s.add_dependency('resque', '>= 1.22.0')
51
- s.add_dependency('rest-client', '~> 1.6.1')
52
- s.add_dependency('thor', '~> 0.18.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 confict detected"
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] ||= {}
@@ -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
- it "should resend page if page exists and no token provided" do
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
- {"count"=>1}, {"progress_count"=>0},{"total_count"=>1},{'insert' => expected}]
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
- {"count"=>0}, {"progress_count"=>0}, {"total_count"=>1}, {}]
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
- it "should send metadata with resend page" do
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
- it "should re-send schema-changed if no token sent" do
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'=>@product1}
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 be_true
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 be_true
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 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
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
@@ -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 "PingJob" do
4
- include_examples "SharedRhoconnectHelper", :rhoconnect_data => true
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
- :device_type => 'Apple',
12
- :device_pin => 'abcde',
13
- :device_port => '3333',
14
- :user_id => @u1.id,
15
- :app_id => @a.id
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 "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}
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
- 'device_port' => @c.device_port}.merge!(scrubbed_params))
37
+ 'device_port' => @c.device_port}.merge!(scrubbed_params))
31
38
  PingJob.perform(params)
32
39
  end
33
40
 
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}
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
- 'device_port' => @c.device_port}.merge!(params))
53
+ 'device_port' => @c.device_port}.merge!(params))
40
54
  PingJob.perform(params)
41
55
  end
42
56
 
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}
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 "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'}
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 { PingJob.perform(params) }.should_not raise_error
85
+ lambda {PingJob.perform(params)}.should_not raise_error
59
86
  end
60
87
 
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'}
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 { PingJob.perform(params) }.should_not raise_error
101
+ lambda {PingJob.perform(params)}.should_not raise_error
69
102
  end
70
103
 
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}
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 { PingJob.perform(params) }.should_not raise_error
124
+ lambda {PingJob.perform(params)}.should_not raise_error
85
125
  end
86
126
 
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'}
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 { PingJob.perform(params) }.should_not raise_error
148
+ lambda {PingJob.perform(params)}.should_not raise_error
103
149
  end
104
150
 
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 }
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 "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'}
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 { PingJob.perform(params) }.should_not raise_error
188
+ lambda {PingJob.perform(params)}.should_not raise_error
130
189
  end
131
190
 
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'}
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 { PingJob.perform(params) }.should_not raise_error
206
+ lambda {PingJob.perform(params)}.should_not raise_error
141
207
  end
142
208
 
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 }
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
- 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))
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 "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 }
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 "should process ping for device_push_type if available" do
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
- 'user_id' => @u.id,
177
- 'message' => 'hello world',
178
- 'device_port' => '',
179
- 'vibrate' => '',
180
- 'phone_id' => nil
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
- {'device_pin' => @c.device_pin}.merge!(scrubbed_params)
268
+ {'device_pin' => @c.device_pin}.merge!(scrubbed_params)
186
269
  )
187
270
  PingJob.perform(params)
188
271
  end
189
- end
272
+ end