Skip to content

Commit

Permalink
Merge branch 'master' into feature/emit-metrics-via-datadog
Browse files Browse the repository at this point in the history
  • Loading branch information
vu-hoang-kaligo authored Jan 14, 2025
2 parents 19a7aa6 + c972f6e commit 96affbc
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
idempotency (0.1.2)
idempotency (0.1.3)
base64
dry-configurable
dry-monitor
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,14 @@ end

# Render your response
```

### Testing

For those using `mock_redis` gem, some methods that `idempotency` gem uses are not implemented (e.g. eval, evalsha), and this could cause test cases to fail. To get around this, the gem has a monkeypatch over `mock_redis` gem to override the missing methods. To use it, simply add following lines to your `spec_helper.rb`:

```ruby
RSpec.configure do |config|
config.include Idempotency::Testing::Helpers
end
```

29 changes: 29 additions & 0 deletions lib/idempotency/testing/helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

require 'idempotency/cache'

class Idempotency
module Testing
module Helpers
def self.included(_base)
return unless defined?(MockRedis)

MockRedis.class_eval do
def evalsha(sha, keys:, argv:)
return unless sha == Idempotency::Cache::COMPARE_AND_DEL_SCRIPT_SHA

value = argv[0]
cached_value = get(keys[0])

if value == cached_value
del(keys[0])
value
else
cached_value
end
end
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/idempotency/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

class Idempotency
VERSION = '0.1.2'
VERSION = '0.1.3'
end

0 comments on commit 96affbc

Please sign in to comment.