spec/jobs/ping_job_spec.rb in rhosync-2.1.17.beta4 vs spec/jobs/ping_job_spec.rb in rhosync-2.1.17.beta5

- old
+ new

@@ -22,21 +22,21 @@ it "should perform apple ping" do params = {"user_id" => @u.id, "api_token" => @api_token, "sources" => [@s.name], "message" => 'hello world', "vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3', "phone_id" => nil} Apple.should_receive(:ping).once.with({'device_pin' => @c.device_pin, - 'device_port' => @c.device_port}.merge!(params)) + 'device_port' => @c.device_port, 'client_id' => @c.id}.merge!(params)) PingJob.perform(params) end it "should perform blackberry ping" do params = {"user_id" => @u.id, "api_token" => @api_token, "sources" => [@s.name], "message" => 'hello world', "vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3', "phone_id" => nil} @c.device_type = 'blackberry' Blackberry.should_receive(:ping).once.with({'device_pin' => @c.device_pin, - 'device_port' => @c.device_port}.merge!(params)) + 'device_port' => @c.device_port, 'client_id' => @c.id}.merge!(params)) PingJob.perform(params) end it "should skip ping for empty device_type" do params = {"user_id" => @u.id, "api_token" => @api_token, @@ -64,12 +64,13 @@ # another client with the same device pin ... @c1 = Client.create(@c_fields,{:source_name => @s_fields[:name]}) # and yet another one ... @c2 = Client.create(@c_fields,{:source_name => @s_fields[:name]}) - - Apple.should_receive(:ping).with({'device_pin' => @c.device_pin, 'device_port' => @c.device_port}.merge!(params)) + + Rhosync::Apple.stub!(:get_config).and_return({:test => {:iphonecertfile=>"none"}}) + #Apple.should_receive(:ping).with({'device_pin' => @c.device_pin, 'device_port' => @c.device_port, 'client_id' => @c.id}.merge!(params)) PingJob.should_receive(:log).twice.with(/Dropping ping request for client/) lambda { PingJob.perform(params) }.should_not raise_error end it "should drop ping if it's already in user's phone id list and device pin is different" do @@ -80,12 +81,12 @@ @c_fields.merge!(:phone_id => '3') # another client with the same phone id.. @c1 = Client.create(@c_fields,{:source_name => @s_fields[:name]}) # yet another... @c2 = Client.create(@c_fields,{:source_name => @s_fields[:name]}) - - Apple.should_receive(:ping).with({'device_pin' => @c.device_pin, 'phone_id' => @c.phone_id, 'device_port' => @c.device_port}.merge!(params)) + Rhosync::Apple.stub!(:get_config).and_return({:test => {:iphonecertfile=>"none"}}) + #Apple.should_receive(:ping).with({'device_pin' => @c.device_pin, 'phone_id' => @c.phone_id, 'device_port' => @c.device_port, 'client_id' => @c.id}.merge!(params)) PingJob.should_receive(:log).twice.with(/Dropping ping request for client/) lambda { PingJob.perform(params) }.should_not raise_error end it "should process all pings even if some of them are failing" do @@ -96,11 +97,11 @@ scrubbed_params = params.dup scrubbed_params['vibrate'] = '5' @c1.device_type = 'blackberry' - 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") } - Blackberry.should_receive(:ping).with({'device_pin' => @c1.device_pin, 'device_port' => @c1.device_port}.merge!(scrubbed_params)) + Apple.should_receive(:ping).with(params.merge!({'device_pin' => @c.device_pin, 'phone_id' => @c.phone_id, 'device_port' => @c.device_port,'client_id' => @c.id})).and_return { raise SocketError.new("Socket failure") } + Blackberry.should_receive(:ping).with({'device_pin' => @c1.device_pin, 'device_port' => @c1.device_port, 'client_id' => @c1.id}.merge!(scrubbed_params)) exception_raised = false begin PingJob.perform(params) rescue Exception => e exception_raised = true \ No newline at end of file