r.should eq [@artist]
end
end
- context 'DBに5件あって1ページの件数を0件に変えたとして' do
- before do
- @artist2 = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist2', :created_at => Time.now + 100
- @artist3 = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist3', :created_at => Time.now + 200
- @artist4 = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist4', :created_at => Time.now + 300
- @artist5 = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist5', :created_at => Time.now + 400
- Artist.stub(:default_page_size).and_return(2)
- end
- it '通常は全件(5件)を返す' do
- r = Artist.list 5, 0
- r.should have(5).items
- end
+ end
+
+ describe '一覧ページ制御に於いて' do
+ before do
+ Artist.stub(:count).with(any_args).and_return(100)
+ end
+ it 'ページ制御を返す' do
+ r = Artist.list_paginate
+ r.is_a?(Kaminari::PaginatableArray).should be_true
+ end
+ it '一覧の取得条件を利用している' do
+ Artist.stub(:list_where).with(any_args).and_return('')
+ Artist.should_receive(:list_where).with(any_args).exactly(1)
+ r = Artist.list_paginate
+ end
+ it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
+ r = Artist.list_paginate 3, 10
+ r.limit_value.should eq 10
+ r.offset_value.should eq 20
end
end
+
describe '一覧取得オプションに於いて' do
- it 'includeキーを含んでいる' do
- r = Artist.list_opt
- r.has_key?(:include).should be_true
- end
it '1つの項目を含んでいる' do
- r = Artist.list_opt[:include]
+ r = Artist.list_opt
r.should have(1).items
end
it '作家を含んでいる' do
- r = Artist.list_opt[:include]
+ r = Artist.list_opt
r.has_key?(:author).should be_true
end
end