Sha256: 65f53a7ff9a857fc88eac84034a49c1c90aef8e3a3af95af9cfc7342e3ab0a78

Contents?: true

Size: 1.77 KB

Versions: 4

Compression:

Stored size: 1.77 KB

Contents

# rubocop:disable RSpec/FilePath
module SimpleRedisOrm
  module Helpers
    RSpec.describe CoreCommands do
      let(:subject_class) do
        Class.new(Dry::Struct) do
          include CoreCommands
          extend CoreCommands::ClassMethods

          attribute :key, Types::String

          def redis
            self.class.redis
          end

          class << self
            def redis
              @redis ||= MockRedis.new
            end
          end
        end
      end

      let(:key) { 'some-key' }
      let(:field) { :field }
      let(:field_value) { 'some-value' }
      let(:hash_value) { { field => field_value } }
      let(:other_field) { :other_field }
      let(:other_value) { 'other_value' }
      let(:instance) { subject_class.new(key: key) }

      subject(:redis_command) do
        instance.set_hash(hash_value)
        instance
      end

      describe 'ClassMethods' do
        describe '.read_value' do
          before { instance.set(other_value) }

          it 'returns set simple value' do
            actual = subject_class.read_value(key)

            expect(actual).to eql(other_value)
          end
        end

        describe '.read_hash' do
          it 'returns original hash value' do
            redis_command

            expect(subject_class.read_hash(key)).to eql(hash_value)
          end
        end

        describe '.read_by' do
          it 'returns original hash value' do
            redis_command

            expect(subject_class.read_by(key)).to eql(hash_value)
          end

          context 'with unexpected key' do
            it 'returns original hash value' do
              expect(subject_class.read_by('some-other-key')).to be_nil
            end
          end
        end
      end
    end
  end
end
# rubocop:enable RSpec/FilePath

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
simple-redis-orm-0.1.3 spec/simple-redis-orm/helpers/core_commands_spec.rb
simple-redis-orm-0.1.2 spec/simple-redis-orm/helpers/core_commands_spec.rb
simple-redis-orm-0.1.1 spec/simple-redis-orm/helpers/core_commands_spec.rb
simple-redis-orm-0.1.0 spec/simple-redis-orm/helpers/core_commands_spec.rb