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

#292 extend set method to accept a third positional argument #299

Merged
merged 2 commits into from
Jan 17, 2024
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: 2 additions & 2 deletions lib/mock_redis/string_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ def mapped_msetnx(hash)

# Parameter list required to ensure the ArgumentError is returned correctly
# rubocop:disable Metrics/ParameterLists
def set(key, value, ex: nil, px: nil, exat: nil, pxat: nil, nx: nil, xx: nil, keepttl: nil,
get: nil)
def set(key, value, _hash = nil, ex: nil, px: nil, exat: nil, pxat: nil, nx: nil, xx: nil,
keepttl: nil, get: nil)
key = key.to_s
retval = self.get(key) if get

Expand Down
16 changes: 15 additions & 1 deletion spec/commands/set_spec.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
require 'spec_helper'

RSpec.describe '#set(key, value)' do
RSpec.describe '#set(key, value, _hash)' do
let(:key) { 'mock-redis-test' }

it "responds with 'OK'" do
expect(@redises.set('mock-redis-test', 1)).to eq('OK')
end

context 'when the positional argument _hash exists' do
it "responds with 'OK'" do
# Testing MockRedis.new.set instead of @redises.set
# because the latter doesn't align with Redis's set method.
# In mock_redis, set accepts a third positional argument, _hash,
# to accommodate the difference with redis-store's set method,
# which takes three positional arguments, unlike the standard Redis set.
# Reference:
# Redis: https://github.com/redis/redis-rb/blob/09acb9026ab2deaca4c851e0bcdb0ef9318b1ee0/lib/redis/commands/strings.rb#L83
# Redis-store: https://github.com/redis-store/redis-store/blob/5c3fee1b8fba672eb2bd5bfaedb973b68d12b773/lib/redis/store/ttl.rb#L4
expect(MockRedis.new.set('mock-redis-test', 1, { key: 'value' })).to eq('OK')
end
end

context 'options' do
it 'raises an error for EX seconds = 0' do
expect do
Expand Down
Loading