Sha256: d8df0e0b105d989db135836b2427e911860ec7cbced96b6b275912efa862d550

Contents?: true

Size: 1.96 KB

Versions: 8

Compression:

Stored size: 1.96 KB

Contents

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'
      @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 compute pap_message" do
      expected = <<PAP
--asdlfkjiurwghasf
Content-Type: application/xml; charset=UTF-8
  
<?xml version="1.0"?>
<!DOCTYPE pap PUBLIC "-//WAPFORUM//DTD PAP 2.0//EN" 
  "http://www.wapforum.org/DTD/pap_2.0.dtd" 
  [<?wap-pap-ver supported-versions="2.0"?>]>
<pap>
<push-message push-id="pushID:RAND_ID" ppg-notify-requested-to="http://localhost:7778">

<address address-value="WAPPUSH=0%3A100/TYPE=USER@rim.net"/>
<quality-of-service delivery-method="preferconfirmed"/>
</push-message>
</pap>
--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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rhoconnect-3.2.1 spec/ping/blackberry_spec.rb
rhoconnect-3.2.0 spec/ping/blackberry_spec.rb
rhoconnect-3.2.0.beta5 spec/ping/blackberry_spec.rb
rhoconnect-3.2.0.beta4 spec/ping/blackberry_spec.rb
rhoconnect-3.2.0.beta3 spec/ping/blackberry_spec.rb
rhoconnect-3.2.0.beta2 spec/ping/blackberry_spec.rb
rhoconnect-3.2.0.beta1 spec/ping/blackberry_spec.rb
rhoconnect-3.1.2 spec/ping/blackberry_spec.rb