c.should eq [@comic]
end
end
- context 'DBに5件あって1ページの件数を2件に変えたとして' do
- before do
- @comic2 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 100
- @comic3 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 200
- @comic4 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 300
- @comic5 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 400
- Comic.stub(:default_page_size).and_return(2)
- end
- it '件数0は全件(5件)を返す' do
- r = Comic.list 5, 0
- r.should have(5).items
- end
- end
- end
- describe '一覧取得オプションに於いて' do
- it 'includeキーを含んでいる' do
- r = Comic.list_opt
- r.has_key?(:include).should be_true
- end
- it '2つの項目を含んでいる' do
- r = Comic.list_opt[:include]
- r.should have(2).items
- end
- it 'ストーリーを含んでいる' do
- r = Comic.list_opt[:include]
- r.has_key?(:stories).should be_true
- end
- it 'ストーリーはコマを含んでいる' do
- r = Comic.list_opt[:include]
- r[:stories].has_key?(:panel).should be_true
- end
- it '作家を含んでいる' do
- r = Comic.list_opt[:include]
- r.has_key?(:author).should be_true
- end
- end
- describe 'json一覧出力オプションに於いて' do
- before do
- @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
- @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
- @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
- @sbt = FactoryGirl.create :speech_balloon_template
- @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
- @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
- @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
- end
- it 'ストーリーを含んでいる' do
- r = Comic.list.to_json Comic.list_json_opt
- j = JSON.parse r
- i = j.first
- i.has_key?('stories').should be_true
- end
- it 'ストーリーはコマを含んでいる' do
- r = Comic.list.to_json Comic.list_json_opt
- j = JSON.parse r
- i = j.first
- s = i['stories'].first
- s.has_key?('panel').should be_true
- end
- it '作家を含んでいる' do
- r = Comic.list.to_json Comic.list_json_opt
- j = JSON.parse r
- i = j.first
- i.has_key?('author').should be_true
- end
end
describe '自分のコミック一覧取得に於いて' do
c.should eq [@comic]
end
end
- context 'DBに5件あって1ページの件数を0件に変えたとして' do
+ end
+
+ describe '他作家のコミック一覧取得に於いて' do
+ before do
+ @comic = FactoryGirl.create :comic, :author_id => @author.id
+ @other_comic = FactoryGirl.create :comic, :author_id => @other_author.id, :visible => 1
+ end
+ context 'つつがなく終わるとき' do
+ it '一覧取得オプションを利用している' do
+ Comic.stub(:list_opt).with(any_args).and_return({})
+ Comic.should_receive(:list_opt).with(any_args).exactly(1)
+ r = Comic.himlist @other_author
+ end
+ end
+ it '指定した作家のリストを返す' do
+ r = Comic.himlist @other_author
+ r.should eq [@other_comic]
+ end
+ it '時系列で並んでいる' do
+ nc = FactoryGirl.create :comic, :author_id => @other_author.id, :updated_at => Time.now + 100
+ r = Comic.himlist @other_author
+ r.should eq [nc, @other_comic]
+ end
+ it '公開コミックに限る ' do
+ hidden = FactoryGirl.create :comic, :author_id => @other_author.id, :visible => 0
+ r = Comic.himlist @other_author
+ r.should eq [@other_comic]
+ end
+ context 'DBに5件あって1ページの件数を2件に変えたとして' do
before do
- @comic2 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 100
- @comic3 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 200
- @comic4 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 300
- @comic5 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 400
- Author.stub(:default_comic_page_size).and_return(2)
+ @other_comic2 = FactoryGirl.create :comic, :author_id => @other_author.id, :updated_at => Time.now + 100
+ @other_comic3 = FactoryGirl.create :comic, :author_id => @other_author.id, :updated_at => Time.now + 200
+ @other_comic4 = FactoryGirl.create :comic, :author_id => @other_author.id, :updated_at => Time.now + 300
+ @other_comic5 = FactoryGirl.create :comic, :author_id => @other_author.id, :updated_at => Time.now + 400
end
- it '通常は全件(5件)を返す' do
- r = Comic.mylist @author, 5, 0
- r.should have(5).items
+ it '通常は2件を返す' do
+ c = Comic.himlist @other_author, 1, 2
+ c.should have(2).items
+ end
+ it 'page=1なら末尾2件を返す' do
+ #時系列で並んでいる
+ c = Comic.himlist(@other_author, 1, 2)
+ c.should eq [@other_comic5, @other_comic4]
+ end
+ it 'page=2なら中間2件を返す' do
+ c = Comic.himlist(@other_author, 2, 2)
+ c.should eq [@other_comic3, @other_comic2]
+ end
+ it 'page=3なら先頭1件を返す' do
+ c = Comic.himlist(@other_author, 3, 2)
+ c.should eq [@other_comic]
+ end
+ end
+ end
+
+ describe 'コミック一覧ページ制御に於いて' do
+ before do
+ Comic.stub(:count).with(any_args).and_return(100)
+ end
+ it 'ページ制御を返す' do
+ r = Comic.list_paginate
+ r.is_a?(Kaminari::PaginatableArray).should be_true
+ end
+ it 'コミック一覧の取得条件を利用している' do
+ Comic.stub(:list_where).with(any_args).and_return('')
+ Comic.should_receive(:list_where).with(any_args).exactly(1)
+ r = Comic.list_paginate
+ end
+ it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
+ r = Comic.list_paginate 3, 10
+ r.limit_value.should eq 10
+ r.offset_value.should eq 20
+ end
+ end
+
+ describe '自分のコミック一覧ページ制御に於いて' do
+ before do
+ Comic.stub(:count).with(any_args).and_return(100)
+ end
+ it 'ページ制御を返す' do
+ r = Comic.mylist_paginate @author
+ r.is_a?(Kaminari::PaginatableArray).should be_true
+ end
+ it '自分のコミック一覧の取得条件を利用している' do
+ Comic.stub(:mylist_where).with(any_args).and_return('')
+ Comic.should_receive(:mylist_where).with(any_args).exactly(1)
+ r = Comic.mylist_paginate @author
+ end
+ it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
+ r = Comic.mylist_paginate @author, 3, 10
+ r.limit_value.should eq 10
+ r.offset_value.should eq 20
+ end
+ end
+
+ describe '他作家のコミック一覧ページ制御に於いて' do
+ before do
+ Comic.stub(:count).with(any_args).and_return(100)
+ end
+ it 'ページ制御を返す' do
+ r = Comic.himlist_paginate @other_author
+ r.is_a?(Kaminari::PaginatableArray).should be_true
+ end
+ it '他作家のコミック一覧の取得条件を利用している' do
+ Comic.stub(:himlist_where).with(any_args).and_return('')
+ Comic.should_receive(:himlist_where).with(any_args).exactly(1)
+ r = Comic.himlist_paginate @other_author
+ end
+ it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
+ r = Comic.himlist_paginate @other_author, 3, 10
+ r.limit_value.should eq 10
+ r.offset_value.should eq 20
+ end
+ end
+
+ describe '一覧取得オプションに於いて' do
+ it '2つの項目を含んでいる' do
+ r = Comic.list_opt
+ r.should have(2).items
+ end
+ it 'ストーリーを含んでいる' do
+ r = Comic.list_opt
+ r.has_key?(:stories).should be_true
+ end
+ it 'ストーリーはコマを含んでいる' do
+ r = Comic.list_opt
+ r[:stories].has_key?(:panel).should be_true
end
+ it '作家を含んでいる' do
+ r = Comic.list_opt
+ r.has_key?(:author).should be_true
+ end
+ end
+ describe 'json一覧出力オプションに於いて' do
+ before do
+ @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
+ @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+ @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
+ @sbt = FactoryGirl.create :speech_balloon_template
+ @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
+ @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
+ @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
+ end
+ it 'ストーリーを含んでいる' do
+ r = Comic.list.to_json Comic.list_json_opt
+ j = JSON.parse r
+ i = j.first
+ i.has_key?('stories').should be_true
+ end
+ it 'ストーリーはコマを含んでいる' do
+ r = Comic.list.to_json Comic.list_json_opt
+ j = JSON.parse r
+ i = j.first
+ s = i['stories'].first
+ s.has_key?('panel').should be_true
+ end
+ it '作家を含んでいる' do
+ r = Comic.list.to_json Comic.list_json_opt
+ j = JSON.parse r
+ i = j.first
+ i.has_key?('author').should be_true
end
end