Skip to content

Commit

Permalink
Allow setting redis client
Browse files Browse the repository at this point in the history
  • Loading branch information
markedmondson committed Oct 23, 2024
1 parent 51bc4c8 commit b0aa997
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/shipit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ def redis
)
end

def redis=(client)
@redis ||= client
end

module SafeJSON
class << self
def load(serial)
Expand Down
46 changes: 46 additions & 0 deletions test/unit/shipit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,51 @@ class ShipitTest < ActiveSupport::TestCase
Shipit.github.stubs(:oauth_teams).returns(['shopify/developers'])
assert_equal(['shopify/developers'], Shipit.github_teams.map(&:handle))
end

class RedisTest < self
setup do
@client = mock(:client)
end

teardown do
Shipit.instance_variables.each(&Shipit.method(:remove_instance_variable))
Redis.unstub(:new)
end

test ".redis should build a new redis client" do
Redis.expects(:new).with(
has_entries(
url: "redis://127.0.0.1:6379/7",
reconnect_attempts: 3,
reconnect_delay: 0.5,
reconnect_delay_max: 1
)
).returns(@client)

assert_equal(@client, Shipit.redis)
end

test ".redis should return an existing redis client" do
Redis.expects(:new).once.returns(@client)

2.times do
assert_equal(@client, Shipit.redis)
end
end

test ".redis= should set the redis client" do
Shipit.redis = @client

assert_equal(@client, Shipit.redis)
end

test ".redis= should set and memoize the redis client" do
Shipit.redis = @client

Redis.expects(:new).never

assert_equal(@client, Shipit.redis)
end
end
end
end

0 comments on commit b0aa997

Please sign in to comment.