Sha256: db2fc785a7b615549c2610e136a75da20332cc070d266eaa242bbe1a261c20ff

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

Contents

require 'unit_spec_helper'

describe 'GCM' do
  let(:app) { Rpush::Wpns::App.new }
  let(:notification) { Rpush::Wpns::Notification.new }
  let(:response) { double(Net::HTTPResponse, code: 200) }
  let(:http) { double(Net::HTTP::Persistent, request: response, shutdown: nil) }

  before do
    app.name = 'test'
    app.save!

    notification.app = app
    notification.uri = 'http://sn1.notify.live.net/'
    notification.alert = 'test'
    notification.save!

    Rails.stub(root: File.expand_path(File.join(File.dirname(__FILE__), '..', 'tmp')))
    Rpush.config.logger = ::Logger.new(STDOUT)

    Net::HTTP::Persistent.stub(new: http)
  end

  it 'delivers a notification successfully' do
    response.stub(to_hash: {'x-notificationstatus' => ['Received']})

    expect do
      Rpush.push
      notification.reload
    end.to change(notification, :delivered).to(true)
  end

  it 'fails to deliver a notification successfully' do
    response.stub(code: 400)

    expect do
      Rpush.push
      notification.reload
    end.to_not change(notification, :delivered).to(true)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rpush-1.0.0-java spec/functional/wpns_spec.rb
rpush-1.0.0 spec/functional/wpns_spec.rb