#ストーリー
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
+ @author = FactoryGirl.create :author, :user_id => @user.id
@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
+ @other_author = FactoryGirl.create :author, :user_id => @other_user.id
+ @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
end
describe '検証に於いて' do
@panelo = FactoryGirl.create :panel, :author_id => @other_author.id
@storyo = FactoryGirl.create :story, :author_id => @other_author.id, :comic_id => @comico.id, :panel_id => @panelo.id
end
- it '自分のストーリーならyes' do
- @story.own?(@author).should == true
+ context '事前チェックする' do
+ it '自身にロールリストからの作家取得を依頼している' do
+ Story.should_receive(:get_author_from_roles).with(any_args).exactly(1)
+ r = @story.own?([@author])
+ end
+ end
+ context 'ロール内作家が取得できるとき' do
+ before do
+ end
+ it 'ロール内作家のidが自身の作家idと一致するなら許可する' do
+ Story.stub(:get_author_from_roles).with(any_args).and_return(@author)
+ r = @story.own?([@author])
+ r.should be_true
+ end
+ it 'ロール内作家のidが自身の作家idと一致しないならno' do
+ Story.stub(:get_author_from_roles).with(any_args).and_return(@other_author)
+ @story.own?(@other_author).should be_false
+ end
end
- it '他人のストーリーならno' do
- @storyo.own?(@author).should == false
+ context 'ロール内作家が取得できないとき' do
+ before do
+ Story.stub(:get_author_from_roles).with(any_args).and_return(nil)
+ end
+ it 'Falseを返す' do
+ r = @story.own?([@author])
+ r.should be_false
+ 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
+ @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
+ end
+ context 'オープンモードのとき' do
+ before do
+ MagicNumber['run_mode'] = 0
+ end
+ it '自身にゲスト用ロールチェックを問い合わせしている' do
+ Story.any_instance.stub(:guest_role_check).and_return(true)
+ Story.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
+ r = @story.visible?([@author])
+ end
+ it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
+ Story.any_instance.stub(:guest_role_check).and_return(false)
+ r = @story.visible?([@author])
+ r.should be_false
+ end
+ end
+ context 'クローズドモードのとき' do
+ before do
+ MagicNumber['run_mode'] = 1
+ end
+ it '自身に読者用ロールチェックを問い合わせしている' do
+ Story.any_instance.stub(:reader_role_check).and_return(true)
+ Story.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
+ r = @story.visible?([@author])
+ end
+ it '読者用ロールチェックが失敗したとき、falseを返す' do
+ Story.any_instance.stub(:reader_role_check).and_return(false)
+ r = @story.visible?([@author])
+ r.should be_false
+ end
+ end
+ context '事前チェックする' do
+ before do
+ MagicNumber['run_mode'] = 1
+ Story.any_instance.stub(:reader_role_check).and_return(true)
+ end
+ it '自身のコミックに所持判定を問い合わせしている' do
+ Comic.any_instance.stub(:own?).and_return(true)
+ Comic.any_instance.should_receive(:own?).with(any_args).exactly(1)
+ r = @story.visible?([@author])
+ end
+ it '自身のコミックに閲覧許可を問い合わせしている' do
+ Comic.any_instance.stub(:own?).and_return(false)
+ Comic.any_instance.stub(:visible?).and_return(true)
+ Comic.any_instance.should_receive(:visible?).with(any_args).exactly(1)
+ r = @story.visible?([@author])
+ end
+ end
+ context 'つつがなく終わるとき' do
+ before do
+ MagicNumber['run_mode'] = 1
+ Story.any_instance.stub(:reader_role_check).and_return(true)
+ end
+ it '自分のコミックのストーリーなら許可する' do
+ Comic.any_instance.stub(:own?).and_return(true)
+ Comic.any_instance.stub(:visible).and_return(0)
+ r = @story.visible?([@author])
+ r.should be_true
+ end
+ it '他人の非公開コミックのストーリーなら許可しない' do
+ Comic.any_instance.stub(:own?).and_return(false)
+ Comic.any_instance.stub(:visible).and_return(0)
+ r = @story.visible?([@author])
+ r.should be_false
+ end
+ it '他人のコミックのストーリーでも公開なら許可する' do
+ Comic.any_instance.stub(:own?).and_return(false)
+ Comic.any_instance.stub(:visible).and_return(1)
+ r = @story.visible?([@author])
+ r.should be_true
+ end
+ end
+ end
+
+ describe 'プレイリスト取得に於いて' do
before do
@comic = FactoryGirl.create :comic, :author_id => @author.id
@panel = FactoryGirl.create :panel, :author_id => @author.id
end
end
end
- describe 'list関連テーブルプションに於いて' do
- it 'includeキーを含んでいる' do
- r = Story.list_opt
- r.has_key?(:include).should be_true
- end
- it '3つの項目を含んでいる' do
- r = Story.list_opt[:include]
- r.should have(3).items
+
+ describe '一覧取得に於いて' do
+ before do
+ @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
+ @panel = FactoryGirl.create :panel, :author_id => @author.id
+ @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
+ @hidden_comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 0
end
- it 'コミックを含んでいる' do
- r = Story.list_opt[:include]
- r.has_key?(:comic).should be_true
+ context 'page補正について' do
+ it '文字列から数値に変換される' do
+ Story.page('8').should eq 8
+ end
+ it 'nilの場合は1になる' do
+ Story.page().should eq 1
+ end
+ it '0以下の場合は1になる' do
+ Story.page('0').should eq 1
+ end
end
- it 'コミックは作家を含んでいる' do
- r = Story.list_opt[:include]
- r[:comic].has_key?(:author).should be_true
+ context 'page_size補正について' do
+ it '文字列から数値に変換される' do
+ Story.page_size('7').should eq 7
+ end
+ it 'nilの場合はStory.default_page_sizeになる' do
+ Story.page_size().should eq Story.default_page_size
+ end
+ it '0以下の場合はStory.default_page_sizeになる' do
+ Story.page_size('0').should eq Story.default_page_size
+ end
+ it 'Story.max_page_sizeを超えた場合はStory.max_page_sizeになる' do
+ Story.page_size('1000').should eq Story.max_page_size
end
- it '作家を含んでいる' do
- r = Story.list_opt[:include]
- r.has_key?(:author).should be_true
end
- it 'ã\82³ã\83\9eã\82\92å\90«ã\82\93ã\81§ã\81\84ã\82\8b' do
- r = Story.list_opt[:include]
- r.has_key?(:panel).should be_true
+ it 'ã\83ªã\82¹ã\83\88ã\82\92è¿\94ã\81\99' do
+ c = Story.list
+ c.should eq [@story]
end
- it 'コマは作家を含んでいる' do
- r = Story.list_opt[:include]
- r[:panel].has_key?(:author).should be_true
+ it '時系列で並んでいる' do
+ #公開コミックのStoryは(他人のStoryであっても)含んでいる
+ v = FactoryGirl.create :story, :author_id => @other_author.id, :comic_id => @other_comic.id, :panel_id => @other_panel.id, :t => 0, :updated_at => Time.now + 100
+ c = Story.list
+ c.should eq [ v, @story]
+ end
+ it '非公開のストーリーは(自分のストーリーであっても)含まない' do
+ h = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @hidden_comic.id, :panel_id => @panel.id, :t => 0
+ c = Story.list
+ c.should eq [ @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 'コマはコマ絵を含んでいる' do
- r = Story.list_opt[:include]
- r[:panel].has_key?(:panel_pictures).should be_true
+ it '通常は2件を返す' do
+ l = Story.list 1, 2
+ l.should have(2).items
end
- it 'コマ絵は実素材を含んでいる' do
- r = Story.list_opt[:include]
- r[:panel][:panel_pictures].has_key?(:picture).should be_true
- end
- it '実素材は絵師を含んでいる' do
- r = Story.list_opt[:include]
- r[:panel][:panel_pictures][:picture].has_key?(:artist).should be_true
- end
- it '実素材はライセンスを含んでいる' do
- r = Story.list_opt[:include]
- r[:panel][:panel_pictures][:picture].has_key?(:license).should be_true
- end
- it 'コマはフキダシを含んでいる' do
- r = Story.list_opt[:include]
- r[:panel].has_key?(:speech_balloons).should be_true
+ it 'page=1なら末尾2件を返す' do
+ #時系列で並んでいる
+ l = Story.list 1, 2
+ l.should eq [@story5, @story4]
end
- it 'フキダシはフキダシ枠を含んでいる' do
- r = Story.list_opt[:include]
- r[:panel][:speech_balloons].has_key?(:balloons).should be_true
- end
- it 'フキダシはセリフを含んでいる' do
- r = Story.list_opt[:include]
- r[:panel][:speech_balloons].has_key?(:speeches).should be_true
- end
- end
- describe 'json一覧出力オプションに於いて' do
+ it 'page=2なら中間2件を返す' do
+ l = Story.list 2, 2
+ l.should eq [@story3, @story2]
+ end
+ it 'page=3なら先頭1件を返す' do
+ l = Story.list 3, 2
+ l.should eq [@story]
+ end
+ end
end
describe '自分のストーリー一覧取得に於いて' do
@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
+ context 'つつがなく終わるとき' do
+ it '一覧取得オプションを利用している' do
+ Story.stub(:list_opt).with(any_args).and_return({})
+ Story.should_receive(:list_opt).with(any_args).exactly(1)
r = Story.mylist @author
- end\r
- end\r
+ end
+ end
it 'リストを返す' do
s = Story.mylist @author
s.should eq [@story]
@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
+ Story.stub(:default_page_size).and_return(2)
end
it '通常は2件を返す' do
- c = Story.mylist @author, 1, 2
- c.should have(2).items
+ l = Story.mylist @author, 1, 2
+ l.should have(2).items
end
it 'page=1なら末尾2件を返す' do
#時系列で並んでいる
- c = Story.mylist(@author, 1, 2)
- c.should eq [@story5, @story4]
+ l = Story.mylist @author, 1, 2
+ l.should eq [@story5, @story4]
end
it 'page=2なら中間2件を返す' do
- c = Story.mylist(@author, 2, 2)
- c.should eq [@story3, @story2]
+ l = Story.mylist @author, 2, 2
+ l.should eq [@story3, @story2]
end
it 'page=3なら先頭1件を返す' do
- c = Story.mylist(@author, 3, 2)
- c.should eq [@story]
+ l = Story.mylist @author, 3, 2
+ l.should eq [@story]
end
end
- context 'DBに5件あって1ページの件数を0件に変えたとして' 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
+ @other_story = FactoryGirl.create :story, :author_id => @other_author.id, :comic_id => @other_comic.id, :panel_id => @other_panel.id
+ end
+ it 'リストを返す' do
+ r = Story.himlist @other_author
+ r.should eq [@other_story]
+ end
+ it '時系列で並んでいる' do
+ ns = FactoryGirl.create :story, :author_id => @other_author.id, :comic_id => @other_comic.id, :panel_id => @other_panel.id, :t => 1, :updated_at => Time.now + 100
+ r = Story.himlist @other_author
+ r.should eq [ns, @other_story]
+ end
+ it '公開コミックのストーリー' do
+ @hcomic = FactoryGirl.create :comic, :author_id => @other_author.id, :visible => 0
+ ns = FactoryGirl.create :story, :author_id => @other_author.id, :comic_id => @hcomic.id, :panel_id => @other_panel.id, :t => 1, :updated_at => Time.now + 100
+ r = Story.himlist @other_author
+ r.should eq [@other_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
- Author.stub(:default_story_size).and_return(2)\r
+ @other_story2 = FactoryGirl.create :story, :author_id => @other_author.id, :comic_id => @other_comic.id, :panel_id => @other_panel.id, :t => 1, :updated_at => Time.now + 100
+ @other_story3 = FactoryGirl.create :story, :author_id => @other_author.id, :comic_id => @other_comic.id, :panel_id => @other_panel.id, :t => 2, :updated_at => Time.now + 200
+ @other_story4 = FactoryGirl.create :story, :author_id => @other_author.id, :comic_id => @other_comic.id, :panel_id => @other_panel.id, :t => 3, :updated_at => Time.now + 300
+ @other_story5 = FactoryGirl.create :story, :author_id => @other_author.id, :comic_id => @other_comic.id, :panel_id => @other_panel.id, :t => 4, :updated_at => Time.now + 400
+ Story.stub(:default_page_size).and_return(2)
+ end
+ it '通常は2件を返す' do
+ l = Story.himlist @other_author, 1, 2
+ l.should have(2).items
+ end
+ it 'page=1なら末尾2件を返す' do
+ #時系列で並んでいる
+ l = Story.himlist @other_author, 1, 2
+ l.should eq [@other_story5, @other_story4]
+ end
+ it 'page=2なら中間2件を返す' do
+ l = Story.himlist @other_author, 2, 2
+ l.should eq [@other_story3, @other_story2]
+ end
+ it 'page=3なら先頭1件を返す' do
+ l = Story.himlist @other_author, 3, 2
+ l.should eq [@other_story]
+ end
+ end
+ end
+
+ describe 'ストーリー一覧ページ制御に於いて' do
+ before do
+ Story.stub(:count).with(any_args).and_return(100)
+ end
+ it 'ページ制御を返す' do
+ r = Story.list_paginate
+ r.is_a?(Kaminari::PaginatableArray).should be_true
+ end
+ it 'ストーリー一覧の取得条件を利用している' do
+ Story.stub(:list_where).with(any_args).and_return('')
+ Story.should_receive(:list_where).with(any_args).exactly(1)
+ r = Story.list_paginate
+ end
+ it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
+ r = Story.list_paginate 3, 10
+ r.limit_value.should eq 10
+ r.offset_value.should eq 20
+ end
+ end
+
+ describe '自分のストーリー一覧ページ制御に於いて' do
+ before do
+ Story.stub(:count).with(any_args).and_return(100)
+ end
+ it 'ページ制御を返す' do
+ r = Story.mylist_paginate @author
+ r.is_a?(Kaminari::PaginatableArray).should be_true
+ end
+ it '自分のストーリー一覧の取得条件を利用している' do
+ Story.stub(:mylist_where).with(any_args).and_return('')
+ Story.should_receive(:mylist_where).with(any_args).exactly(1)
+ r = Story.mylist_paginate @author
+ end
+ it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
+ r = Story.mylist_paginate @author, 3, 10
+ r.limit_value.should eq 10
+ r.offset_value.should eq 20
+ end
+ end
+
+ describe '他作家のストーリー一覧ページ制御に於いて' do
+ before do
+ Story.stub(:count).with(any_args).and_return(100)
+ end
+ it 'ページ制御を返す' do
+ r = Story.himlist_paginate @other_author
+ r.is_a?(Kaminari::PaginatableArray).should be_true
+ end
+ it '他作家のストーリー一覧の取得条件を利用している' do
+ Story.stub(:himlist_where).with(any_args).and_return('')
+ Story.should_receive(:himlist_where).with(any_args).exactly(1)
+ r = Story.himlist_paginate @other_author
+ end
+ it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
+ r = Story.himlist_paginate @other_author, 3, 10
+ r.limit_value.should eq 10
+ r.offset_value.should eq 20
+ end
+ end
+
+ describe 'list関連テーブルプションに於いて' do
+ it '3つの項目を含んでいる' do
+ r = Story.list_opt
+ r.should have(3).items
+ end
+ it 'コミックを含んでいる' do
+ r = Story.list_opt
+ r.has_key?(:comic).should be_true
+ end
+ it 'コミックは作家を含んでいる' do
+ r = Story.list_opt
+ r[:comic].has_key?(:author).should be_true
+ end
+ it '作家を含んでいる' do
+ r = Story.list_opt
+ r.has_key?(:author).should be_true
+ end
+ it 'コマを含んでいる' do
+ r = Story.list_opt
+ r.has_key?(:panel).should be_true
+ end
+ it 'コマは作家を含んでいる' do
+ r = Story.list_opt
+ r[:panel].has_key?(:author).should be_true
+ end
+ it 'コマはコマ絵を含んでいる' do
+ r = Story.list_opt
+ r[:panel].has_key?(:panel_pictures).should be_true
+ end
+ it 'コマ絵は実素材を含んでいる' do
+ r = Story.list_opt
+ r[:panel][:panel_pictures].has_key?(:picture).should be_true
+ end
+ it '実素材は絵師を含んでいる' do
+ r = Story.list_opt
+ r[:panel][:panel_pictures][:picture].has_key?(:artist).should be_true
+ end
+ it '実素材はライセンスを含んでいる' do
+ r = Story.list_opt
+ r[:panel][:panel_pictures][:picture].has_key?(:license).should be_true
+ end
+ it 'コマはフキダシを含んでいる' do
+ r = Story.list_opt
+ r[:panel].has_key?(:speech_balloons).should be_true
+ end
+ it 'フキダシはフキダシ枠を含んでいる' do
+ r = Story.list_opt
+ r[:panel][:speech_balloons].has_key?(:balloons).should be_true
+ end
+ it 'フキダシはセリフを含んでいる' do
+ r = Story.list_opt
+ r[:panel][:speech_balloons].has_key?(:speeches).should be_true
+ end
+ end
+ describe 'json一覧出力オプションに於いて' do
+ 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
+ it '単体取得オプションを利用している' do
+ Story.stub(:show_opt).with(any_args).and_return({})
+ Story.should_receive(:show_opt).with(any_args).exactly(1)
+ r = Story.show @story.id, @author
+ end
+ it '閲覧許可を問い合わせている' do
+ Story.any_instance.stub(:visible?).with(@author).and_return(true)
+ Story.any_instance.should_receive(:visible?).with(@author).exactly(1)
+ r = Story.show @story.id, @author
+ end
+ end
+ 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
- it '通常は全件(5件)を返す' do
- r = Story.mylist @author, 5, 0
- r.should have(5).items
+ end
+ context '存在しないストーリーを開こうとしたとき' do
+ it '404RecordNotFound例外を返す' do
+ lambda{
+ Story.show 110, @author
+ }.should raise_error(ActiveRecord::RecordNotFound)
end
end
end
@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
+ context 'つつがなく終わるとき' do
+ it '単体取得オプションを利用している' do
+ Story.stub(:show_opt).with(any_args).and_return({})
+ Story.should_receive(:show_opt).with(any_args).exactly(1)
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
+ end
+ it '所持判定を問い合わせている' do
+ Story.any_instance.stub(:own?).with(any_args).and_return(true)
+ Story.any_instance.should_receive(:own?).with(any_args).exactly(1)
r = Story.edit @story.id, @author
- end\r
- end\r
+ end
+ end
it '指定のストーリーを返す' do
l = Story.edit @story.id, @author
l.should eq @story
end
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
+ before do
+ #コマを作成しておく。
+ @panel = FactoryGirl.create :panel, :author_id => @author.id
+ @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height
+ @sb = @panel.speech_balloons.create(
+ FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
+ )
+ @gc = @panel.ground_colors.create(
+ FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id)
+ )
+ @gp = @panel.ground_pictures.create(
+ FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id)
+ )
+ @panel.reload
@comic = FactoryGirl.create :comic, :author_id => @author.id
@story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
- end\r
+ end
context '事前チェックする' do
- before do\r
+ before do
Panel.any_instance.stub(:elements).and_return('{}')
- end\r
- it 'コマ要素のjson出力を依頼している' do\r
+ end
+ it 'コマ要素のjson出力を依頼している' do
Panel.any_instance.stub(:visible?).with(any_args).and_return(true)
- Panel.any_instance.should_receive(:elements).with(any_args).exactly(1)\r
+ Panel.any_instance.should_receive(:elements).with(any_args).exactly(1)
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
+ end
+ end
+ it 'json textを返している' do
+ r = JSON.parse @story.story_as_json(@author)
+ r.is_a?(Hash).should be_true
+ end
+ it 'comic,author,panel,コマ要素を含んでいる' do
+ r = JSON.parse @story.story_as_json(@author)
+ r.has_key?('comic').should be_true
+ r['comic'].has_key?('author').should be_true
+ r.has_key?('author').should be_true
+ r.has_key?('panel').should be_true
+ r['panel'].has_key?('author').should be_true
+ end
context 'コマ閲覧許可のとき' do
- before do\r
+ before do
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
+ end
+ it 'コマ要素にコマ要素を追加している' do
+ r = JSON.parse @story.story_as_json(@author)
+ r['panel'].has_key?('elements').should be_true
+ r['panel']['elements'].should_not be_empty
+ end
+ end
context 'コマ閲覧不許可のとき' do
- before do\r
+ before do
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
+ it 'コマ要素にデータを含ませない' do
+ r = JSON.parse @story.story_as_json(@author)
+ r['panel'].has_key?('elements').should be_false
+ end
+ end
end
- describe 'ストーリーリストのjson出力に於いて' do\r
- before do\r
- @panel = FactoryGirl.create :panel, :author_id => @author.id\r
+ describe 'ストーリーリストのjson出力に於いて' do
+ before do
+ @panel = FactoryGirl.create :panel, :author_id => @author.id
@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
+ Story.any_instance.stub(:story_as_json).with(@author).and_return('{"s": 5}')
+ end
+ context 'つつがなく終わるとき' do
+ it 'ストーリーのjson出力を依頼している' do
+ Story.any_instance.should_receive(:story_as_json).with(@author).exactly(1)
+ r = Story.list_as_json_text [@story], @author
+ end
+ end
+ it 'json textを返している' do
+ r = Story.list_as_json_text [@story], @author
j = JSON.parse r
- j.first.has_key?('s').should be_true\r
- end\r
+ j.is_a?(Array).should be_true
+ end
+ it 'ストーリーを含んでいる' do
+ r = Story.list_as_json_text [@story], @author
+ j = JSON.parse r
+ j.first.has_key?('s').should be_true
+ end
end
- \r
+
+ describe 'ライセンス素材に於いて' do
+ before do
+ #コマを作成しておく。
+ @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id
+ @p2 = FactoryGirl.create :picture, :original_picture_id => @op2.id, :license_id => @license.id, :artist_id => @artist.id
+ @rp2 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op2.id, :picture_id => @p2.id
+ @panel = FactoryGirl.create :panel, :author_id => @author.id
+ @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 0, :width => @p.width, :height => @p.height, :picture_id => @p.id
+ @panel.reload
+ @panel2 = FactoryGirl.create :panel, :author_id => @author.id
+ @pp2= FactoryGirl.create :panel_picture, :panel_id => @panel2.id, :t => 0, :width => @p2.width, :height => @p2.height, :picture_id => @p2.id
+ @panel2.reload
+
+ @comic = FactoryGirl.create :comic, :author_id => @author.id
+ @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
+ @story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel2.id
+ end
+ context '事前チェック' do
+ end
+ context 'つつがなく終わるとき' do
+ end
+ it '連想配列(値は実素材、キーは実素材id)を返している' do
+ r = Story.licensed_pictures [@story, @story2]
+ r.is_a?(Hash).should be_true
+ r.should have(2).items
+ r[@pp.picture_id].should eq @p
+ r[@pp2.picture_id].should eq @p2
+ end
+ context 'コマが削除されているときき' do
+ before do
+ @panel2.destroy
+ end
+ it '削除されているコマは無視する' do
+ r = Story.licensed_pictures [@story, @story2]
+ r.is_a?(Hash).should be_true
+ r.should have(1).items
+ r[@pp.picture_id].should eq @p
+ r[@pp2.picture_id].should be_nil
+ end
+ end
+ end
+
describe 't補充値に於いて' do
before do
@comic = FactoryGirl.create :comic, :author_id => @author.id
end
context 'コミックで引っかかるとき' do
it 'falseを返す' do
- @story.comic_id = nil
+ Panel.any_instance.stub(:usable?).with(any_args).and_return(true)
+ Comic.any_instance.stub(:own?).with(any_args).and_return(false)
r = @story.allow?
r.should be_false
end
+ end
+ context 'コマで引っかかるとき' do
it 'falseを返す' do
- Comic.any_instance.stub(:own?).with(any_args).and_return(false)
+ Comic.any_instance.stub(:own?).with(any_args).and_return(true)
+ Panel.any_instance.stub(:usable?).with(any_args).and_return(false)
r = @story.allow?
r.should be_false
end
end
- context 'コマで引っかかるとき' do
- it 'falseを返す' do
+ context 'コミックまたはコマが指定されていなかったとき' do
+ it 'nilを返す' do
+ Comic.any_instance.stub(:own?).with(any_args).and_return(true)
@story.panel_id = nil
r = @story.allow?
- r.should be_false
+ r.should eq nil
end
- it 'falseを返す' do
- Panel.any_instance.stub(:usable?).with(any_args).and_return(false)
+ it 'nilを返す' do
+ Panel.any_instance.stub(:usable?).with(any_args).and_return(true)
+ @story.comic_id = nil
r = @story.allow?
- r.should be_false
+ r.should eq nil
end
end
end
@story.destroy_and_shorten
}.should change(Story, :count ).by(-1)
end
+ it 'Trueを返す' do
+ r = @story.destroy_and_shorten
+ r.should be_true
+ end
+ end
+ context '削除に失敗したとき' do
+ before do
+ Story.any_instance.stub(:destroy).and_return(false)
+ end
+ it 'ロールバックされる' do
+ lambda{
+ @story.destroy_and_shorten
+ }.should_not change(Story, :count )
+ end
+ it 'Falseを返す' do
+ r = @story.destroy_and_shorten
+ r.should be_false
+ end
end
#連携テスト。切り詰めが直接DBをいじる
context '2件で先頭を削除したとき' do