Skip to content

Commit

Permalink
fix(http-stream): Add HTTPS support
Browse files Browse the repository at this point in the history
  • Loading branch information
pandomic committed May 2, 2019
1 parent 2a1551b commit 4c2f627
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Documentation for error handlers
- Tests for error handlers
- New method to build Message from json

## [0.1.2] - 2019-05-02
### Added
- HTTPS targets support
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
active_record_streams (0.1.1)
active_record_streams (0.1.2)
activerecord (~> 4.2.10)
aws-sdk (~> 2.11.9)

Expand Down Expand Up @@ -93,4 +93,4 @@ DEPENDENCIES
rubocop-performance (~> 1.1.0)

BUNDLED WITH
1.17.1
1.17.3
10 changes: 9 additions & 1 deletion lib/active_record_streams/publishers/http_stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,15 @@ def request
end

def http
@http ||= Net::HTTP.new(uri.host, uri.port)
@http ||= begin
http_client = Net::HTTP.new(uri.host, uri.port)
http_client.use_ssl = true if https?
http_client
end
end

def https?
uri.scheme == 'https'
end

def uri
Expand Down
15 changes: 14 additions & 1 deletion lib/active_record_streams/publishers/http_stream_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

let(:request) { double('body=': nil) }
let(:response) { double(code: 200) }
let(:http_client) { double('body=': nil, request: response) }
let(:http_client) { double('body=': nil, 'use_ssl=': nil, request: response) }
let(:message) { double(json: '{}') }

subject do
Expand Down Expand Up @@ -88,5 +88,18 @@
subject.publish(actual_table_name, message)
end
end

context 'https target' do
let(:url) { 'https://hello.world' }

it 'sends event to an https target' do
expect(http_client).to receive(:use_ssl=).with(true)

subject.publish(actual_table_name, message)

expect(request).to have_received(:body=).with(message.json)
expect(http_client).to have_received(:request).with(request)
end
end
end
end
2 changes: 1 addition & 1 deletion lib/active_record_streams/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module ActiveRecordStreams
VERSION = '0.1.1'
VERSION = '0.1.2'
end
2 changes: 1 addition & 1 deletion lib/active_record_streams/version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

RSpec.describe ActiveRecordStreams::VERSION do
it 'has a version number' do
expect(subject).to eq('0.1.1')
expect(subject).to eq('0.1.2')
end
end

0 comments on commit 4c2f627

Please sign in to comment.