Skip to content

Commit

Permalink
Reconnect with HTTPS fix: establish SSL connection also when reconnec…
Browse files Browse the repository at this point in the history
…ting

Fixes voloko#22
  • Loading branch information
rud committed Jan 26, 2012
1 parent 6b5c2fa commit 60f5369
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/twitter/json_stream.rb
Expand Up @@ -60,7 +60,6 @@ def self.connect options = {}
end

connection = EventMachine.connect host, port, self, options
connection.start_tls if options[:ssl]
connection
end

Expand Down Expand Up @@ -122,6 +121,7 @@ def receive_data(data)
end

def connection_completed
start_tls if @options[:ssl]
send_request
end

Expand Down
13 changes: 13 additions & 0 deletions spec/twitter/json_stream_spec.rb
Expand Up @@ -69,6 +69,13 @@ def receive_data data
stream = JSONStream.connect(:proxy => "http://my-proxy:8080") {}
end

it "should not trigger SSL until connection is established" do
connection = stub('connection')
EM.should_receive(:connect).and_return(connection)
stream = JSONStream.connect(:ssl => true)
stream.should == connection
end

end

context "on valid stream" do
Expand Down Expand Up @@ -198,6 +205,12 @@ def receive_data data
end
end

it "should reconnect with SSL if enabled" do
connect_stream :ssl => true do
stream.should_receive(:start_tls).twice
end
end

it_should_behave_like "network failure"
end

Expand Down

0 comments on commit 60f5369

Please sign in to comment.