# -*- encoding: utf-8 -*-
require 'spec_helper'
#ストーリー
+
describe Story do
before do
@admin = FactoryGirl.create :admin
+ @demand_user = FactoryGirl.create :demand_user
@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 = FactoryGirl.create :author, :user_id => @user.id
@artist = FactoryGirl.create :artist_yas, :author_id => @author.id
@other_user = FactoryGirl.create( :user_yas)
@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
+ @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
end
describe '検証に於いて' do
before do
@comic = FactoryGirl.create :comic, :author_id => @author.id
- @panel = FactoryGirl.create :panel, :author_id => @author.id
- @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+ @story = FactoryGirl.build :story, :comic_id => @comic.id
end
context 'オーソドックスなデータのとき' do
it '下限データが通る' do
+ @story.title = 'a'
+ @story.visible = 0
@story.t = 0
@story.should be_valid
end
it '上限データが通る' do
+ @story.title = 'a'*100
+ @story.visible = 1
@story.t = 99999
@story.should be_valid
end
end
end
- context 'panel_idを検証するとき' do
+ context 'titleを検証するとき' do
it 'nullなら失敗する' do
- @story.panel_id = nil
+ @story.title = nil
@story.should_not be_valid
end
- it '数値でなければ失敗する' do
- @story.panel_id = 'a'
- @story.should_not be_valid
- end
- it '存在するコマでなければ失敗する' do
- @story.panel_id = 0
+ it '100文字以上なら失敗する' do
+ @story.title = 'a'*101
@story.should_not be_valid
end
end
- context 'tを検証するとき' do
+ context 'visibleを検証するとき' do
it 'nullなら失敗する' do
- @story.t = nil
+ @story.visible = nil
@story.should_not be_valid
end
- it '数値でなければ失敗する' do
- @story.t = 'a'
+ it '負なら失敗する' do
+ @story.visible = -1
@story.should_not be_valid
end
- it '負なら失敗する' do
- @story.t = -1
+ it '2以上なら失敗する' do
+ @story.visible = 2
@story.should_not be_valid
end
end
- context 'author_idを検証するとき' do
+ context 'tを検証するとき' do
it 'nullなら失敗する' do
- @story.author_id = nil
+ @story.t = nil
@story.should_not be_valid
end
it '数値でなければ失敗する' do
- @story.author_id = 'a'
+ @story.t = 'a'
@story.should_not be_valid
end
- it '存在する作家でなければ失敗する' do
- @story.author_id = 0
+ it '負なら失敗する' do
+ @story.t = -1
@story.should_not be_valid
end
end
- context '全体を検証するとき' do
- 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.build :story, :comic_id => @comic.id
end
- #dbのデフォルト値が0だから明示的にnilにしないと追加ができない
- it 'tをnilにする' do
- @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id
- @story.supply_default
- @story.t.should be_nil
+ context 'titleを検証するとき' do
+ it 'Shift JISなら失敗する' do
+ @story.title = "\x83G\x83r\x83]\x83D"
+ lambda{
+ @story.valid_encode
+ }.should raise_error(Pettanr::BadRequest)
+ end
end
+ context 'descriptionを検証するとき' do
+ it 'Shift JISなら失敗する' do
+ @story.description = "\x83G\x83r\x83]\x83D"
+ lambda{
+ @story.valid_encode
+ }.should raise_error(Pettanr::BadRequest)
+ end
+ end
end
- describe '上書き補充に於いて' do
- before do
- @comic = FactoryGirl.create :comic, :author_id => @author.id
- @panel = FactoryGirl.create :panel, :author_id => @author.id
- end
-
- context 'author_idを補充' do
- it '問答無用でauthor_idを補充する' do
- @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id
- @story.author_id = nil
- @story.overwrite @author
- @story.author_id.should eq @author.id
- end
+ describe 'デフォルト値補充に於いて' do
+ it 'visibleが0になっている' do
+ @story = FactoryGirl.build :story, :visible => nil
+ @story.supply_default
+ @story.visible.should eq 0
end
-
+ end
+
+ describe '上書き補充に於いて' 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
- @comico = FactoryGirl.create :comic, :author_id => @other_author.id
- @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
+ @story = FactoryGirl.build :story, :comic_id => @comic.id
end
context '事前チェックする' do
it '自身にロールリストからの作家取得を依頼している' do
context 'ロール内作家が取得できるとき' do
before do
end
- it 'ロール内作家のidが自身の作家idと一致するなら許可する' do
+ 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
+ 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
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
+ @story = FactoryGirl.build :story, :comic_id => @comic.id
end
context 'オープンモードのとき' do
before do
before do
MagicNumber['run_mode'] = 1
Story.any_instance.stub(:reader_role_check).and_return(true)
+ Story.any_instance.stub(:own?).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)
+ it '自身に所持判定を問い合わせしている' do
+ Story.any_instance.should_receive(:own?).with(any_args).exactly(1)
r = @story.visible?([@author])
end
end
MagicNumber['run_mode'] = 1
Story.any_instance.stub(:reader_role_check).and_return(true)
end
- it 'è\87ªå\88\86ã\81®ã\82³ã\83\9fã\83\83ã\82¯ã\81®ã\82¹ã\83\88ã\83¼ã\83ªã\83¼ã\81ªã\82\89許å\8f¯ã\81\99ã\82\8b' do
- Comic.any_instance.stub(:own?).and_return(true)
- Comic.any_instance.stub(:visible).and_return(0)
+ it '自分のストーリーなら許可する' do
+ Story.any_instance.stub(:own?).and_return(true)
+ Story.any_instance.stub(:visible).and_return(0)
r = @story.visible?([@author])
r.should be_true
end
- it 'ä»\96人ã\81®é\9d\9eå\85¬é\96\8bã\82³ã\83\9fã\83\83ã\82¯ã\81®ã\82¹ã\83\88ã\83¼ã\83ªã\83¼ã\81ªã\82\89許å\8f¯ã\81\97ã\81ªã\81\84' do
- Comic.any_instance.stub(:own?).and_return(false)
- Comic.any_instance.stub(:visible).and_return(0)
+ it '他人の非公開ストーリーなら許可しない' do
+ Story.any_instance.stub(:own?).and_return(false)
+ Story.any_instance.stub(:visible).and_return(0)
r = @story.visible?([@author])
r.should be_false
end
- it 'ä»\96人ã\81®ã\82³ã\83\9fã\83\83ã\82¯ã\81®ã\82¹ã\83\88ã\83¼ã\83ªã\83¼ã\81§ã\82\82å\85¬é\96\8bã\81ªã\82\89許å\8f¯ã\81\99ã\82\8b' do
- Comic.any_instance.stub(:own?).and_return(false)
- Comic.any_instance.stub(:visible).and_return(1)
+ it '他人のストーリーでも公開なら許可する' do
+ Story.any_instance.stub(:own?).and_return(false)
+ Story.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
- @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
- Story.offset(100, '8').should eq 8
- end
- it 'nilの場合は0になる' do
- Story.offset(100).should eq 0
- end
- #投稿されたコマ数以上の値が指定されたときは、最後のコマだけになる
- #最後のコマとは、コマ数‐1.
- it '1件のときオフセット1なら0になる' do
- Story.offset(1, '1').should eq 0
- end
- it '5件のときオフセット5なら4になる' do
- Story.offset(5, '5').should eq 4
- end
- # 負の値が指定されたときは、最後のコマから数えてコマを飛ばして表示する。
- #-4のときは、最後から4つのコマを表示する。
- it '2件のときオフセット-1なら1になる' do
- Story.offset(2, '-1').should eq 1
- end
- it '5件のときオフセット-2なら3になる' do
- Story.offset(5, '-2').should eq 3
- end
- # 最終的なが負になるなど、不正な値が入ったときは0となる。
- it '2件のときオフセット-5なら0になる' do
- Story.offset(2, '-5').should eq 0
- end
- end
- context 'panel_count補正について' do
- it '文字列から数値に変換される' do
- Story.panel_count(100, '7').should eq 7
- end
- it 'nilの場合はStory.default_panel_sizeになる' do
- Story.panel_count(100).should eq Story.default_panel_size
- end
- it '0以下の場合はStory.default_panel_sizeになる' do
- Story.panel_count(100, '0').should eq Story.default_panel_size
- end
- it 'Story.max_panel_sizeを超えた場合はStory.max_panel_sizeになる' do
- Story.panel_count(100, '1000').should eq Story.max_panel_size
- end
- end
- it 'リストを返す' do
- 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.play_list @comic, @author
- c.should eq [ @story, v]
- end
- it '非公開のコマは含んでいる' do
- h = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel2.id, :t => 1
- c = Story.play_list @comic, @author
- c.should eq [ @story, h]
- 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
- @story3 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 2
- @story4 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 3
- @story5 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 4
- end
- it 'offset=0なら末尾2件を返す' do
- #時系列で並んでいる
- c = Story.play_list( @comic, @author, 0, 2)
- c.should eq [@story, @story2]
- end
- it 'offset=2なら中間2件を返す' do
- c = Story.play_list(@comic, @author, 2, 2)
- c.should eq [@story3, @story4]
- end
- it 'offset=4なら先頭1件を返す' do
- c = Story.play_list(@comic, @author, 4, 2)
- c.should eq [@story5]
- 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
- end
- it 'コミックを含んでいる' do
- r = Story.list_opt[:include]
- r.has_key?(:comic).should be_true
- end
- it 'コミックは作家を含んでいる' do
- r = Story.list_opt[:include]
- r[:comic].has_key?(:author).should be_true
- end
- it '作家を含んでいる' do
- r = Story.list_opt[:include]
- r.has_key?(:author).should be_true
- end
- it 'コマを含んでいる' do
- r = Story.list_opt[:include]
- r.has_key?(:panel).should be_true
- end
- it 'コマは作家を含んでいる' do
- r = Story.list_opt[:include]
- r[:panel].has_key?(:author).should be_true
- end
- it 'コマはコマ絵を含んでいる' do
- r = Story.list_opt[:include]
- r[:panel].has_key?(:panel_pictures).should be_true
- 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
- 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
- end
-
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
+ @comic = FactoryGirl.create :comic, :author_id => @author.id
+ @story = FactoryGirl.create :story, :comic_id => @comic.id
end
context 'page補正について' do
it '文字列から数値に変換される' do
Story.page_size('1000').should eq Story.max_page_size
end
end
+ 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.list
+ end
+ end
it 'リストを返す' do
c = Story.list
c.should eq [@story]
end
- 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]
+ it '非公開ストーリーは(自分のストーリーであっても)含んでいない' do
+ FactoryGirl.create :story, :comic_id => @comic.id, :visible => 0
+ c = Story.list
+ c.should eq [@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]
+ it '時系列で並んでいる' do
+ #公開ストーリーは(他人のストーリーであっても)含んでいる
+ other_comic = FactoryGirl.create :comic, :author_id => @other_author.id
+ v = FactoryGirl.create :story, :comic_id => other_comic.id, :updated_at => Time.now + 100
+ c = Story.list
+ c.should eq [v, @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
+ @story2 = FactoryGirl.create :story, :comic_id => @comic.id, :updated_at => Time.now + 100
+ @story3 = FactoryGirl.create :story, :comic_id => @comic.id, :updated_at => Time.now + 200
+ @story4 = FactoryGirl.create :story, :comic_id => @comic.id, :updated_at => Time.now + 300
+ @story5 = FactoryGirl.create :story, :comic_id => @comic.id, :updated_at => Time.now + 400
+ Story.stub(:default_page_size).and_return(2)
end
it '通常は2件を返す' do
- l = Story.list 1, 2
- l.should have(2).items
+ c = Story.list
+ c.should have(2).items
end
it 'page=1なら末尾2件を返す' do
#時系列で並んでいる
- l = Story.list 1, 2
- l.should eq [@story5, @story4]
+ c = Story.list(1)
+ c.should eq [@story5, @story4]
end
it 'page=2なら中間2件を返す' do
- l = Story.list 2, 2
- l.should eq [@story3, @story2]
+ c = Story.list(2)
+ c.should eq [@story3, @story2]
end
it 'page=3なら先頭1件を返す' do
- l = Story.list 3, 2
- l.should eq [@story]
- end
- 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
- Story.stub(:default_page_size).and_return(2)
- end
- it '件数0は全件(5件)を返す' do
- r = Story.list 5, 0
- r.should have(5).items
+ c = Story.list(3)
+ c.should eq [@story]
end
end
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
+ @comic = FactoryGirl.create :comic, :author_id => @author.id
+ @story = FactoryGirl.create :story, :comic_id => @comic.id
end
context 'つつがなく終わるとき' do
it '一覧取得オプションを利用している' do
end
end
it 'リストを返す' do
- s = Story.mylist @author
- s.should eq [@story]
+ c = Story.mylist @author
+ c.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]
+ nc = FactoryGirl.create :story, :comic_id => @comic.id, :updated_at => Time.now + 100
+ cl = Story.mylist @author
+ cl.should eq [nc, @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]
+ it '他人のストーリーは公開でも含まない' do
+ other_comic = FactoryGirl.create :comic, :author_id => @other_author.id
+ nc = FactoryGirl.create :story, :comic_id => other_comic.id, :visible => 1
+ cl = Story.mylist @author
+ cl.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]
+ it '自分のストーリーは非公開でも含んでいる' do
+ nc = FactoryGirl.create :story, :comic_id => @comic.id, :visible => 0, :updated_at => Time.now + 100
+ cl = Story.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
- Story.stub(:default_page_size).and_return(2)
+ @story2 = FactoryGirl.create :story, :comic_id => @comic.id, :updated_at => Time.now + 100
+ @story3 = FactoryGirl.create :story, :comic_id => @comic.id, :updated_at => Time.now + 200
+ @story4 = FactoryGirl.create :story, :comic_id => @comic.id, :updated_at => Time.now + 300
+ @story5 = FactoryGirl.create :story, :comic_id => @comic.id, :updated_at => Time.now + 400
end
it '通常は2件を返す' do
- l = Story.mylist @author, 1, 2
- l.should have(2).items
+ c = Story.mylist @author, 1, 2
+ c.should have(2).items
end
it 'page=1なら末尾2件を返す' do
#時系列で並んでいる
- l = Story.mylist @author, 1, 2
- l.should eq [@story5, @story4]
+ c = Story.mylist(@author, 1, 2)
+ c.should eq [@story5, @story4]
end
it 'page=2なら中間2件を返す' do
- l = Story.mylist @author, 2, 2
- l.should eq [@story3, @story2]
+ c = Story.mylist(@author, 2, 2)
+ c.should eq [@story3, @story2]
end
it 'page=3なら先頭1件を返す' do
- l = Story.mylist @author, 3, 2
- l.should eq [@story]
+ c = Story.mylist(@author, 3, 2)
+ c.should eq [@story]
+ end
+ end
+ end
+
+ describe '他作家のストーリー一覧取得に於いて' do
+ before do
+ @comic = FactoryGirl.create :comic, :author_id => @author.id
+ @story = FactoryGirl.create :story, :comic_id => @comic.id
+ @other_comic = FactoryGirl.create :comic, :visible => 1, :author_id => @other_author.id
+ @other_story = FactoryGirl.create :story, :visible => 1, :comic_id => @other_comic.id
+ end
+ 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.himlist @other_author
end
end
+ it '指定した作家のリストを返す' do
+ r = Story.himlist @other_author
+ r.should eq [@other_story]
+ end
+ it '時系列で並んでいる' do
+ nc = FactoryGirl.create :story, :comic_id => @other_comic.id, :updated_at => Time.now + 100
+ r = Story.himlist @other_author
+ r.should eq [nc, @other_story]
+ end
+ it '公開ストーリーに限る ' do
+ hidden = FactoryGirl.create :story, :comic_id => @other_comic.id, :visible => 0
+ 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_page_size).and_return(2)
+ @other_story2 = FactoryGirl.create :story, :comic_id => @other_comic.id, :updated_at => Time.now + 100
+ @other_story3 = FactoryGirl.create :story, :comic_id => @other_comic.id, :updated_at => Time.now + 200
+ @other_story4 = FactoryGirl.create :story, :comic_id => @other_comic.id, :updated_at => Time.now + 300
+ @other_story5 = FactoryGirl.create :story, :comic_id => @other_comic.id, :updated_at => Time.now + 400
+ end
+ it '通常は2件を返す' do
+ c = Story.himlist @other_author, 1, 2
+ c.should have(2).items
+ end
+ it 'page=1なら末尾2件を返す' do
+ #時系列で並んでいる
+ c = Story.himlist(@other_author, 1, 2)
+ c.should eq [@other_story5, @other_story4]
+ end
+ it 'page=2なら中間2件を返す' do
+ c = Story.himlist(@other_author, 2, 2)
+ c.should eq [@other_story3, @other_story2]
end
- it '件数0は全件(5件)を返す' do
- r = Story.mylist @author, 5, 0
- r.should have(5).items
+ it 'page=3なら先頭1件を返す' do
+ c = Story.himlist(@other_author, 3, 2)
+ c.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 '一覧取得オプションに於いて' do
+ it '1つの項目を含んでいる' do
+ r = Story.list_opt
+ r.should have(1).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
+ end
+ describe 'json一覧出力オプションに於いて' do
+ before do
+ @comic = FactoryGirl.create :comic, :author_id => @author.id
+ @story = FactoryGirl.create :story, :comic_id => @comic.id, :visible => 1
+ end
+ it 'コミックを含んでいる' do
+ r = Story.list.to_json Story.list_json_opt
+ j = JSON.parse r
+ i = j.first
+ i.has_key?('comic').should be_true
end
+ it 'コミックは作家を含んでいる' do
+ r = Story.list.to_json Story.list_json_opt
+ j = JSON.parse r
+ i = j.first
+ s = i['comic']
+ s.has_key?('author').should be_true
+ 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
+ @story = FactoryGirl.create :story, :comic_id => @comic.id
end
context 'つつがなく終わるとき' do
it '単体取得オプションを利用している' do
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)
+ Story.any_instance.stub(:visible?).with(any_args).and_return(true)
+ Story.any_instance.should_receive(:visible?).with(any_args).exactly(1)
r = Story.show @story.id, @author
end
end
it '指定のストーリーを返す' do
- l = Story.show @story.id, @author
- l.should eq @story
+ c = Story.show @story.id, @author
+ c.should eq @story
end
- context '他人のストーリーを開こうとしたとき' do
+ context '閲覧許可が出なかったとき' do
it '403Forbidden例外を返す' do
- Story.any_instance.stub(:visible?).with(@other_author).and_return(false)
+ Story.any_instance.stub(:visible?).and_return(false)
lambda{
- Story.show @story.id, @other_author
+ Story.show @story.id, @author
}.should raise_error(ActiveRecord::Forbidden)
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
+ @story = FactoryGirl.create :story, :comic_id => @comic.id
end
context 'つつがなく終わるとき' do
it '単体取得オプションを利用している' do
end
end
it '指定のストーリーを返す' do
- l = Story.edit @story.id, @author
- l.should eq @story
+ Story.any_instance.stub(:own?).and_return(true)
+ c = Story.edit @story.id, @author.id
+ c.should eq @story
end
context '他人のストーリーを開こうとしたとき' do
it '403Forbidden例外を返す' do
end
end
end
-
describe '単体取得オプションに於いて' do
it 'includeキーを含んでいる' do
r = Story.show_opt
r.has_key?(:include).should be_true
end
- it '3つの項目を含んでいる' do
+ it '1つの項目を含んでいる' do
r = Story.show_opt[:include]
- r.should have(3).items
+ r.should have(1).items
end
it 'コミックを含んでいる' do
r = Story.show_opt[:include]
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
- end
-
- describe 'ストーリーのjson出力に於いて' do
- 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, :color_id => @color.id)
- )
- @gp = @panel.ground_pictures.create(
- FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id)
- )
- @pc = @panel.panel_colors.create(
- FactoryGirl.attributes_for(:panel_color, :panel_id => @panel.id, :code => 0xff0000)
- )
- @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
- context '事前チェックする' do
- before do
- Panel.any_instance.stub(:elements).and_return('{}')
- 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 = @story.story_as_json @author
- 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
- Panel.any_instance.stub(:visible?).with(any_args).and_return(true)
- 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
- Panel.any_instance.stub(:visible?).with(any_args).and_return(false)
- 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
+ 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}')
- 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.is_a?(Array).should be_true
+ @story = FactoryGirl.create :story, :comic_id => @comic.id, :visible => 1
end
- it 'ã\82¹ã\83\88ã\83¼ã\83ªã\83¼を含んでいる' do
- r = Story.list_as_json_text [@story], @author
+ it 'ã\82³ã\83\9fã\83\83ã\82¯を含んでいる' do
+ r = Story.show(@story.id, @author).to_json Story.show_json_opt
j = JSON.parse r
- j.first.has_key?('s').should be_true
- end
- end
-
- 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
+ i = j
+ i.has_key?('comic').should be_true
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
+ it 'コミックは作家を含んでいる' do
+ r = Story.show(@story.id, @author).to_json Story.show_json_opt
+ j = JSON.parse r
+ i = j
+ s = i['comic']
+ s.has_key?('author').should be_true
end
- end
end
describe 't補充値に於いて' do
before do
@comic = FactoryGirl.create :comic, :author_id => @author.id
- @panel = FactoryGirl.create :panel, :author_id => @author.id
end
context 'コミック初のコマなら' do
it '0を補充値とする' do
- @story = FactoryGirl.build :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
+ @story = FactoryGirl.build :story, :comic_id => @comic.id
@story.t = nil
r = Story.new_t @story.comic_id
r.should eq 0
end
context 'コミックに一個コマがあるとき' do
it '1を補充値とする' do
- FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 0
- @story = FactoryGirl.build :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
+ FactoryGirl.create :story, :comic_id => @comic.id, :t => 0
+ @story = FactoryGirl.build :story, :comic_id => @comic.id
@story.t = nil
r = Story.new_t @story.comic_id
r.should eq 1
end
context 'コミックに2個コマがあるとき' do
it '2を補充値とする' do
- FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 0
- FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1
- @story = FactoryGirl.build :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
+ FactoryGirl.create :story, :comic_id => @comic.id, :t => 0
+ FactoryGirl.create :story, :comic_id => @comic.id, :t => 1
+ @story = FactoryGirl.build :story, :comic_id => @comic.id
@story.t = nil
r = Story.new_t @story.comic_id
r.should eq 2
describe 't収集に於いて' do
before do
@comic = FactoryGirl.create :comic, :author_id => @author.id
- @panel = FactoryGirl.create :panel, :author_id => @author.id
- @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+ @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
@comic2 = FactoryGirl.create :comic, :author_id => @author.id
- @c2story = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
+ @c2story = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id
end
context 'つつがなく終わるとき' do
it 'ストーリーから同一コミックのtだけを収集している' do
end
context '複数コマのとき' do
it 'ストーリーから同一コミックのtだけを収集している' do
- @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+ @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
r = Story.collect_t @story
r.sort.should eq [0, 1]
end
end
- context 'è¤\87æ\95°ã\82³ã\83\9eでヨソのコミックも混じっているとき' do
+ context 'è¤\87æ\95°ã\82¹ã\83\88ã\83¼ã\83ªã\83¼でヨソのコミックも混じっているとき' do
it 'ストーリーから同一コミックのtだけを収集している' do
- @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+ @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
r = Story.collect_t @story
r.sort.should eq [0, 1]
end
describe 'tチェックに於いて' do
before do
@comic = FactoryGirl.create :comic, :author_id => @author.id
- @panel = FactoryGirl.create :panel, :author_id => @author.id
- @story = FactoryGirl.build :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+ @story = FactoryGirl.build :story, :t => 1, :comic_id => @comic.id
end
context 'つつがなく終わるとき' do
it 't収集を依頼している' do
#依頼チェックだけでは不安なので最低限のチェックを
context '新規のとき' do
it '一件だけで正常通過している' do
- @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id, :t => 0
+ @story = FactoryGirl.build :story, :comic_id => @comic.id, :t => 0
r = Story.validate_t @story
r.should be_true
end
end
context '既存のとき' do
it '2件目を作っても正常通過している' do
- @story = FactoryGirl.create :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id, :t => 0
- @story2 = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id, :t => 1
+ @story = FactoryGirl.create :story, :comic_id => @comic.id, :t => 0
+ @story2 = FactoryGirl.build :story, :comic_id => @comic.id, :t => 1
r = Story.validate_t @story2
r.should be_true
end
describe '挿入シフトに於いて' do
before do
@comic = FactoryGirl.create :comic, :author_id => @author.id
- @panel = FactoryGirl.create :panel, :author_id => @author.id
end
context '依頼チェック' do
#テーブルが空で0に挿入
it 'Updateを依頼している' do
Story.stub(:update_all).with(any_args)
Story.should_receive(:update_all).with(any_args).exactly(1)
- @story = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+ @story = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id
@story.insert_shift
end
end
context 'テーブルに1件(t:0)で0に挿入したとき' do
before do
- @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story2 = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+ @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+ @story2 = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id
end
it '既存の行を1にシフトしている' do
@story2.insert_shift
end
context 'テーブルに2件(t:0,1)で1に挿入したとき' do
before do
- @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story3 = FactoryGirl.build :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+ @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+ @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
+ @story3 = FactoryGirl.build :story, :t => 1, :comic_id => @comic.id
end
it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
@story3.insert_shift
end
context 'テーブルに5件(t:0,1,2,3,4)で2に挿入したとき' do
before do
- @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+ @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+ @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
+ @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id
+ @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id
+ @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id
+ @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id
end
it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
@story6.insert_shift
context '先ほどのケース+他のコミック1件で挿入したとき' do
before do
@comic2 = FactoryGirl.create :comic, :author_id => @author.id
- @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
- @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+ @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id
+ @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+ @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
+ @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id
+ @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id
+ @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id
+ @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id
end
it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
@story6.insert_shift
end
describe '少ない方に移動に於いて' do
before do
- @comic = FactoryGirl.create :comic, :author_id => @author.id
- @panel = FactoryGirl.create :panel, :author_id => @author.id
+ @comic = FactoryGirl.create :comic
end
context '依頼チェック' do
it 'Updateを依頼している' do
- @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+ @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+ @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
Story.stub(:update_all).with(any_args)
Story.should_receive(:update_all).with(any_args).exactly(1)
ot = @story2.t
end
context 'テーブルに2件(t:0,1)で1を0に移動したとき' do
before do
- @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+ @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+ @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
@ot = @story2.t
@story2.t = 0
end
end
context 'テーブルに3件(t:0,1,2)で2を1に移動したとき' do
before do
- @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+ @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+ @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
+ @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id
@ot = @story3.t
@story3.t = 1
end
end
context 'テーブルに5件(t:0,1,2,3,4)で3を1に移動したとき' do
before do
- @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+ @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+ @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
+ @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id
+ @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id
+ @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id
@ot = @story4.t
@story4.t = 1
end
end
context '先ほどのケース+他のコミック1件で挿入したとき' do
before do
- @comic2 = FactoryGirl.create :comic, :author_id => @author.id
- @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
- @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+ @comic2 = FactoryGirl.create :comic
+ @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id
+ @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+ @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
+ @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id
+ @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id
+ @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id
@ot = @story4.t
@story4.t = 1
end
#負のときは0として正常扱い
context 'テーブルに2件(t:0,1)で1を-1に移動したとき' do
before do
- @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+ @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+ @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
@ot = @story2.t
@story2.t = -1
end
describe '大きい方に移動に於いて' do
before do
@comic = FactoryGirl.create :comic, :author_id => @author.id
- @panel = FactoryGirl.create :panel, :author_id => @author.id
end
context '依頼チェック' do
it 'Updateを依頼している' do
- @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+ @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+ @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
Story.stub(:update_all).with(any_args)
Story.should_receive(:update_all).with(any_args).exactly(1)
ot = @story.t
end
context 'テーブルに2件(t:0,1)で0を1に移動したとき' do
before do
- @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+ @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+ @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
@ot = @story.t
@story.t = 1
end
end
context 'テーブルに3件(t:0,1,2)で0を1に移動したとき' do
before do
- @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+ @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+ @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
+ @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id
@ot = @story.t
@story.t = 1
end
end
context 'テーブルに5件(t:0,1,2,3,4)で1を3に移動したとき' do
before do
- @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+ @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+ @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
+ @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id
+ @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id
+ @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id
@ot = @story2.t
@story2.t = 3
end
context '先ほどのケース+他のコミック1件で挿入したとき' do
before do
@comic2 = FactoryGirl.create :comic, :author_id => @author.id
- @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
- @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+ @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id
+ @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+ @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
+ @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id
+ @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id
+ @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id
@ot = @story2.t
@story2.t = 3
end
#max超えたときはmaxとして正常扱い
context 'テーブルに2件(t:0,1)で0を2に移動したとき' do
before do
- @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+ @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+ @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
@ot = @story.t
@story.t = 2
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, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+ @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+ @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
end
context '新tが旧tより小さいとき' do
it '少ない方に移動を依頼している' do
describe '順序入れ替えに於いて' do
before do
@comic = FactoryGirl.create :comic, :author_id => @author.id
- @panel = FactoryGirl.create :panel, :author_id => @author.id
end
context 'オブジェクトが新規でtが空のとき' do
it '末尾追加としてtを補充依頼している' do
- @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+ @story = FactoryGirl.build :story, :comic_id => @comic.id
Story.stub(:new_t).with(any_args).and_return(0)
Story.should_receive(:new_t).with(any_args).exactly(1)
@story.t = nil
end
context 'オブジェクトが新規でtが設定されているとき' do
it '挿入追加として挿入シフトを依頼している' do
- @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+ @story = FactoryGirl.build :story, :comic_id => @comic.id
Story.any_instance.stub(:insert_shift).with(any_args)
Story.any_instance.should_receive(:insert_shift).with(any_args).exactly(1)
@story.t = 0
end
end
context 'オブジェクトが新規でなくtが設定されているとき' do
- it 'コマ移動として入れ替えを依頼している' do
- @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+ it '移動として入れ替えを依頼している' do
+ @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+ @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
Story.any_instance.stub(:update_shift).with(any_args)
Story.any_instance.should_receive(:update_shift).with(1).exactly(1)
@story2.t = 0
describe '編集許可に於いて' do
before do
@comic = FactoryGirl.create :comic, :author_id => @author.id
- @panel = FactoryGirl.create :panel, :author_id => @author.id
- @story = FactoryGirl.build :story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+ @story = FactoryGirl.build :story, :t => nil, :comic_id => @comic.id
end
context 'つつがなく終わるとき' do
it 'trueを返す' do
- r = @story.allow?
+ r = @story.allow? @author
r.should be_true
end
end
context 'コミックで引っかかるとき' do
it 'falseを返す' do
- 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(true)
- Panel.any_instance.stub(:usable?).with(any_args).and_return(false)
- r = @story.allow?
+ r = @story.allow? @other_author
r.should be_false
end
end
- context 'ã\82³ã\83\9fã\83\83ã\82¯ã\81¾ã\81\9fã\81¯ã\82³ã\83\9eã\81\8cæ\8c\87å®\9aã\81\95ã\82\8cã\81¦ã\81\84ã\81ªã\81\8bã\81£ã\81\9fã\81¨ã\81\8d' 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 eq nil
- end
- it 'nilを返す' do
- Panel.any_instance.stub(:usable?).with(any_args).and_return(true)
@story.comic_id = nil
- r = @story.allow?
+ r = @story.allow? @author
r.should eq nil
end
end
describe '保存に於いて' do
before do
@comic = FactoryGirl.create :comic, :author_id => @author.id
- @panel = FactoryGirl.create :panel, :author_id => @author.id
- @story = FactoryGirl.build :story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+ @story = FactoryGirl.build :story, :t => nil, :comic_id => @comic.id
end
context 'つつがなく終わるとき' do
it '編集許可チェックを依頼している' do
Story.any_instance.stub(:allow?).with(any_args).and_return(true)
Story.any_instance.should_receive(:allow?).with(any_args).exactly(1)
- r = @story.store
+ r = @story.store @author
end
it '順序入れ替えを依頼している' do
Story.any_instance.stub(:rotate).with(any_args).and_return(0)
Story.any_instance.should_receive(:rotate).with(any_args).exactly(1)
Story.any_instance.stub(:save).with(any_args).and_return(true)
Story.stub(:validate_t).with(any_args).and_return(true)
- r = @story.store
+ r = @story.store @author
end
it '保存を依頼している' do
Story.stub(:new_t).with(any_args).and_return(0)
Story.any_instance.stub(:save).with(any_args).and_return(true)
Story.any_instance.should_receive(:save).with(any_args).exactly(1)
Story.stub(:validate_t).with(any_args).and_return(true)
- r = @story.store
+ r = @story.store @author
end
it 'tのシリアライズチェックを依頼している' do
Story.stub(:new_t).with(any_args).and_return(0)
Story.any_instance.stub(:save).with(any_args).and_return(true)
Story.stub(:validate_t).with(any_args).and_return(true)
Story.should_receive(:validate_t).with(any_args).exactly(1)
- r = @story.store
+ r = @story.store @author
end
end
#入れ替えテストと同じテストを実施。こちらはシフトだけでなく本尊も更新されている
context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で2に挿入したとき' do
before do
@comic2 = FactoryGirl.create :comic, :author_id => @author.id
- @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
- @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+ @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id
+ @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+ @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
+ @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id
+ @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id
+ @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id
+ @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id
end
it '既存のt0には変化がない' do
- @story6.store
+ @story6.store @author
@story.reload
@story.t.should eq 0
end
it '既存のt1には変化がない' do
- @story6.store
+ @story6.store @author
@story2.reload
@story2.t.should eq 1
end
it '既存のt2を3にシフトしている' do
- @story6.store
+ @story6.store @author
@story3.reload
@story3.t.should eq 3
end
it '既存のt3を4にシフトしている' do
- @story6.store
+ @story6.store @author
@story4.reload
@story4.t.should eq 4
end
it '既存のt5を5にシフトしている' do
- @story6.store
+ @story6.store @author
@story5.reload
@story5.t.should eq 5
end
it '新規のt2が作成されている' do
- @story6.store
+ @story6.store @author
@story6.reload
@story6.t.should eq 2
end
it '他のコミックに影響がない' do
@ot = @storyc2.t
- @story6.store
+ @story6.store @author
@storyc2.reload
@storyc2.t.should eq @ot
end
context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で3を1に移動したとき' do
before do
@comic2 = FactoryGirl.create :comic, :author_id => @author.id
- @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
- @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+ @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id
+ @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+ @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
+ @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id
+ @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id
+ @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id
@ot = @story4.t
@story4.t = 1
end
it '既存のt0には変化がない' do
- @story4.store @ot
+ @story4.store @author, @ot
@story.reload
@story.t.should eq 0
end
it '既存のt4には変化がない' do
- @story4.store @ot
+ @story4.store @author, @ot
@story5.reload
@story5.t.should eq 4
end
it '既存のt1を2にシフトしている' do
- @story4.store @ot
+ @story4.store @author, @ot
@story2.reload
@story2.t.should eq 2
end
it '既存のt2を3にシフトしている' do
- @story4.store @ot
+ @story4.store @author, @ot
@story3.reload
@story3.t.should eq 3
end
it '既存のt3を1にシフトしている' do
- @story4.store @ot
+ @story4.store @author, @ot
@story4.reload
@story4.t.should eq 1
end
it '他のコミックに影響がない' do
- @story4.store @ot
+ @story4.store @author, @ot
@storyc2.reload
@storyc2.t.should eq 0
end
context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で1を3に移動したとき' do
before do
@comic2 = FactoryGirl.create :comic, :author_id => @author.id
- @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
- @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+ @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id
+ @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+ @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
+ @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id
+ @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id
+ @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id
@ot = @story2.t
@story2.t = 3
end
it '既存のt0には変化がない' do
- @story2.store @ot
+ @story2.store @author, @ot
@story.reload
@story.t.should eq 0
end
it '既存のt4には変化がない' do
- @story2.store @ot
+ @story2.store @author, @ot
@story5.reload
@story5.t.should eq 4
end
it '既存のt1を3にシフトしている' do
- @story2.store @ot
+ @story2.store @author, @ot
@story2.reload
@story2.t.should eq 3
end
it '既存のt2を1にシフトしている' do
- @story2.store @ot
+ @story2.store @author, @ot
@story3.reload
@story3.t.should eq 1
end
it '既存のt3を2にシフトしている' do
- @story2.store @ot
+ @story2.store @author, @ot
@story4.reload
@story4.t.should eq 2
end
it '他のコミックに影響がない' do
- @story2.store @ot
+ @story2.store @author, @ot
@storyc2.reload
@storyc2.t.should eq 0
end
before do
Story.any_instance.stub(:save).with(any_args).and_return(false)
@comic2 = FactoryGirl.create :comic, :author_id => @author.id
- @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
- @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+ @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id
+ @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+ @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
+ @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id
+ @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id
+ @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id
+ @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id
end
it '既存のtに変化がない' do
- @story6.store
+ @story6.store @author
@story.reload
@story.t.should eq 0
@story2.reload
@storyc2.t.should eq 0
end
it 'falseを返す' do
- r = @story6.store
+ r = @story6.store @author
r.should be_false
end
end
before do
Story.stub(:validate_t).with(any_args).and_return(false)
@comic2 = FactoryGirl.create :comic, :author_id => @author.id
- @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
- @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+ @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id
+ @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+ @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
+ @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id
+ @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id
+ @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id
@ot = @story4.t
@story4.t = 1
end
it '既存のtに変化がない' do
- @story4.store @ot
+ @story4.store @author, @ot
@story.reload
@story.t.should eq 0
@story2.reload
@storyc2.t.should eq 0
end
it 'falseを返す' do
- r = @story4.store @ot
+ r = @story4.store @author, @ot
r.should be_false
end
it 'tにエラーメッセージが入っている' do
- @story4.store @ot
+ @story4.store @author, @ot
@story4.errors[:t].should_not be_empty
@story4.valid?.should be_true
end
end
context '編集不可だったとき' do
before do
- @story = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+ @story = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id
Story.any_instance.stub(:allow?).and_return(false)
end
it '403Forbidden例外を返す' do
lambda{
- @story.store
+ @story.store @author
}.should raise_error(ActiveRecord::Forbidden)
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, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+ @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
end
context 'つつがなく終わるとき' do
+ it '削除を依頼している' do
+ Story.any_instance.stub(:destroy_with_story_sheet).with(any_args).and_return(true)
+ Story.any_instance.should_receive(:destroy_with_story_sheet).with(any_args).exactly(1)
+ r = @story.destroy_and_shorten
+ end
it '削除される' do
lambda{
@story.destroy_and_shorten
end
context '削除に失敗したとき' do
before do
- Story.any_instance.stub(:destroy).and_return(false)
+ Story.any_instance.stub(:destroy_with_story_sheet).and_return(false)
end
it 'ロールバックされる' do
lambda{
#連携テスト。切り詰めが直接DBをいじる
context '2件で先頭を削除したとき' do
before do
- @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+ @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
end
it '行が削除される' do
lambda{
end
context '3件で先頭を削除したとき' do
before do
- @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+ @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
+ @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id
end
it '行が削除される' do
lambda{
end
context '5件で3件目を削除したとき' do
before do
- @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
- @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+ @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
+ @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id
+ @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id
+ @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id
end
it '行が削除される' do
lambda{
end
#ロールバックテスト。切り詰めが直接DBをいじるので、すべてのケースで確実にロールバックを確認する
end
+ describe '削除に於いて' do
+ before do
+ @comic = FactoryGirl.create :comic, :author_id => @author.id
+ @story = FactoryGirl.create :story, :comic_id => @comic.id
+ @sheet = FactoryGirl.create :sheet, :author_id => @author.id
+ @story_sheet = FactoryGirl.create :story_sheet, :author_id => @author.id, :story_id => @story.id, :sheet_id => @sheet.id
+ @other_comic = FactoryGirl.create :comic, :author_id => @author.id
+ @other_story = FactoryGirl.create :story, :comic_id => @other_comic.id
+ @other_sheet = FactoryGirl.create :sheet, :author_id => @author.id
+ @other_story_sheet = FactoryGirl.create :story_sheet, :author_id => @author.id, :story_id => @other_story.id, :sheet_id => @other_sheet.id
+ end
+ context 'つつがなく終わるとき' do
+ it '自身を削除する' do
+ lambda {
+ r = @story.destroy_with_story_sheet
+ }.should change(Story, :count).by(-1)
+ lambda {
+ r = Story.find @story.id
+ }.should raise_error
+ end
+ it '自身にリンクしているスト紙をすべて削除する' do
+ lambda {
+ r = @story.destroy_with_story_sheet
+ }.should change(StorySheet, :count).by(-1)
+ lambda {
+ r = StorySheet.find @story_sheet.id
+ }.should raise_error
+ end
+ it 'Trueを返す' do
+ r = @story.destroy_with_story_sheet
+ r.should be_true
+ end
+ end
+ context '削除に失敗したとき' do
+ before do
+ StorySheet.any_instance.stub(:destroy).with(any_args).and_return(false)
+ end
+ it 'Falseを返す' do
+ r = @story.destroy_with_story_sheet
+ r.should be_false
+ end
+ it 'ロールバックしている' do
+ lambda {
+ r = @story.destroy_with_story_sheet
+ }.should_not change(Story, :count)
+ lambda {
+ r = @story.destroy_with_story_sheet
+ }.should_not change(StorySheet, :count)
+ end
+ end
+ end
end