Skip to content

Commit

Permalink
Fix primary_key spec for older rails versions
Browse files Browse the repository at this point in the history
Post.first.reload wouldn't solve this as composite primary_key isn't 
supported in older AR versions
  • Loading branch information
vprigent committed Jan 25, 2025
1 parent f9677ab commit a0a5370
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions spec/bullet/ext/object_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,16 @@
expect(post.bullet_primary_key_value).to eq("#{post.category_id},#{post.writer_id}")
end

it 'should return value for multiple primary keys from ActiveRecord 7.1' do
allow(Post).to receive(:primary_key).and_return(%i[category_id writer_id])
post = Post.first
expect(post.bullet_primary_key_value).to eq("#{post.category_id},#{post.writer_id}")
if Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new('7.1')
it 'should return value for multiple primary keys from ActiveRecord 7.1' do
allow(Post).to receive(:primary_key).and_return(%i[category_id writer_id])
post = Post.first

expect(post.bullet_primary_key_value).to eq("#{post.category_id},#{post.writer_id}")
end
end

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

0 comments on commit a0a5370

Please sign in to comment.