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

- old
+ new

@@ -2,10 +2,25 @@ describe "PingJob" do it_should_behave_like "SpecBootstrapHelper" it_should_behave_like "SourceAdapterHelper" + before(:each) do + @u1_fields = {:login => 'testuser1'} + @u1 = User.create(@u1_fields) + @u1.password = 'testpass1' + @c1_fields = { + :device_type => 'Apple', + :device_pin => 'abcde', + :device_port => '3333', + :user_id => @u1.id, + :app_id => @a.id + } + @c1 = Client.create(@c1_fields,{:source_name => @s_fields[:name]}) + @a.users << @u1.id + end + 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, @@ -70,8 +85,29 @@ Apple.should_receive(:ping).with({'device_pin' => @c.device_pin, 'phone_id' => @c.phone_id, 'device_port' => @c.device_port}.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 + params = {"user_id" => [ @u.id, @u1.id], "api_token" => @api_token, + "sources" => [@s.name], "message" => 'hello world', + "vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3', 'phone_id' => nil } + @c.phone_id = '3' + + 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)) + exception_raised = false + begin + PingJob.perform(params) + rescue Exception => e + exception_raised = true + end + exception_raised.should == true + end end \ No newline at end of file