Sha256: 5fcf995421063de955c604c6a3c0faeffe59f5a1de0006e9e255db1cde219d41

Contents?: true

Size: 609 Bytes

Versions: 2

Compression:

Stored size: 609 Bytes

Contents

# 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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
idempotency-0.1.4 lib/idempotency/testing/helpers.rb
idempotency-0.1.3 lib/idempotency/testing/helpers.rb