Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

Commit

Permalink
Only set the head where there are elements in the collection
Browse files Browse the repository at this point in the history
This caused sparse nil's to be added to a collection sometimes
which can cause very strange bugs
  • Loading branch information
dbussink committed Nov 2, 2009
1 parent c318941 commit 2e8e7fd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/dm-core/collection.rb
Expand Up @@ -216,7 +216,7 @@ def first(*args)
collection
elsif with_query || loaded?
collection.to_a.first
else
elsif collection.any?
head[0] = collection.to_a.first
end
end
Expand Down
15 changes: 15 additions & 0 deletions spec/public/shared/finder_shared_spec.rb
Expand Up @@ -732,6 +732,21 @@
end
end

describe 'on an empty collection' do
before :all do
@articles = @articles.all(:id => nil)
@return = @articles.first
end

it 'should still be an empty collection' do
@articles.should be_empty
end

it 'should return nil' do
@return.should be_nil
end
end

describe 'with offset specified' do
before :all do
@return = @resource = @articles.first(:offset => 1)
Expand Down

0 comments on commit 2e8e7fd

Please sign in to comment.