Skip to content

Commit

Permalink
Merge pull request #3 from groupme/disconnect_tests_from_apns
Browse files Browse the repository at this point in the history
Don't connect to APNS in tests
  • Loading branch information
daveyeu committed Oct 13, 2011
2 parents c2445f9 + 5ffc3ee commit 6e494d0
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 21 deletions.
6 changes: 1 addition & 5 deletions lib/em-apn/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module APN
class Client < EventMachine::Connection
SANDBOX_GATEWAY = "gateway.sandbox.push.apple.com"
PRODUCTION_GATEWAY = "gateway.push.apple.com"
PORT = 2195
PORT = 2195

# Create a connection to Apple's push notification gateway
#
Expand All @@ -26,10 +26,6 @@ def self.connect(options = {})
EM.connect(gateway, PORT, self, options)
end

def self.gateway
(ENV["APN_ENV"] == "production") ? "gateway.push.apple.com" : "gateway.sandbox.push.apple.com"
end

def initialize(options = {})
@key = options[:key]
@cert = options[:cert]
Expand Down
4 changes: 0 additions & 4 deletions lib/em-apn/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ def deliver_with_testing(notification)
alias :deliver_without_testing :deliver
alias :deliver :deliver_with_testing

def connect
# Nope
end

def send_data(data)
# Nope
end
Expand Down
15 changes: 5 additions & 10 deletions spec/em-apn/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ def new_client(*args)
end

context "configuring the gateway" do
before do
ENV["APN_GATEWAY"] = nil
end

let(:options) { {:key => ENV["APN_KEY"], :cert => ENV["APN_CERT"]} }

it "defaults to Apple's sandbox (gateway.sandbox.push.apple.com)" do
Expand All @@ -33,14 +37,11 @@ def new_client(*args)
end

it "uses an environment variable for the gateway host (APN_GATEWAY) if specified" do
original_apn_gateway = ENV["APN_GATEWAY"]
ENV["APN_GATEWAY"] = "localhost"

expected_args = ["localhost", 2195, EM::APN::Client, options]
EM.should_receive(:connect).with(*expected_args).and_return(client)
EM::APN::Client.connect.should == client

ENV["APN_GATEWAY"] = original_apn_gateway
end

it "switches to the production gateway if APN_ENV is set to 'production'" do
Expand All @@ -56,21 +57,15 @@ def new_client(*args)

context "configuring SSL" do
it "falls back to environment variables for key and cert (APN_KEY and APN_CERT) if they are unspecified" do
original_apn_key = ENV["APN_KEY"]
original_apn_cert = ENV["APN_CERT"]

ENV["APN_KEY"] = "path/to/key.pem"
ENV["APN_CERT"] = "path/to/cert.pem"

expected_args = ["gateway.sandbox.push.apple.com", 2195, EM::APN::Client, {
expected_args = ["127.0.0.1", 2195, EM::APN::Client, {
:key => "path/to/key.pem",
:cert => "path/to/cert.pem"
}]
EM.should_receive(:connect).with(*expected_args).and_return(client)
EM::APN::Client.connect.should == client

ENV["APN_KEY"] = original_apn_key
ENV["APN_CERT"] = original_apn_cert
end

it "key and cert are used to start SSL" do
Expand Down
5 changes: 3 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

RSpec.configure do |config|
config.before(:each) do
ENV["APN_KEY"] = "spec/support/certs/key.pem"
ENV["APN_CERT"] = "spec/support/certs/cert.pem"
ENV["APN_KEY"] = "spec/support/certs/key.pem"
ENV["APN_CERT"] = "spec/support/certs/cert.pem"
ENV["APN_GATEWAY"] = "127.0.0.1"

EM::APN.logger = Logger.new("/dev/null")
end
Expand Down

0 comments on commit 6e494d0

Please sign in to comment.