Sha256: 72d7a3578438019b1461b84f41229810091ddef5a43017d7e493fb229b6d2717

Contents?: true

Size: 1.27 KB

Versions: 4

Compression:

Stored size: 1.27 KB

Contents

# rubocop:disable RSpec/FilePath
#
module SimpleRedisOrm
  RSpec.describe ApplicationEntry do
    let(:subject_class) do
      Class.new(ApplicationEntry) do
        attribute :email, Types::String.optional

        class << self
          def new(id:, **attributes)
            super(id: id, **attributes.merge(email: without_redis_key_prefix(id)))
          end

          def create(email:)
            attrs = { email: email }

            new(id: email, **attrs).save
          end

          def name
            'SomeModel'
          end

          def redis
            Entry.redis
          end
        end
      end
    end

    describe '.new' do
      it 'add redis entry' do
        user = subject_class.new(id: 'desoleary@gmail.com')
        user.save

        actual = subject_class.find('desoleary@gmail.com')
        expect(actual.attributes).to eql({ email: 'desoleary@gmail.com' })
      end
    end

    describe '.create' do
      let(:email) { 'email@domain.com' }

      it 'add redis entry' do
        subject_class.create(email: email)

        user = subject_class.find(email)
        expect(user.key).to eql("some_model:#{email}")
        expect(user.id).to eql(email)
        expect(user.email).to eql(email)
      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/application_entry_spec.rb
simple-redis-orm-0.1.2 spec/simple-redis-orm/application_entry_spec.rb
simple-redis-orm-0.1.1 spec/simple-redis-orm/application_entry_spec.rb
simple-redis-orm-0.1.0 spec/simple-redis-orm/application_entry_spec.rb