require File.join(File.dirname(__FILE__),'..','spec_helper') describe "Ping Blackberry" do it_behaves_like "SharedRhoconnectHelper", :rhoconnect_data => false do before do @params = {"user_id" => @u.id, "api_token" => @api_token, "sources" => [@s.name], "message" => 'hello world', "vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3', "device_pin" => @c.device_pin, "device_port" => @c.device_port} post = mock('post') post.stub!(:new).and_return(post) post.stub!(:body=) Net::HTTP::Post.stub!(:new).and_return(post) @http = mock('http') @http.stub!(:request) @http.stub!(:start).and_yield(@http) Net::HTTP.stub!(:new).and_return(@http) end it "should ping blackberry" do Blackberry.ping(@params) end it "should ping blackberry with connection error" do error = 'Connection refused' Rhoconnect::Blackberry.stub!(:get_config).and_return({:test => {:mdsserver=>'testserver',:mdsserverport=>'testport'}}) Rhoconnect::Blackberry.should_receive(:get_config).once @http.stub!(:request).and_return { raise SocketError.new(error) } Blackberry.should_receive(:log).once.with("Error while sending ping: #{error}") lambda { Blackberry.ping(@params) }.should raise_error(SocketError,error) end it "should do nothing if no host and port" do error = 'Connection refused' Rhoconnect::Blackberry.stub!(:get_config).and_return({:test => {}}) Rhoconnect::Blackberry.should_receive(:get_config).once Net::HTTP.should_receive(:new).exactly(0).times Blackberry.ping(@params) end it "should compute pap_message" do expected = < ]>
--asdlfkjiurwghasf Content-Type: text/plain do_sync=SampleAdapter alert=hello world vibrate=5 sound=hello.mp3 --asdlfkjiurwghasf-- PAP actual = Blackberry.pap_message(@params).gsub!(/pushID\:\d+/,'pushID:RAND_ID') actual.gsub!(/\r|\n|\s/,"").should == expected.gsub!(/\r|\n|\s/,"") end end end