Skip to content
This repository has been archived by the owner on Jul 23, 2023. It is now read-only.

Upgrade dependencies #243

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 96 additions & 84 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,79 +2,86 @@ PATH
remote: .
specs:
slanger (0.6.0)
activesupport (~> 4.2.1)
em-hiredis (~> 0.2.0)
em-http-request (~> 0.3.0)
em-websocket (~> 0.5.1)
eventmachine (~> 1.0.0)
oj (~> 2.12.9)
rack (~> 1.4.5)
rack-fiber_pool (~> 0.9.2)
signature (~> 0.1.6)
sinatra (~> 1.4.4)
thin (~> 1.6.0)
activesupport
em-hiredis
em-http-request
em-websocket
eventmachine
oj
rack
rack-fiber_pool
signature
sinatra
thin

GEM
remote: https://rubygems.org/
specs:
activesupport (4.2.5)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
activesupport (6.0.2.2)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
addressable (2.3.8)
byebug (3.5.1)
columnize (~> 0.8)
debugger-linecache (~> 1.2)
slop (~> 3.6)
coderay (1.1.0)
columnize (0.9.0)
crack (0.4.2)
zeitwerk (~> 2.2)
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
byebug (11.1.3)
coderay (1.1.2)
concurrent-ruby (1.1.6)
cookiejar (0.3.3)
crack (0.4.3)
safe_yaml (~> 1.0.0)
daemons (1.2.3)
debugger-linecache (1.2.0)
daemons (1.3.1)
diff-lcs (1.3)
em-hiredis (0.2.1)
hiredis (~> 0.4.0)
em-http-request (0.3.0)
addressable (>= 2.0.0)
escape_utils
eventmachine (>= 0.12.9)
em-hiredis (0.3.1)
eventmachine (~> 1.0)
hiredis (~> 0.6.0)
em-http-request (1.1.5)
addressable (>= 2.3.4)
cookiejar (!= 0.3.1)
em-socksify (>= 0.3)
eventmachine (>= 1.0.3)
http_parser.rb (>= 0.6.0)
em-socksify (0.3.2)
eventmachine (>= 1.0.0.beta.4)
em-websocket (0.5.1)
eventmachine (>= 0.12.9)
http_parser.rb (~> 0.6.0)
escape_utils (1.1.0)
eventmachine (1.0.8)
haml (3.1.8)
hiredis (0.4.5)
eventmachine (1.2.7)
haml (5.1.2)
temple (>= 0.8.0)
tilt
hashdiff (1.0.1)
hiredis (0.6.3)
http_parser.rb (0.6.0)
httpclient (2.6.0.1)
i18n (0.7.0)
json (1.8.3)
metaclass (0.0.4)
method_source (0.8.2)
minitest (5.8.4)
mocha (0.13.3)
metaclass (~> 0.0.1)
multi_json (1.11.0)
oj (2.12.12)
pry (0.10.1)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
pry-byebug (2.0.0)
byebug (~> 3.4)
pry (~> 0.10)
pusher (0.14.4)
httpclient (~> 2.5)
httpclient (2.8.3)
i18n (1.8.2)
concurrent-ruby (~> 1.0)
method_source (1.0.0)
minitest (5.14.0)
mocha (1.11.2)
multi_json (1.14.1)
mustermann (1.1.1)
ruby2_keywords (~> 0.0.1)
oj (3.10.6)
pry (0.13.1)
coderay (~> 1.1)
method_source (~> 1.0)
pry-byebug (3.9.0)
byebug (~> 11.0)
pry (~> 0.13.0)
public_suffix (4.0.4)
pusher (1.3.3)
httpclient (~> 2.7)
multi_json (~> 1.0)
signature (~> 0.1.8)
rack (1.4.7)
pusher-signature (~> 0.1.8)
pusher-signature (0.1.8)
rack (2.2.2)
rack-fiber_pool (0.9.3)
rack-protection (1.5.3)
rack-protection (2.0.8.1)
rack
rake (10.4.2)
rake (13.0.1)
rb-readline (0.5.5)
rspec (3.6.0)
rspec-core (~> 3.6.0)
rspec-expectations (~> 3.6.0)
Expand All @@ -88,41 +95,46 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.6.0)
rspec-support (3.6.0)
safe_yaml (1.0.4)
ruby2_keywords (0.0.2)
safe_yaml (1.0.5)
signature (0.1.8)
sinatra (1.4.6)
rack (~> 1.4)
rack-protection (~> 1.4)
tilt (>= 1.3, < 3)
slop (3.6.0)
thin (1.6.3)
sinatra (2.0.8.1)
mustermann (~> 1.0)
rack (~> 2.0)
rack-protection (= 2.0.8.1)
tilt (~> 2.0)
temple (0.8.2)
thin (1.7.2)
daemons (~> 1.0, >= 1.0.9)
eventmachine (~> 1.0)
rack (~> 1.0)
thread_safe (0.3.5)
tilt (2.0.2)
timecop (0.3.5)
tzinfo (1.2.2)
eventmachine (~> 1.0, >= 1.0.4)
rack (>= 1, < 3)
thread_safe (0.3.6)
tilt (2.0.10)
timecop (0.9.1)
tzinfo (1.2.7)
thread_safe (~> 0.1)
webmock (1.8.11)
addressable (>= 2.2.7)
crack (>= 0.1.7)
webmock (3.8.3)
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
zeitwerk (2.3.0)

