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

Commit

Permalink
Added Model#fetch
Browse files Browse the repository at this point in the history
* Added specs for #fetch to finder interface
  • Loading branch information
dkubb committed May 25, 2010
1 parent daebfb3 commit 7167f97
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/dm-core/model.rb
Expand Up @@ -305,6 +305,10 @@ def at(*args)
all.at(*args)
end

def fetch(*args, &block)
all.fetch(*args, &block)
end

def reverse
all.reverse
end
Expand Down
47 changes: 47 additions & 0 deletions spec/public/shared/finder_shared_spec.rb
Expand Up @@ -880,6 +880,53 @@
end
end

it { @articles.should respond_to(:fetch) }

describe '#fetch' do
subject { @articles.fetch(*args, &block) }

let(:block) { nil }

context 'with a valid index and no default' do
let(:args) { [ 0 ] }

before do
@copy = @articles.kind_of?(Class) ? @articles : @articles.dup
@copy.to_a
end

should_not_be_a_kicker

it { should be_kind_of(DataMapper::Resource) }

it { should == @copy.entries.fetch(*args) }
end

context 'with an invalid index and no default' do
let(:args) { [ 42 ] }

it { method(:subject).should raise_error(IndexError) }
end

context 'with an invalid index and a default' do
let(:default) { mock('Default') }
let(:args) { [ 42, default ] }

it { should equal(default) }
end

context 'with an invalid index and a block default' do
let(:yields) { [] }
let(:default) { mock('Default') }
let(:block) { lambda { |index| yields << index; default } }
let(:args) { [ 42 ] }

it { should equal(default) }

it { method(:subject).should change { yields.dup }.from([]).to([ 42 ]) }
end
end

it { @articles.should respond_to(:first) }

describe '#first' do
Expand Down

0 comments on commit 7167f97

Please sign in to comment.