#ストーリー
describe Story do
before do
- FactoryGirl.create :admin
+ @admin = FactoryGirl.create :admin
@sp = FactoryGirl.create :system_picture
@lg = FactoryGirl.create :license_group
@license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
+ @color = FactoryGirl.create :color
@user = FactoryGirl.create( :user_yas)
@author = @user.author
@artist = FactoryGirl.create :artist_yas, :author_id => @author.id
@other_user = FactoryGirl.create( :user_yas)
@other_author = @other_user.author
+ @op = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
+ @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
+ @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id\r
+ @sbt = FactoryGirl.create :speech_balloon_template\r
end
describe '検証に於いて' do
@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
+ it 'パラメータが作家でないならno' do
@story.own?(nil).should == false
end
end
- describe '単体取得に於いて' do
- before do
+
+ describe '閲覧許可に於いて' do\r
+ before do\r
@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
-
+ end\r
+ context '検査対象がnil(ゲスト)のとき' do
+ context 'クローズドモードのとき' do
+ before do
+ MagicNumber['run_mode'] = 1
+ end
+ it '不許可を返す。' do\r
+ r = @story.visible?(nil)
+ r.should be_false
+ end\r
+ end\r
+ context 'オープンモードのとき' do
+ before do
+ MagicNumber['run_mode'] = 0
+ end
+ it '公開コミックのストーリーなら許可する' do\r
+ Comic.any_instance.stub(:visible?).with(nil).and_return(true)\r
+ r = @story.visible?(nil)
+ r.should be_true
+ end\r
+ it '非公開コミックのストーリーなら許可しない' do\r
+ Comic.any_instance.stub(:visible?).with(nil).and_return(false)\r
+ r = @story.visible?(nil)
+ r.should be_false
+ end\r
+ end\r
+ end\r
+ context '検査対象が作家のとき' do
+ it '自分のコミックのストーリーなら許可する' do\r
+ Comic.any_instance.stub(:own?).with(@author).and_return(true)\r
+ Comic.any_instance.stub(:visible?).with(@author).and_return(true)\r
+ r = @story.visible?(@author)
+ r.should == true
+ end\r
+ it '他人の非公開コミックのストーリーなら許可しない' do\r
+ Comic.any_instance.stub(:own?).with(@other_author).and_return(false)\r
+ Comic.any_instance.stub(:visible?).with(@other_author).and_return(false)\r
+ r = @story.visible?(@other_author)
+ r.should == false
+ end\r
+ it '他人のコミックのストーリーでも公開なら許可する' do\r
+ Comic.any_instance.stub(:own?).with(@other_author).and_return(false)\r
+ Comic.any_instance.stub(:visible?).with(@other_author).and_return(true)\r
+ r = @story.visible?(@other_author)
+ r.should == true
+ end\r
+ end\r
+ context '検査対象がそれ以外のとき' do
+ it '不許可を返す。' do\r
+ r = @story.visible?(@admin)
+ r.should be_false
+ end\r
+ end\r
+ end\r
+ \r
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
end
end
it 'リストを返す' do
- c = Story.list @comic, @author
+ c = Story.play_list @comic, @author
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 = Story.play_list @comic, @author
c.should eq [ @story, v]
end
- it 'é\9d\9eå\85¬é\96\8bã\81®ã\82³ã\83\9eã\81¯å\90«ã\81¾ã\81ªã\81\84' do
+ it 'é\9d\9eå\85¬é\96\8bã\81®ã\82³ã\83\9eã\81¯å\90«ã\82\93ã\81§ã\81\84ã\82\8b' do
h = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel2.id, :t => 1
- c = Story.list @comic, @author
- c.should eq [ @story]
+ c = Story.play_list @comic, @author
+ c.should eq [ @story, h]
end
context 'DBに5件あって1ページの件数を2件に変えたとして' do
before do
end
it 'offset=0なら末尾2件を返す' do
#時系列で並んでいる
- c = Story.list( @comic, @author, 0, 2)
+ c = Story.play_list( @comic, @author, 0, 2)
c.should eq [@story, @story2]
end
it 'offset=2なら中間2件を返す' do
- c = Story.list(@comic, @author, 2, 2)
+ c = Story.play_list(@comic, @author, 2, 2)
c.should eq [@story3, @story4]
end
it 'offset=4なら先頭1件を返す' do
- c = Story.list(@comic, @author, 4, 2)
+ c = Story.play_list(@comic, @author, 4, 2)
c.should eq [@story5]
end
end
end
end
describe 'json一覧出力オプションに於いて' do
+ end
+
+ describe '自分のストーリー一覧取得に於いて' do
+ before do
+ @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
+ @other_comic = FactoryGirl.create :comic, :author_id => @other_author.id, :visible => 1
+ @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
+ @hcomic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 0
+ @hpanel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
+ 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]
+ end
+ it '時系列で並んでいる' do
+ ns = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
+ sl = Story.mylist @author
+ sl.should eq [ns, @story]
+ end
+ 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
+ hs = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @hcomic.id, :panel_id => @hpanel.id, :updated_at => Time.now + 100
+ sl = Story.mylist @author
+ sl.should eq [hs, @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
+ Author.stub(:default_story_size).and_return(2)\r
+ 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.show @story.id, @author
+ end\r
+ it '閲覧許可を問い合わせている' do\r
+ Story.any_instance.stub(:visible?).with(@author).and_return(true)\r
+ Story.any_instance.should_receive(:visible?).with(@author).exactly(1)\r
+ r = Story.show @story.id, @author
+ end\r
+ end\r
+ it '指定のストーリーを返す' do
+ l = Story.show @story.id, @author
+ l.should eq @story
+ end
+ context '他人のストーリーを開こうとしたとき' do
+ it '403Forbidden例外を返す' do
+ Story.any_instance.stub(:visible?).with(@other_author).and_return(false)
+ lambda{
+ Story.show @story.id, @other_author
+ }.should raise_error(ActiveRecord::Forbidden)
+ end
+ end
+ context '存在しないストーリーを開こうとしたとき' do
+ it '404RecordNotFound例外を返す' do
+ lambda{
+ Story.show 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
+ 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.list_json_opt
+ r = Story.show_opt
r.has_key?(:include).should be_true
end
it '3つの項目を含んでいる' do
- r = Story.list_json_opt[:include]
+ r = Story.show_opt[:include]
r.should have(3).items
end
it 'コミックを含んでいる' do
- r = Story.list_json_opt[:include]
+ r = Story.show_opt[:include]
r.has_key?(:comic).should be_true
end
it 'コミックは作家を含んでいる' do
- r = Story.list_json_opt[:include]
+ r = Story.show_opt[:include]
r[:comic].has_key?(:author).should be_true
end
it '作家を含んでいる' do
- r = Story.list_json_opt[:include]
+ r = Story.show_opt[:include]
r.has_key?(:author).should be_true
end
it 'コマを含んでいる' do
- r = Story.list_json_opt[:include]
+ r = Story.show_opt[:include]
r.has_key?(:panel).should be_true
end
it 'コマは作家を含んでいる' do
- r = Story.list_json_opt[:include]
+ r = Story.show_opt[:include]
r[:panel].has_key?(:author).should be_true
end
it 'コマはコマ絵を含んでいる' do
- r = Story.list_json_opt[:include]
+ r = Story.show_opt[:include]
r[:panel].has_key?(:panel_pictures).should be_true
end
it 'コマ絵は実素材を含んでいる' do
- r = Story.list_json_opt[:include]
+ r = Story.show_opt[:include]
r[:panel][:panel_pictures].has_key?(:picture).should be_true
end
it '実素材は絵師を含んでいる' do
- r = Story.list_json_opt[:include]
+ r = Story.show_opt[:include]
r[:panel][:panel_pictures][:picture].has_key?(:artist).should be_true
end
it '実素材はライセンスを含んでいる' do
- r = Story.list_json_opt[:include]
+ r = Story.show_opt[:include]
r[:panel][:panel_pictures][:picture].has_key?(:license).should be_true
end
it 'コマはフキダシを含んでいる' do
- r = Story.list_json_opt[:include]
+ r = Story.show_opt[:include]
r[:panel].has_key?(:speech_balloons).should be_true
end
it 'フキダシはフキダシ枠を含んでいる' do
- r = Story.list_json_opt[:include]
+ r = Story.show_opt[:include]
r[:panel][:speech_balloons].has_key?(:balloons).should be_true
end
it 'フキダシはセリフを含んでいる' do
- r = Story.list_json_opt[:include]
+ r = Story.show_opt[:include]
r[:panel][:speech_balloons].has_key?(:speeches).should be_true
end
end
+ describe 'json単体取得オプションに於いて' do
+ end
- describe '自分のストーリー一覧取得に於いて' do
- before do
+ describe 'ストーリーのjson出力に於いて' do
+ before do\r
+ #コマを作成しておく。\r
+ @panel = FactoryGirl.create :panel, :author_id => @author.id\r
+ @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height\r
+ @sb = @panel.speech_balloons.create(\r
+ FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)\r
+ )\r
+ @gc = @panel.ground_colors.create(\r
+ FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :color_id => @color.id)\r
+ )\r
+ @gp = @panel.ground_pictures.create(\r
+ FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id)\r
+ )\r
+ @pc = @panel.panel_colors.create(\r
+ FactoryGirl.attributes_for(:panel_color, :panel_id => @panel.id, :code => 0xff0000)\r
+ )\r
+ @panel.reload\r
@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
- s = Story.mylist @author
- s.should eq [@story]
- end
- it '時系列で並んでいる' do
- ns = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1
- 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
- sl = Story.mylist @author
- sl.should eq [@story]
- end
+ end\r
+ context '事前チェックする' do
+ before do\r
+ Panel.any_instance.stub(:elements).and_return('{}')
+ end\r
+ it 'コマ要素のjson出力を依頼している' do\r
+ Panel.any_instance.stub(:visible?).with(any_args).and_return(true)
+ Panel.any_instance.should_receive(:elements).with(any_args).exactly(1)\r
+ r = @story.story_as_json @author
+ end\r
+ end\r
+ it 'json textを返している' do\r
+ r = JSON.parse @story.story_as_json(@author)\r
+ r.is_a?(Hash).should be_true\r
+ end\r
+ it 'comic,author,panel,コマ要素を含んでいる' do\r
+ r = JSON.parse @story.story_as_json(@author)\r
+ r.has_key?('comic').should be_true\r
+ r['comic'].has_key?('author').should be_true\r
+ r.has_key?('author').should be_true\r
+ r.has_key?('panel').should be_true\r
+ r['panel'].has_key?('author').should be_true\r
+ end\r
+ context 'コマ閲覧許可のとき' do
+ before do\r
+ Panel.any_instance.stub(:visible?).with(any_args).and_return(true)
+ end\r
+ it 'コマ要素にコマ要素を追加している' do\r
+ r = JSON.parse @story.story_as_json(@author)\r
+ r['panel'].has_key?('elements').should be_true\r
+ r['panel']['elements'].should_not be_empty\r
+ end\r
+ end\r
+ context 'コマ閲覧不許可のとき' do
+ before do\r
+ Panel.any_instance.stub(:visible?).with(any_args).and_return(false)
+ end\r
+ it 'コマ要素にデータを含ませない' do\r
+ r = JSON.parse @story.story_as_json(@author)\r
+ r['panel'].has_key?('elements').should be_false\r
+ end\r
+ end\r
end
+ describe 'ストーリーリストのjson出力に於いて' do\r
+ before do\r
+ @panel = FactoryGirl.create :panel, :author_id => @author.id\r
+ @comic = FactoryGirl.create :comic, :author_id => @author.id
+ @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
+ Story.any_instance.stub(:story_as_json).with(@author).and_return('{"s": 5}')\r
+ end\r
+ context 'つつがなく終わるとき' do\r
+ it 'ストーリーのjson出力を依頼している' do\r
+ Story.any_instance.should_receive(:story_as_json).with(@author).exactly(1)\r
+ r = Story.list_as_json_text [@story], @author\r
+ end\r
+ end\r
+ it 'json textを返している' do\r
+ r = Story.list_as_json_text [@story], @author\r
+ j = JSON.parse r\r
+ j.is_a?(Array).should be_true\r
+ end\r
+ it 'ストーリーを含んでいる' do\r
+ r = Story.list_as_json_text [@story], @author\r
+ j = JSON.parse r
+ j.first.has_key?('s').should be_true\r
+ end\r
+ end
+ \r
describe 't補充値に於いて' do
before do
@comic = FactoryGirl.create :comic, :author_id => @author.id