PLATFORMS
ruby

DEPENDENCIES
bundler (~> 1.5)
haml (~> 3.1.2)
mocha (~> 0.13.2)
pry (~> 0.10.1)
pry-byebug (~> 2.0.0)
pusher (~> 0.14.2)
rake (~> 10.4.2)
bundler
haml
mocha
pry
pry-byebug
pusher
rake
rb-readline
rspec (~> 3.6.0)
slanger!
timecop (~> 0.3.5)
webmock (~> 1.8.7)
timecop
webmock

BUNDLED WITH
1.15.3
1.17.1
2 changes: 1 addition & 1 deletion lib/slanger/redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def regular_connection
end

def publisher
@publisher ||= new_connection
@publisher ||= new_connection.pubsub
end

def subscriber
Expand Down
43 changes: 22 additions & 21 deletions slanger.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,29 @@ Gem::Specification.new do |s|
s.homepage = "https://github.com/stevegraham/slanger"
s.license = "MIT"

s.add_dependency "eventmachine", "~> 1.0.0"
s.add_dependency "em-hiredis", "~> 0.2.0"
s.add_dependency "em-websocket", "~> 0.5.1"
s.add_dependency "rack", "~> 1.4.5"
s.add_dependency "rack-fiber_pool", "~> 0.9.2"
s.add_dependency "signature", "~> 0.1.6"
s.add_dependency "activesupport", "~> 4.2.1"
s.add_dependency "sinatra", "~> 1.4.4"
s.add_dependency "thin", "~> 1.6.0"
s.add_dependency "em-http-request", "~> 0.3.0"
s.add_dependency "oj", "~> 2.12.9"
s.add_dependency "eventmachine"
s.add_dependency "em-hiredis"
s.add_dependency "em-websocket"
s.add_dependency "rack"
s.add_dependency "rack-fiber_pool"
s.add_dependency "signature"
s.add_dependency "activesupport"
s.add_dependency "sinatra"
s.add_dependency "thin"
s.add_dependency "em-http-request"
s.add_dependency "oj"

s.add_development_dependency "rspec", "~> 3.6.0"
s.add_development_dependency "pusher", "~> 0.14.2"
s.add_development_dependency "haml", "~> 3.1.2"
s.add_development_dependency "timecop", "~> 0.3.5"
s.add_development_dependency "webmock", "~> 1.8.7"
s.add_development_dependency "mocha", "~> 0.13.2"
s.add_development_dependency "pry", "~> 0.10.1"
s.add_development_dependency "pry-byebug", "~> 2.0.0"
s.add_development_dependency "bundler", "~> 1.5"
s.add_development_dependency "rake", "~> 10.4.2"
s.add_development_dependency "rspec", "~> 3.6.0"
s.add_development_dependency "pusher"
s.add_development_dependency "haml"
s.add_development_dependency "timecop"
s.add_development_dependency "webmock"
s.add_development_dependency "mocha"
s.add_development_dependency "pry"
s.add_development_dependency "pry-byebug"
s.add_development_dependency "bundler"
s.add_development_dependency "rake"
s.add_development_dependency "rb-readline"

