@story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
end
- it 'オーソドックスなデータなら通る' do
- @story.should be_valid
+ context 'オーソドックスなデータのとき' do
+ it '下限データが通る' do
+ @story.t = 0
+ @story.should be_valid
+ end
+ it '上限データが通る' do
+ @story.t = 99999
+ @story.should be_valid
+ end
end
context 'comic_idを検証するとき' do
- it 'テストデータの確認' do
- @story.comic_id = @comic.id
- @story.should be_valid
- end
it 'nullなら失敗する' do
@story.comic_id = nil
@story.should_not be_valid
end
context 'panel_idを検証するとき' do
- it 'テストデータの確認' do
- @story.panel_id = @panel.id
- @story.should be_valid
- end
it 'nullなら失敗する' do
@story.panel_id = nil
@story.should_not be_valid
end
context 'tを検証するとき' do
- before do
- end
- it 'テストデータの確認' do
- @story.t = 0
- @story.should be_valid
- end
it 'nullなら失敗する' do
@story.t = nil
@story.should_not be_valid
end
context 'author_idを検証するとき' do
- it 'テストデータの確認' do
- @story.author_id = @author.id
- @story.should be_valid
- end
it 'nullなら失敗する' do
@story.author_id = nil
@story.should_not be_valid
end
end
context '全体を検証するとき' do
- before do
- @story = FactoryGirl.create :story, :author_id => @author.id
- end
end
end
end
- describe '作者判定に於いて' do
+ describe '所持判定に於いて' do
before do
@comic = FactoryGirl.create :comic, :author_id => @author.id
@panel = FactoryGirl.create :panel, :author_id => @author.id
it '他人のストーリーならno' do
@storyo.own?(@author).should == false
end
- it '作家が不明ならno' do
- @story.own?(nil).should == false
- end
- end
- describe '編集取得に於いて' do
- before do
- @comic = FactoryGirl.create :comic, :author_id => @author.id
- @panel = FactoryGirl.create :panel, :author_id => @author.id
- @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
- end
- it '指定のストーリーを返す' do
- l = Story.edit @story.id, @author
- l.should eq @story
- end
- context '他人のストーリーを開こうとしたとき' do
- it '403Forbidden例外を返す' do
- Story.any_instance.stub(:own?).and_return(false)
- lambda{
- Story.edit @story.id, @author
- }.should raise_error(ActiveRecord::Forbidden)
- end
- end
- context '存在しないストーリーを開こうとしたとき' do
- it '404RecordNotFound例外を返す' do
- lambda{
- Story.edit 110, @author
- }.should raise_error(ActiveRecord::RecordNotFound)
- end
- end
end
-
describe '一覧取得に於いて' do
before do
@comic = FactoryGirl.create :comic, :author_id => @author.id
@panel = FactoryGirl.create :panel, :author_id => @author.id
@story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
@panel2 = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
+ @other_comic = FactoryGirl.create :comic, :author_id => @other_author.id, :visible => 1
+ @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
end
context 'offset補正について' do
it '文字列から数値に変換される' do
c.should eq [@story]
end
it 't順で並んでいる' do
+ #公開コミックの公開コマは(他人のコミックであっても)含んでいる
v = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1
c = Story.list @comic, @author
c.should eq [ @story, v]
describe '自分のストーリー一覧取得に於いて' do
before do
- @comic = FactoryGirl.create :comic, :author_id => @author.id
- @panel = FactoryGirl.create :panel, :author_id => @author.id
+ @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 0
+ @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
@story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
- end
+ @other_comic = FactoryGirl.create :comic, :author_id => @other_author.id, :visible => 1
+ @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
+ end
+ context 'つつがなく終わるとき' do\r
+ it '一覧取得オプションを利用している' do\r
+ Story.stub(:list_opt).with(any_args).and_return({})\r
+ Story.should_receive(:list_opt).with(any_args).exactly(1)\r
+ r = Story.mylist @author
+ end\r
+ end\r
it 'リストを返す' do
s = Story.mylist @author
s.should eq [@story]
sl = Story.mylist @author
sl.should eq [ns, @story]
end
- it '他人のストーリーは含まない' do
- cc = FactoryGirl.create :comic, :author_id => @other_author.id
- pl = FactoryGirl.create :panel, :author_id => @other_author.id
- so = FactoryGirl.create :story, :author_id => @other_author.id, :comic_id => cc.id, :panel_id => pl.id
+ it '他人のストーリーはコマコミックともに公開でも含まない' do
+ so = FactoryGirl.create :story, :author_id => @other_author.id, :comic_id => @other_comic.id, :panel_id => @other_panel.id
sl = Story.mylist @author
sl.should eq [@story]
end
+ it '自分のストーリーはコマコミックともには非公開でも含んでいる' do
+ nc = FactoryGirl.create :comic, :author_id => @author.id, :visible => 0, :updated_at => Time.now + 100
+ cl = Comic.mylist @author
+ cl.should eq [nc, @story]
+ end
+ context 'DBに5件あって1ページの件数を2件に変えたとして' do
+ before do
+ @story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
+ @story3 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 2, :updated_at => Time.now + 200
+ @story4 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 3, :updated_at => Time.now + 300
+ @story5 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 4, :updated_at => Time.now + 400
+ end
+ it '通常は2件を返す' do
+ c = Story.mylist @author, 1, 2
+ c.should have(2).items
+ end
+ it 'page=1なら末尾2件を返す' do
+ #時系列で並んでいる
+ c = Story.mylist(@author, 1, 2)
+ c.should eq [@story5, @story4]
+ end
+ it 'page=2なら中間2件を返す' do
+ c = Story.mylist(@author, 2, 2)
+ c.should eq [@story3, @story2]
+ end
+ it 'page=3なら先頭1件を返す' do
+ c = Story.mylist(@author, 3, 2)
+ c.should eq [@story]
+ end
+ end
+ context 'DBに5件あって1ページの件数を0件に変えたとして' do
+ before do
+ @story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
+ @story3 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 2, :updated_at => Time.now + 200
+ @story4 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 3, :updated_at => Time.now + 300
+ @story5 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 4, :updated_at => Time.now + 400
+ end
+ it '通常は全件(5件)を返す' do
+ r = Story.mylist @author, 5, 0
+ r.should have(5).items
+ end
+ end
+ end
+
+ describe '編集取得に於いて' do
+ before do
+ @comic = FactoryGirl.create :comic, :author_id => @author.id
+ @panel = FactoryGirl.create :panel, :author_id => @author.id
+ @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
+ end
+ context 'つつがなく終わるとき' do\r
+ it '単体取得オプションを利用している' do\r
+ Story.stub(:show_opt).with(any_args).and_return({})\r
+ Story.should_receive(:show_opt).with(any_args).exactly(1)\r
+ r = Story.edit @story.id, @author
+ end\r
+ it '所持判定を問い合わせている' do\r
+ Story.any_instance.stub(:own?).with(any_args).and_return(true)\r
+ Story.any_instance.should_receive(:own?).with(any_args).exactly(1)\r
+ r = Story.edit @story.id, @author
+ end\r
+ end\r
+ it '指定のストーリーを返す' do
+ l = Story.edit @story.id, @author
+ l.should eq @story
+ end
+ context '他人のストーリーを開こうとしたとき' do
+ it '403Forbidden例外を返す' do
+ Story.any_instance.stub(:own?).and_return(false)
+ lambda{
+ Story.edit @story.id, @author
+ }.should raise_error(ActiveRecord::Forbidden)
+ end
+ end
+ context '存在しないストーリーを開こうとしたとき' do
+ it '404RecordNotFound例外を返す' do
+ lambda{
+ Story.edit 110, @author
+ }.should raise_error(ActiveRecord::RecordNotFound)
+ end
+ end
+ end
+
+ describe '単体取得オプションに於いて' do
+ it 'includeキーを含んでいる' do
+ r = Story.show_opt
+ r.has_key?(:include).should be_true
+ end
+ it '3つの項目を含んでいる' do
+ r = Story.show_opt[:include]
+ r.should have(3).items
+ end
+ it 'コミックを含んでいる' do
+ r = Story.show_opt[:include]
+ r.has_key?(:comic).should be_true
+ end
+ it 'コミックは作家を含んでいる' do
+ r = Story.show_opt[:include]
+ r[:comic].has_key?(:author).should be_true
+ end
+ it '作家を含んでいる' do
+ r = Story.show_opt[:include]
+ r.has_key?(:author).should be_true
+ end
+ it 'コマを含んでいる' do
+ r = Story.show_opt[:include]
+ r.has_key?(:panel).should be_true
+ end
+ it 'コマは作家を含んでいる' do
+ r = Story.show_opt[:include]
+ r[:panel].has_key?(:author).should be_true
+ end
+ it 'コマはコマ絵を含んでいる' do
+ r = Story.show_opt[:include]
+ r[:panel].has_key?(:panel_pictures).should be_true
+ end
+ it 'コマ絵は実素材を含んでいる' do
+ r = Story.show_opt[:include]
+ r[:panel][:panel_pictures].has_key?(:picture).should be_true
+ end
+ it '実素材は絵師を含んでいる' do
+ r = Story.show_opt[:include]
+ r[:panel][:panel_pictures][:picture].has_key?(:artist).should be_true
+ end
+ it '実素材はライセンスを含んでいる' do
+ r = Story.show_opt[:include]
+ r[:panel][:panel_pictures][:picture].has_key?(:license).should be_true
+ end
+ it 'コマはフキダシを含んでいる' do
+ r = Story.show_opt[:include]
+ r[:panel].has_key?(:speech_balloons).should be_true
+ end
+ it 'フキダシはフキダシ枠を含んでいる' do
+ r = Story.show_opt[:include]
+ r[:panel][:speech_balloons].has_key?(:balloons).should be_true
+ end
+ it 'フキダシはセリフを含んでいる' do
+ r = Story.show_opt[:include]
+ r[:panel][:speech_balloons].has_key?(:speeches).should be_true
+ end
+ end
+ describe 'json単体取得オプションに於いて' do
+ it 'includeキーを含んでいる' do
+ r = Story.show_json_opt
+ r.has_key?(:include).should be_true
+ end
+ it '3つの項目を含んでいる' do
+ r = Story.show_json_opt[:include]
+ r.should have(3).items
+ end
+ it 'コミックを含んでいる' do
+ r = Story.show_json_opt[:include]
+ r.has_key?(:comic).should be_true
+ end
+ it 'コミックは作家を含んでいる' do
+ r = Story.show_json_opt[:include]
+ r[:comic].has_key?(:author).should be_true
+ end
+ it '作家を含んでいる' do
+ r = Story.show_json_opt[:include]
+ r.has_key?(:author).should be_true
+ end
+ it 'コマを含んでいる' do
+ r = Story.show_json_opt[:include]
+ r.has_key?(:panel).should be_true
+ end
+ it 'コマは作家を含んでいる' do
+ r = Story.show_json_opt[:include]
+ r[:panel].has_key?(:author).should be_true
+ end
+ it 'コマはコマ絵を含んでいる' do
+ r = Story.show_json_opt[:include]
+ r[:panel].has_key?(:panel_pictures).should be_true
+ end
+ it 'コマ絵は実素材を含んでいる' do
+ r = Story.show_json_opt[:include]
+ r[:panel][:panel_pictures].has_key?(:picture).should be_true
+ end
+ it '実素材は絵師を含んでいる' do
+ r = Story.show_json_opt[:include]
+ r[:panel][:panel_pictures][:picture].has_key?(:artist).should be_true
+ end
+ it '実素材はライセンスを含んでいる' do
+ r = Story.show_json_opt[:include]
+ r[:panel][:panel_pictures][:picture].has_key?(:license).should be_true
+ end
+ it 'コマはフキダシを含んでいる' do
+ r = Story.show_json_opt[:include]
+ r[:panel].has_key?(:speech_balloons).should be_true
+ end
+ it 'フキダシはフキダシ枠を含んでいる' do
+ r = Story.show_json_opt[:include]
+ r[:panel][:speech_balloons].has_key?(:balloons).should be_true
+ end
+ it 'フキダシはセリフを含んでいる' do
+ r = Story.show_json_opt[:include]
+ r[:panel][:speech_balloons].has_key?(:speeches).should be_true
+ end
end
describe 't補充値に於いて' do