Sha256: f8368b618e3668690846382760c60690a898a9954c4d0aae2736a8c487b2bc73

Contents?: true

Size: 1.2 KB

Versions: 8

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe Object do
  context 'bullet_key' do
    it 'should return class and id composition' do
      post = Post.first
      expect(post.bullet_key).to eq("Post:#{post.id}")
    end

    if mongoid?
      it 'should return class with namesapce and id composition' do
        post = Mongoid::Post.first
        expect(post.bullet_key).to eq("Mongoid::Post:#{post.id}")
      end
    end
  end

  context 'bullet_primary_key_value' do
    it 'should return id' do
      post = Post.first
      expect(post.bullet_primary_key_value).to eq(post.id)
    end

    it 'should return primary key value' do
      post = Post.first
      Post.primary_key = 'name'
      expect(post.bullet_primary_key_value).to eq(post.name)
      Post.primary_key = 'id'
    end

    it 'should return value for multiple primary keys' do
      post = Post.first
      allow(Post).to receive(:primary_keys).and_return(%i[category_id writer_id])
      expect(post.bullet_primary_key_value).to eq("#{post.category_id},#{post.writer_id}")
    end

    it 'it should return nil for unpersisted records' do
      post = Post.new(id: 123)
      expect(post.bullet_primary_key_value).to be_nil
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
bullet-6.1.4 spec/bullet/ext/object_spec.rb
bullet-6.1.3 spec/bullet/ext/object_spec.rb
bullet-6.1.2 spec/bullet/ext/object_spec.rb
bullet-6.1.1 spec/bullet/ext/object_spec.rb
bullet-6.1.0 spec/bullet/ext/object_spec.rb
bullet-6.0.2 spec/bullet/ext/object_spec.rb
bullet-6.0.1 spec/bullet/ext/object_spec.rb
bullet-6.0.0 spec/bullet/ext/object_spec.rb