s.files = Dir["README.md", "lib/**/*", "slanger.rb"]
s.require_path = "."
Expand Down
19 changes: 11 additions & 8 deletions spec/unit/channel_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def clear_redis_connections

describe 'Slanger::Channel' do
let(:channel) { Slanger::Channel.create channel_id: 'test' }
let(:mock_incr_response) {mock("Incr response mock")}

before(:each) do
EM::Hiredis.stubs(:connect).returns stub_everything('redis', :pubsub => stub_everything('redis'))
Expand All @@ -23,9 +24,10 @@ def clear_redis_connections

describe '#unsubscribe' do
it 'decrements channel subscribers on Redis' do
mock_incr_response.expects(:callback).once.yields(2)
Slanger::Redis.expects(:hincrby).
with('channel_subscriber_count', channel.channel_id, -1).
once.returns mock { expects(:callback).once.yields(2) }
once.returns mock_incr_response

channel.unsubscribe 1
end
Expand All @@ -35,34 +37,35 @@ def clear_redis_connections
with(name: 'channel_vacated', channel: channel.channel_id).
once

mock_incr_response.expects(:callback).times(3).yields(2).then.yields(1).then.yields(0)
Slanger::Redis.expects(:hincrby).
with('channel_subscriber_count', channel.channel_id, -1).
times(3).returns mock {
expects(:callback).times(3).yields(2).then.yields(1).then.yields(0)
}
times(3).returns mock_incr_response

3.times { |i| channel.unsubscribe i + 1 }
end
end

describe '#subscribe' do
it 'increments channel subscribers on Redis' do
mock_incr_response.expects(:callback).once.yields(2)

Slanger::Redis.expects(:hincrby).
with('channel_subscriber_count', channel.channel_id, 1).
once.returns mock { expects(:callback).once.yields(2) }
once.returns mock_incr_response
channel.subscribe { |m| nil }
end

it 'activates a webhook when the first subscriber of a channel joins' do
mock_incr_response.expects(:callback).times(3).yields(1).then.yields(2).then.yields(3)
Slanger::Webhook.expects(:post).
with(name: 'channel_occupied', channel: channel.channel_id).
once

Slanger::Redis.expects(:hincrby).
with('channel_subscriber_count', channel.channel_id, 1).
times(3).returns mock {
expects(:callback).times(3).yields(1).then.yields(2).then.yields(3)
}
times(3).returns mock_incr_response


3.times { channel.subscribe { |m| nil } }
end
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/request_validation_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#encoding: utf-8
require 'spec_helper'
require "signature"

describe Slanger::Api::RequestValidation do
describe '#socket_id' do
Expand Down Expand Up @@ -69,4 +70,3 @@ def body(socket_id)
{socket_id: socket_id}.to_json
end
end

9 changes: 8 additions & 1 deletion spec/unit/webhook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@

describe 'Slanger::Webhook' do

def ensure_em
unless EventMachine.reactor_running? && EventMachine.reactor_thread.alive?
Thread.new { EventMachine.run }
sleep 1
end
end

around do |example|
Slanger::Config.load webhook_url: 'https://example.com/pusher',
app_key: 'PUSHER_APP_KEY', secret: 'secret'
Expand All @@ -21,7 +28,7 @@

digest = OpenSSL::Digest::SHA256.new
hmac = OpenSSL::HMAC.hexdigest(digest, Slanger::Config.secret, payload)

ensure_em
stub_request(:post, Slanger::Config.webhook_url).
with(body: payload, headers: {
"X-Pusher-Key" => Slanger::Config.app_key,
Expand Down