Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement call method in pipelined block #283

Merged
merged 1 commit into from
Oct 29, 2023
Merged
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
4 changes: 0 additions & 4 deletions lib/mock_redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ def id
end
alias location id

def call(command, &_block)
send(*command)
end

def host
options[:host]
end
Expand Down
4 changes: 4 additions & 0 deletions lib/mock_redis/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ def initialize_copy(_source)

# Redis commands go below this line and above 'private'

def call(command, &_block)
public_send(*command)
end

def auth(_)
'OK'
end
Expand Down
22 changes: 22 additions & 0 deletions spec/commands/pipelined_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,26 @@
expect(results).to eq([value1, value2])
end
end

context 'with `call` method' do
let(:key1) { 'hello' }
let(:key2) { 'world' }
let(:value1) { 'foo' }
let(:value2) { 'bar' }

before do
@redises.set key1, value1
@redises.set key2, value2
end

it 'returns results of pipelined operations' do
results = @redises.pipelined do |redis|
redis.call(['get', key1])
redis.call(['set', key2, 'foobar'])
redis.call(['get', key2])
end

expect(results).to eq([value1, 'OK', 'foobar'])
end
end
end
Loading