X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=spec%2Fmodels%2Fpanel_spec.rb;h=20afa074a0d3cc98a229fbb57b1e6b5058afc1f0;hb=refs%2Fheads%2Fv06sheet;hp=76996f972eb34859841e592e03315354effdb11a;hpb=809beb5cd929c25f2d0ea1c3edd536d8d682c3a4;p=pettanr%2Fpettanr.git diff --git a/spec/models/panel_spec.rb b/spec/models/panel_spec.rb index 76996f97..20afa074 100644 --- a/spec/models/panel_spec.rb +++ b/spec/models/panel_spec.rb @@ -3,46 +3,47 @@ require 'spec_helper' #コマ describe Panel do before do - Factory :admin - @license = Factory :license - @user = Factory( :user_yas) - @author = @user.author - @artist = Factory :artist_yas, :author_id => @author.id - @other_user = Factory( :user_yas) - @other_author = @other_user.author - @other_artist = Factory :artist_yas, :author_id => @other_author.id - @op = Factory :original_picture, :artist_id => @artist.id, :license_id => @license.id - @rp = Factory :resource_picture, :original_picture_id => @op.id, :license_id => @license.id - @sbt = Factory :speech_balloon_template + SpeechBalloonTemplate.delete_all + @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 + @writing_format = FactoryGirl.create :writing_format + @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 + @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.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, "name" => "circle@pettan.com", "classname" => "CircleSpeechBalloon", "caption" => "cc", "system_picture_id" => @sp.id, "settings" => '{}' end describe '検証に於いて' do before do - @comic = Factory :comic, :author_id => @author.id + @panel = FactoryGirl.build :panel, :author_id => @author.id end - it 'オーソドックスなデータなら通る' do - @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id - @panel.should be_valid - end - - context 'comic_idを検証するとき' do - before do - @panel = Factory.build :panel, :author_id => @author.id, :comic_id => nil + context 'オーソドックスなデータのとき' do + it '下限データが通る' do + @panel.width = 1 + @panel.height = 1 + @panel.border = 0 + @panel.publish = 0 + @panel.should be_valid end - it 'テストデータの確認' do - @panel.comic_id = @comic.id + it '上限データが通る' do + @panel.width = 99999 + @panel.height = 99999 + @panel.border = 99999 + @panel.publish = 99999 @panel.should be_valid end end + context 'widthを検証するとき' do - before do - @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id - end - it 'テストデータの確認' do - @panel.width = 1 - @panel.should be_valid - end it 'nullなら失敗する' do @panel.width = nil @panel.should_not be_valid @@ -61,13 +62,6 @@ describe Panel do end end context 'heightを検証するとき' do - before do - @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id - end - it 'テストデータの確認' do - @panel.height = '1' - @panel.should be_valid - end it 'nullなら失敗する' do @panel.height = nil @panel.should_not be_valid @@ -86,13 +80,6 @@ describe Panel do end end context 'borderを検証するとき' do - before do - @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id - end - it 'テストデータの確認' do - @panel.border = '1' - @panel.should be_valid - end it 'nullなら失敗する' do @panel.border = nil @panel.should_not be_valid @@ -110,263 +97,503 @@ describe Panel do @panel.should be_valid end end - context 'xを検証するとき' do - before do - @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id - end - it 'テストデータの確認' do - @panel.x = '1' - @panel.should be_valid + context 'author_idを検証するとき' do + it 'nullなら失敗する' do + @panel.author_id = nil + @panel.should_not be_valid end it '数値でなければ失敗する' do - @panel.x = 'a' + @panel.author_id = 'a' @panel.should_not be_valid end - it '0なら通る' do - @panel.x = '0' - @panel.should be_valid - end - it '負でも通る' do - @panel.x = -1 - @panel.should be_valid + it '存在する作家でなければ失敗する' do + @panel.author_id = 0 + @panel.should_not be_valid end end - context 'yを検証するとき' do - before do - @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id - end - it 'テストデータの確認' do - @panel.y = '1' - @panel.should be_valid - end + context '公開フラグを検証するとき' do it '数値でなければ失敗する' do - @panel.y = 'a' + @panel.publish = 'a' @panel.should_not be_valid end - it '0なら通る' do - @panel.y = '0' - @panel.should be_valid + end + context '全体を検証するとき' do + before do + @panel = FactoryGirl.create :panel, :author_id => @author.id end - it '負でも通る' do - @panel.y = -1 - @panel.should be_valid + end + end + + describe '文字コード検証に於いて' do + before do + @panel = FactoryGirl.build :panel, :author_id => @author.id + end + + context 'captionを検証するとき' do + it 'Shift JISなら失敗する' do + @panel.caption = "\x83G\x83r\x83]\x83D" + lambda{ + @panel.valid_encode + }.should raise_error(Pettanr::BadRequest) end end - context 'zを検証するとき' do - before do - @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id + + end + + describe 'デフォルト値補充に於いて' do + before do + @panel = FactoryGirl.build :panel, :author_id => @author.id + end + it 'borderは2を補充する' do + @panel.border = nil + @panel.supply_default + @panel.border.should eq 2 + end + it 'publishは0を補充する' do + @panel.publish = nil + @panel.supply_default + @panel.publish.should eq 0 + end + end + + describe '上書き補充に於いて' do + before do + @panel = FactoryGirl.build :panel, :author_id => @author.id + end + context 'author_idを補充' do + it 'ログイン中の作家idを補充する' do + @panel.author_id = nil + @panel.overwrite @author + @panel.author_id.should eq @author.id end - it 'テストデータの確認' do - @panel.z = '1' - @panel.should be_valid + end + + end + + describe '所持判定に於いて' do + before do + @panel = FactoryGirl.create :panel, :author_id => @author.id + end + context '事前チェックする' do + it '自身にロールリストからの作家取得を依頼している' do + Panel.should_receive(:get_author_from_roles).with(any_args).exactly(1) + r = @panel.own?([@author]) end - it '数値でなければ失敗する' do - @panel.z = 'a' - @panel.should_not be_valid + end + context 'ロール内作家が取得できるとき' do + before do end - it '0なら失敗する' do - @panel.z = '0' - @panel.should_not be_valid + it 'ロール内作家のidが自身の作家idと一致するなら許可する' do + Panel.stub(:get_author_from_roles).with(any_args).and_return(@author) + r = @panel.own?([@author]) + r.should be_true end - it '負なら失敗する' do - @panel.z = -1 - @panel.should_not be_valid + it 'ロール内作家のidが自身の作家idと一致しないならno' do + Panel.stub(:get_author_from_roles).with(any_args).and_return(@other_author) + @panel.own?(@other_author).should be_false end end - context 'tを検証するとき' do + context 'ロール内作家が取得できないとき' do before do - @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id + Panel.stub(:get_author_from_roles).with(any_args).and_return(nil) end - it 'テストデータの確認' do - @panel.t = '1' - @panel.should be_valid + it 'Falseを返す' do + r = @panel.own?([@author]) + r.should be_false end - it '数値でなければ失敗する' do - @panel.t = 'a' - @panel.should_not be_valid + end + end + + describe '閲覧許可に於いて' do + before do + @scroll = FactoryGirl.create :scroll, :author_id => @author.id + @panel = FactoryGirl.create :panel, :author_id => @author.id + @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id + end + context 'オープンモードのとき' do + before do + MagicNumber['run_mode'] = 0 end - it '0なら通る' do - @panel.t = '0' - @panel.should be_valid + it '自身にゲスト用ロールチェックを問い合わせしている' do + Panel.any_instance.stub(:guest_role_check).and_return(true) + Panel.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1) + r = @panel.visible?([@author]) end - it '負でも失敗する' do - @panel.t = -1 - @panel.should_not be_valid + it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do + Panel.any_instance.stub(:guest_role_check).and_return(false) + r = @panel.visible?([@author]) + r.should be_false end end - context 'author_idを検証するとき' do + context 'クローズドモードのとき' do before do - @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id + MagicNumber['run_mode'] = 1 end - it 'テストデータの確認' do - @panel.author_id = @author.id - @panel.should be_valid + it '自身に読者用ロールチェックを問い合わせしている' do + Panel.any_instance.stub(:reader_role_check).and_return(true) + Panel.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1) + r = @panel.visible?([@author]) end - it 'nullなら失敗する' do - @panel.author_id = nil - @panel.should_not be_valid + it '読者用ロールチェックが失敗したとき、falseを返す' do + Panel.any_instance.stub(:reader_role_check).and_return(false) + r = @panel.visible?([@author]) + r.should be_false end - it '数値でなければ失敗する' do - @panel.author_id = 'a' - @panel.should_not be_valid + end + context '事前チェックする' do + before do + MagicNumber['run_mode'] = 1 + Panel.any_instance.stub(:reader_role_check).and_return(true) end - it '存在する絵師でなければ失敗する' do - @panel.author_id = 0 - @panel.should_not be_valid + it '自身に所持判定を問い合わせしている' do + Panel.any_instance.stub(:own?).and_return(true) + Panel.any_instance.should_receive(:own?).with(any_args).exactly(1) + r = @panel.visible?([@author]) + end + it '自身に閲覧許可を問い合わせしている' do + Panel.any_instance.stub(:own?).and_return(false) + Panel.any_instance.stub(:publish?).and_return(true) + Panel.any_instance.should_receive(:publish?).with(any_args).exactly(1) + r = @panel.visible?([@author]) end end - context '全体を検証するとき' do + context 'つつがなく終わるとき' do before do - @panel = Factory :panel, :author_id => @author.id, :comic_id => @comic.id + MagicNumber['run_mode'] = 1 + Panel.any_instance.stub(:reader_role_check).and_return(true) + end + it '自分のコマなら許可する' do + Panel.any_instance.stub(:own?).and_return(true) + Panel.any_instance.stub(:publish?).and_return(false) + r = @panel.visible?([@author]) + r.should be_true + end + it '他人の非公開コマなら許可しない' do + Panel.any_instance.stub(:own?).and_return(false) + Panel.any_instance.stub(:publish?).and_return(false) + r = @panel.visible?([@author]) + r.should be_false + end + it '他人のコマでも公開なら許可する' do + Panel.any_instance.stub(:own?).and_return(false) + Panel.any_instance.stub(:publish?).and_return(true) + r = @panel.visible?([@author]) + r.should be_true end end end - describe 'データ補充に於いて' do + describe '一覧取得に於いて' do before do - @comic = Factory :comic, :author_id => @author.id - @panel = Factory.build :panel, :comic_id => @comic.id + @panel = FactoryGirl.create :panel, :author_id => @author.id end - context 'widthを補充' do - it '空の時はコミックから補充する' do - @panel.width = nil - @panel.supply_default @author - @panel.width.should eq @comic.width + context 'page補正について' do + it '文字列から数値に変換される' do + Panel.page('8').should eq 8 end - it '空の時でもコミックが不在なら補充しない' do - @panel.width = nil - @panel.comic_id = nil - @panel.supply_default @author - @panel.width.should be_nil + it 'nilの場合は1になる' do + Panel.page().should eq 1 end - it '空でない時は変化しない' do - @panel.width = 45 - lambda { - @panel.supply_default @author - }.should_not change @panel, :width + it '0以下の場合は1になる' do + Panel.page('0').should eq 1 end end - context 'heightを補充' do - it '空の時はコミックから補充する' do - @panel.height = nil - @panel.supply_default @author - @panel.height.should eq @comic.height + context 'page_size補正について' do + it '文字列から数値に変換される' do + Panel.page_size('7').should eq 7 end - it '空の時でもコミックが不在なら補充しない' do - @panel.height = nil - @panel.comic_id = nil - @panel.supply_default @author - @panel.height.should be_nil + it 'nilの場合はPanel.default_page_sizeになる' do + Panel.page_size().should eq Panel.default_page_size end - it '空でない時は変化しない' do - @panel.height = 87 - lambda { - @panel.supply_default @author - }.should_not change @panel, :height + it '0以下の場合はPanel.default_page_sizeになる' do + Panel.page_size('0').should eq Panel.default_page_size + end + it 'Panel.max_page_sizeを超えた場合はPanel.max_page_sizeになる' do + Panel.page_size('1000').should eq Panel.max_page_size end end - context 'borderを補充' do - it '空の時は0を補充する' do - @panel.border = nil - @panel.supply_default @author - @panel.border.should eq 0 + it 'リストを返す' do + r = Panel.list + r.should eq [@panel] + end + it '時系列で並んでいる' do + #公開コミックは(他人のコミックであっても)含んでいる + npl = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100 + r = Panel.list + r.should eq [npl, @panel] + end + it '非公開のコマ(自分のコマであっても)は含まない' do + npl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0 + r = Panel.list + r.should eq [@panel] + end + context 'DBに5件あって1ページの件数を2件に変えたとして' do + before do + @npl2 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100 + @npl3 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 200 + @npl4 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 300 + @npl5 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 400 + Panel.stub(:default_page_size).and_return(2) end - it '空でない時は変化しない' do - @panel.border = 1 - lambda { - @panel.supply_default @author - }.should_not change @panel, :border + it '通常は2件を返す' do + pl = Panel.list + pl.should have(2).items end + it 'page=1なら末尾2件を返す' do + #時系列で並んでいる + pl = Panel.list 1 + pl.should eq [@npl5, @npl4] + end + it 'page=2なら中間2件を返す' do + pl = Panel.list 2 + pl.should eq [@npl3, @npl2] + end + it 'page=3なら先頭1件を返す' do + pl = Panel.list 3 + pl.should eq [@panel] + end + end + end + + describe '自分のコマ一覧取得に於いて' do + before do + @panel = FactoryGirl.create :panel, :author_id => @author.id + end + it 'リストを返す' do + pl = Panel.mylist @author + pl.should eq [@panel] end - context 'tを補充' do - it '空の時はコミック内のtの最大値+1を補充する' do - pl = Factory :panel, :author_id => @author.id, :comic_id => @comic.id, :t => 0 - @panel.t = nil - @panel.supply_default @author - @panel.t.should eq 1 + it '時系列で並んでいる' do + npl = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100 + pl = Panel.mylist @author + pl.should eq [npl, @panel] + end + it '他人のコマは公開でも含まない' do + npl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1 + pl = Panel.mylist @author + pl.should eq [@panel] + end + it '自分のコマは非公開でも含んでいる' do + npl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0, :updated_at => Time.now + 100 + pl = Panel.mylist @author + pl.should eq [npl, @panel] + end + context 'DBに5件あって1ページの件数を2件に変えたとして' do + before do + @npl2 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100 + @npl3 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 200 + @npl4 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 300 + @npl5 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 400 end - it '空でコミック初のコマなら0を補充する' do - @panel.t = nil - @panel.supply_default @author - @panel.t.should eq 0 + it '通常は2件を返す' do + pl = Panel.mylist @author, 1, 2 + pl.should have(2).items end - it '空の時でも更新ケースなら補充しない' do - pl = Factory :panel, :author_id => @author.id, :comic_id => @comic.id, :t => 1 - pl.t = nil - lambda { - pl.supply_default @author - }.should_not change pl, :t + it 'page=1なら末尾2件を返す' do + #時系列で並んでいる + pl = Panel.mylist @author, 1, 2 + pl.should eq [@npl5, @npl4] end - it '空でない時は変化しない' do - @panel.t = 1 - lambda { - @panel.supply_default @author - }.should_not change @panel, :t + it 'page=2なら中間2件を返す' do + pl = Panel.mylist @author, 2, 2 + pl.should eq [@npl3, @npl2] + end + it 'page=3なら先頭1件を返す' do + pl = Panel.mylist @author, 3, 2 + pl.should eq [@panel] end end - context 'author_idを補充' do - it 'ログイン中の作家idを補充する' do - @panel.author_id = nil - @panel.supply_default @author - @panel.author_id.should eq @author.id + end + + describe '他作家のコマ一覧取得に於いて' do + before do + @panel = FactoryGirl.create :panel, :author_id => @author.id + @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1 + end + it 'リストを返す' do + r = Panel.himlist @other_author + r.should eq [@other_panel] + end + it '時系列で並んでいる' do + npl = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100 + r = Panel.himlist @other_author + r.should eq [npl, @other_panel] + end + it '公開コマに限る' do + npl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 0 + r = Panel.himlist @other_author + r.should eq [@other_panel] + end + context 'DBに5件あって1ページの件数を2件に変えたとして' do + before do + @other_panel2 = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100 + @other_panel3 = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 200 + @other_panel4 = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 300 + @other_panel5 = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 400 + end + it '通常は2件を返す' do + pl = Panel.himlist @other_author, 1, 2 + pl.should have(2).items + end + it 'page=1なら末尾2件を返す' do + #時系列で並んでいる + pl = Panel.himlist @other_author, 1, 2 + pl.should eq [@other_panel5, @other_panel4] + end + it 'page=2なら中間2件を返す' do + pl = Panel.himlist @other_author, 2, 2 + pl.should eq [@other_panel3, @other_panel2] + end + it 'page=3なら先頭1件を返す' do + pl = Panel.himlist @other_author, 3, 2 + pl.should eq [@other_panel] end end - end - describe '作者判定に於いて' do + describe 'コマ一覧ページ制御に於いて' do before do - @comic = Factory :comic, :author_id => @author.id + Panel.stub(:count).with(any_args).and_return(100) end - it '自作のコマならyes' do - panel = Factory :panel, :author_id => @author.id, :comic_id => @comic.id - panel.own?(@author).should == true + it 'ページ制御を返す' do + r = Panel.list_paginate + r.is_a?(Kaminari::PaginatableArray).should be_true end - it '他人のコマならno' do - panel = Factory :panel, :author_id => @other_author.id, :comic_id => @comic.id - panel.own?(@author).should == false + it 'コマ一覧の取得条件を利用している' do + Panel.stub(:list_where).with(any_args).and_return('') + Panel.should_receive(:list_where).with(any_args).exactly(1) + r = Panel.list_paginate end - it '作家が不明ならno' do - panel = Factory :panel, :author_id => @author.id, :comic_id => @comic.id - panel.own?(nil).should == false + it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do + r = Panel.list_paginate 3, 10 + r.limit_value.should eq 10 + r.offset_value.should eq 20 end end - describe '閲覧許可に於いて' do + + describe '自分のコマ一覧ページ制御に於いて' do + before do + Panel.stub(:count).with(any_args).and_return(100) + end + it 'ページ制御を返す' do + r = Panel.mylist_paginate @author + r.is_a?(Kaminari::PaginatableArray).should be_true + end + it '自分のコマ一覧の取得条件を利用している' do + Panel.stub(:mylist_where).with(any_args).and_return('') + Panel.should_receive(:mylist_where).with(any_args).exactly(1) + r = Panel.mylist_paginate @author + end + it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do + r = Panel.mylist_paginate @author, 3, 10 + r.limit_value.should eq 10 + r.offset_value.should eq 20 + end + end + + describe '他作家のコマ一覧ページ制御に於いて' do before do - @comic = Factory :comic, :author_id => @author.id + Panel.stub(:count).with(any_args).and_return(100) + end + it 'ページ制御を返す' do + r = Panel.himlist_paginate @other_author + r.is_a?(Kaminari::PaginatableArray).should be_true + end + it '他作家のコマ一覧の取得条件を利用している' do + Panel.stub(:himlist_where).with(any_args).and_return('') + Panel.should_receive(:himlist_where).with(any_args).exactly(1) + r = Panel.himlist_paginate @other_author end - it '自作の公開コミックのコマを見るときは許可する' do - Comic.any_instance.stub(:visible?).and_return(true) - panel = Factory :panel, :author_id => @author.id, :comic_id => @comic.id - panel.visible?(@author).should == true + it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do + r = Panel.himlist_paginate @other_author, 3, 10 + r.limit_value.should eq 10 + r.offset_value.should eq 20 end - it '自作のコマは非公開コミックでも許可する' do - Comic.any_instance.stub(:visible?).and_return(false) - panel = Factory :panel, :author_id => @author.id, :comic_id => @comic.id - panel.visible?(@author).should == true + end + + describe '一覧取得オプションに於いて' do + it '5つの項目を含んでいる' do + r = Panel.list_opt + r.should have(5).items + end + it 'コマ絵を含んでいる' do + r = Panel.list_opt + r.has_key?(:panel_pictures).should be_true + end + it 'コマ絵は実素材を含んでいる' do + r = Panel.list_opt + r[:panel_pictures].has_key?(:picture).should be_true + end + it '実素材は絵師を含んでいる' do + r = Panel.list_opt + r[:panel_pictures][:picture].has_key?(:artist).should be_true + end + it '実素材はライセンスを含んでいる' do + r = Panel.list_opt + r[:panel_pictures][:picture].has_key?(:license).should be_true + end + it 'フキダシを含んでいる' do + r = Panel.list_opt + r.has_key?(:speech_balloons).should be_true + end + it 'フキダシはフキダシ枠を含んでいる' do + r = Panel.list_opt + r[:speech_balloons].has_key?(:balloon).should be_true + end + it 'フキダシはセリフを含んでいる' do + r = Panel.list_opt + r[:speech_balloons].has_key?(:speech).should be_true + end + it '絵地を含んでいる' do + r = Panel.list_opt + r.has_key?(:ground_pictures).should be_true end - it '他人のコマでも公開コミックなら許可する' do - Comic.any_instance.stub(:visible?).and_return(true) - panel = Factory :panel, :author_id => @other_author.id, :comic_id => @comic.id - panel.visible?(@author).should == true + it '絵地は実素材を含んでいる' do + r = Panel.list_opt + r[:ground_pictures].has_key?(:picture).should be_true + end + it '実素材は絵師を含んでいる' do + r = Panel.list_opt + r[:ground_pictures][:picture].has_key?(:artist).should be_true + end + it '実素材はライセンスを含んでいる' do + r = Panel.list_opt + r[:ground_pictures][:picture].has_key?(:license).should be_true + end + it '色地を含んでいる' do + r = Panel.list_opt + r.has_key?(:ground_colors).should be_true end - it '他人のコマで非公開コミックなら許可しない' do - Comic.any_instance.stub(:visible?).and_return(false) - panel = Factory :panel, :author_id => @other_author.id, :comic_id => @comic.id - panel.visible?(@author).should == false + it '作家を含んでいる' do + r = Panel.list_opt + r.has_key?(:author).should be_true end end + describe 'json一覧出力オプションに於いて' do + end + describe '単体取得に於いて' do before do - @comic = Factory :comic, :author_id => @author.id - @panel = Factory :panel, :comic_id => @comic.id, :author_id => @author.id + @panel = FactoryGirl.create :panel, :author_id => @author.id + end + context 'つつがなく終わるとき' do + it '単体取得オプションを利用している' do + Panel.stub(:show_opt).with(any_args).and_return({}) + Panel.should_receive(:show_opt).with(any_args).exactly(1) + r = Panel.show @panel.id, @author + end + it '閲覧許可を問い合わせている' do + Panel.any_instance.stub(:visible?).with(any_args).and_return(true) + Panel.any_instance.should_receive(:visible?).with(any_args).exactly(1) + r = Panel.show @panel.id, @author + end end it '指定のコマを返す' do - Comic.any_instance.stub(:visible?).and_return(true) + Panel.any_instance.stub(:visible?).and_return(true) pl = Panel.show @panel.id, @author pl.should eq @panel end - context '他人の非公開コミックのコマを開こうとしたとき' do + context '閲覧許可が出なかったとき' do it '403Forbidden例外を返す' do Panel.any_instance.stub(:visible?).and_return(false) lambda{ @@ -374,292 +601,871 @@ describe Panel do }.should raise_error(ActiveRecord::Forbidden) end end - context '存在しないコマを開こうとしたとき' do - it '404RecordNotFound例外を返す' do - lambda{ - Panel.show 110, @author - }.should raise_error(ActiveRecord::RecordNotFound) + context '存在しないコマを開こうとしたとき' do + it '404RecordNotFound例外を返す' do + lambda{ + Panel.show 110, @author + }.should raise_error(ActiveRecord::RecordNotFound) + end + end + end + describe '編集取得に於いて' do + before do + @panel = FactoryGirl.create :panel, :author_id => @author.id + end + context 'つつがなく終わるとき' do + it '単体取得オプションを利用している' do + Panel.stub(:show_opt).with(any_args).and_return({}) + Panel.should_receive(:show_opt).with(any_args).exactly(1) + r = Panel.edit @panel.id, @author + end + it '所持判定を問い合わせている' do + Panel.any_instance.stub(:own?).with(any_args).and_return(true) + Panel.any_instance.should_receive(:own?).with(any_args).exactly(1) + r = Panel.edit @panel.id, @author + end + end + it '指定のコマを返す' do + Panel.any_instance.stub(:own?).and_return(true) + pl = Panel.edit @panel.id, @author + pl.should eq @panel + end + context '他人のコマを開こうとしたとき' do + it '403Forbidden例外を返す' do + Panel.any_instance.stub(:own?).and_return(false) + lambda{ + Panel.edit @panel.id, @author + }.should raise_error(ActiveRecord::Forbidden) + end + end + context '存在しないコマを開こうとしたとき' do + it '404RecordNotFound例外を返す' do + lambda{ + Panel.edit 110, @author + }.should raise_error(ActiveRecord::RecordNotFound) + end + end + end + describe '単体取得オプションに於いて' do + it 'includeキーを含んでいる' do + r = Panel.show_opt + r.has_key?(:include).should be_true + end + it '5つの項目を含んでいる' do + r = Panel.show_opt[:include] + r.should have(5).items + end + it 'コマ絵を含んでいる' do + r = Panel.show_opt[:include] + r.has_key?(:panel_pictures).should be_true + end + it 'コマ絵は実素材を含んでいる' do + r = Panel.show_opt[:include] + r[:panel_pictures].has_key?(:picture).should be_true + end + it '実素材は絵師を含んでいる' do + r = Panel.show_opt[:include] + r[:panel_pictures][:picture].has_key?(:artist).should be_true + end + it '実素材はライセンスを含んでいる' do + r = Panel.show_opt[:include] + r[:panel_pictures][:picture].has_key?(:license).should be_true + end + it 'フキダシを含んでいる' do + r = Panel.show_opt[:include] + r.has_key?(:speech_balloons).should be_true + end + it 'フキダシはフキダシ枠を含んでいる' do + r = Panel.show_opt[:include] + r[:speech_balloons].has_key?(:balloon).should be_true + end + it 'フキダシはセリフを含んでいる' do + r = Panel.show_opt[:include] + r[:speech_balloons].has_key?(:speech).should be_true + end + it '絵地を含んでいる' do + r = Panel.show_opt[:include] + r.has_key?(:ground_pictures).should be_true + end + it '絵地は実素材を含んでいる' do + r = Panel.show_opt[:include] + r[:ground_pictures].has_key?(:picture).should be_true + end + it '実素材は絵師を含んでいる' do + r = Panel.show_opt[:include] + r[:ground_pictures][:picture].has_key?(:artist).should be_true + end + it '実素材はライセンスを含んでいる' do + r = Panel.show_opt[:include] + r[:ground_pictures][:picture].has_key?(:license).should be_true + end + it '色地を含んでいる' do + r = Panel.show_opt[:include] + r.has_key?(:ground_colors).should be_true + end + it '作家を含んでいる' do + r = Panel.show_opt[:include] + r.has_key?(:author).should be_true + end + end + describe 'json単体出力オプションに於いて' do + end + describe 'コマ部品集合に於いて' 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.build( + FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0) + ) + @sb.build_balloon( + FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id) + ) + @sb.build_speech( + FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id) + ) + @sb.boost + @sb.save! + @gc = @panel.ground_colors.create( + FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2) + ) + @gp = @panel.ground_pictures.create( + FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 3) + ) + @panel.reload + end + it 'リストを返している' do + r = @panel.parts_element + r.is_a?(Array).should be_true + end + it 'コマ絵とフキダシと絵地と色地を合わせている' do + r = @panel.parts_element + r.include?(@pp).should be_true + r.include?(@sb).should be_true + r.include?(@gc).should be_true + r.include?(@gp).should be_true + end + end + + describe 'z順コマ部品に於いて' do + before do + #コマを作成しておく。 + @panel = FactoryGirl.create :panel, :author_id => @author.id + @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 0, :z => 2, :width => @p.width, :height => @p.height + @sb = @panel.speech_balloons.build( + FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 1, :z => 1) + ) + @sb.build_balloon( + FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id) + ) + @sb.build_speech( + FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id) + ) + @sb.boost + @sb.save! + @gc = @panel.ground_colors.create( + FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2, :z => 3) + ) + @gp = @panel.ground_pictures.create( + FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 3, :z => 4) + ) + @panel.reload + end + context 'つつがなく終わるとき' do + it 'コマ部品集合を利用している' do + Panel.any_instance.stub(:parts_element).with(any_args).and_return([]) + Panel.any_instance.should_receive(:parts_element).with(any_args).exactly(1) + r = @panel.zorderd_elements + end + end + it 'リストを返している' do + r = @panel.zorderd_elements + r.is_a?(Array).should be_true + r.size.should eq 4 + end + it 'zでオフセットを0でソートしている' do + r = @panel.zorderd_elements + r[0].should eq @sb + r[1].should eq @pp + r[2].should eq @gc + r[3].should eq @gp + end + context 'さらに末尾にフキダシを追加したとき' do + before do + @sb2 = @panel.speech_balloons.build( + FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 4, :z => 5) + ) + @sb2.build_balloon( + FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id) + ) + @sb2.build_speech( + FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id) + ) + @sb2.boost + @sb2.save! + @panel.reload + end + it 'zでソートしている' do + r = @panel.zorderd_elements + r[0].should eq @sb + r[1].should eq @pp + r[2].should eq @gc + r[3].should eq @gp + r[4].should eq @sb2 + end + end + end + describe 'コマ要素に於いて' 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.build( + FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0) + ) + @sb.build_balloon( + FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id) + ) + @sb.build_speech( + FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id) + ) + @sb.boost + @sb.save! + @gc = @panel.ground_colors.create( + FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2) + ) + @gp = @panel.ground_pictures.create( + FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 3) + ) + @panel.reload + end + context 'つつがなく終わるとき' do + it 'コマ部品を利用している' do + Panel.any_instance.stub(:parts_element).with(any_args).and_return([]) + Panel.any_instance.should_receive(:parts_element).with(any_args).exactly(1) + r = @panel.panel_elements + end + end + it 'リストを返している' do + r = @panel.panel_elements + r.is_a?(Array).should be_true + end + it 'tでソートしている' do + r = @panel.panel_elements + r[0].should eq @sb + r[1].should eq @pp + r[2].should eq @gc + r[3].should eq @gp + end + context 'さらに末尾にフキダシを追加したとき' do + before do + @sb2 = @panel.speech_balloons.build( + FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 4) + ) + @sb2.build_balloon( + FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id) + ) + @sb2.build_speech( + FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id) + ) + @sb2.boost + @sb2.save! + @panel.reload + end + it 'tでソートしている' do + r = @panel.panel_elements + r[0].should eq @sb + r[1].should eq @pp + r[2].should eq @gc + r[3].should eq @gp + r[4].should eq @sb2 + end + end + 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.build( + FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0) + ) + @sb.build_balloon( + FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id) + ) + @sb.build_speech( + FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id) + ) + @sb.boost + @sb.save! + @gc = @panel.ground_colors.create( + FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2) + ) + @gp = @panel.ground_pictures.create( + FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 3) + ) + @panel.reload + end + context 'つつがなく終わるとき' do + before do + PanelPicture.stub(:json_opt_for_panel).and_return({}) + SpeechBalloon.stub(:json_opt_for_panel).and_return({}) + GroundPicture.stub(:json_opt_for_panel).and_return({}) + GroundColor.stub(:json_opt_for_panel).and_return({}) + end + it 'コマ絵にjson出力オプションを依頼している' do + PanelPicture.should_receive(:json_opt_for_panel).exactly(1) + r = @panel.elements + end + it 'フキダシにjson出力オプションを依頼している' do + SpeechBalloon.should_receive(:json_opt_for_panel).exactly(1) + r = @panel.elements + end + it '絵地にjson出力オプションを依頼している' do + GroundPicture.should_receive(:json_opt_for_panel).exactly(1) + r = @panel.elements + end + it '色地にjson出力オプションを依頼している' do + GroundColor.should_receive(:json_opt_for_panel).exactly(1) + r = @panel.elements + end + end + it 'リストを返している' do + r = @panel.elements + r.is_a?(Array).should be_true + end + 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.build( + FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0) + ) + @sb.build_balloon( + FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id) + ) + @sb.build_speech( + FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id) + ) + @sb.boost + @sb.save! + @gc = @panel.ground_colors.create( + FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2) + ) + @gp = @panel.ground_pictures.create( + FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 3) + ) + @panel.reload + end + context 'つつがなく終わるとき' do + before do + Panel.any_instance.stub(:elements).with(any_args).and_return({}) + end + it 'コマ要素のjson出力を依頼している' do + Panel.any_instance.should_receive(:elements).with(any_args).exactly(1) + r = @panel.panel_elements_as_json + end + end + it 'json textを返している' do + r = JSON.parse @panel.panel_elements_as_json + r.is_a?(Hash).should be_true + end + it 'author,コマ要素を含んでいる' do + r = JSON.parse @panel.panel_elements_as_json + r.has_key?('author').should be_true + r.has_key?('elements').should be_true + #t:0 + sb = r['elements'].first + sb.has_key?('classname').should be_true + sb.has_key?('balloon').should be_true + sb.has_key?('speech').should be_true + #t:1 + end + end + describe 'コマリストのjson出力に於いて' do + before do + @panel = FactoryGirl.create :panel, :author_id => @author.id + Panel.any_instance.stub(:panel_elements_as_json).with(any_args).and_return('{"p": 5}') + end + context 'つつがなく終わるとき' do + it 'コマのjson出力を依頼している' do + Panel.any_instance.should_receive(:panel_elements_as_json).with(any_args).exactly(1) + r = Panel.list_as_json_text [@panel] + end + end + it 'json textを返している' do + r = Panel.list_as_json_text [@panel] + j = JSON.parse r + j.is_a?(Array).should be_true + end + it 'コマを含んでいる' do + r = Panel.list_as_json_text [@panel] + j = JSON.parse r + j.first.has_key?('p').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 => 1, :width => @p.width, :height => @p.height, :picture_id => @p.id + @sb = @panel.speech_balloons.build( + FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0) + ) + @sb.build_balloon( + FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id) + ) + @sb.build_speech( + FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id) + ) + @sb.boost + @sb.save! + @gc = @panel.ground_colors.create( + FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2) + ) + @gp = @panel.ground_pictures.create( + FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p2.id, :t => 3) + ) + @panel.reload + end + context '事前チェック' do + end + context 'つつがなく終わるとき' do + end + it '連想配列(値は実素材、キーは実素材id)を返している' do + r = @panel.licensed_pictures + r.is_a?(Hash).should be_true + r.should have(2).items + r[@pp.picture_id].should eq @p + r[@gp.picture_id].should eq @p2 + end + end + + describe '検証値収集に於いて' do + context 'つつがなく終わるとき' do + it '第一パラメータで指定された配列中から第二引数のカラム値を収集している' do + elements = [[{:panel_id => 1, :a => 'a'}, {:panel_id => 2, :a => 'a'}], + [{:panel_id => 3, :a => 'a'}, {:panel_id => 4, :a => 'a'}]] + r = Panel.collect_element_value elements, :panel_id + r.should eq [1, 2, 3, 4] + end + it '第一パラメータで指定された配列中から第二引数のカラム値を収集している' do + elements = [[{:t => 1, :a => 'a'}, {:t => 2, :a => 'a'}], + [{:t => 3, :a => 'a'}, {:t => 0, :a => 'a'}]] + r = Panel.collect_element_value elements, :t + r.should eq [1, 2, 3, 0] + end + end + end + describe 'シリアライズチェックに於いて' do + context 'つつがなく終わるとき' do + it '0からシリアライズされているならTrueを返す' do + r = Panel.validate_serial [0, 1, 2] + r.should be_true + end + it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do + r = Panel.validate_serial [0, 2, 1] + r.should be_true + end + it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do + r = Panel.validate_serial [ 2, 1, 4, 3, 0] + r.should be_true + end + end + context 'オフセットが1のとき' do + it '0からシリアライズされているならFalseを返す' do + r = Panel.validate_serial [0, 1, 2], 1 + r.should be_false + end + it '1からシリアライズされているならTrueを返す' do + r = Panel.validate_serial [1, 2, 3], 1 + r.should be_true + end + end + context '異常なとき' do + it '0から始まらないならFalseを返す' do + r = Panel.validate_serial [1, 2, 3] + r.should be_false + end + it '連続していないならFalseを返す' do + r = Panel.validate_serial [0, 1, 2, 4] + r.should be_false + end + it '連続していないならFalseを返す' do + r = Panel.validate_serial [0, 1, 2, 4, 5] + r.should be_false + end + end + end + describe 'シリアライズチェック単体に於いて' do + before do + end + context 'つつがなく終わるとき' do + it '検証値収集を依頼している' do + Panel.should_receive(:collect_element_value).with(any_args).exactly(1) + Panel.stub(:collect_element_value).with(any_args).and_return([]) + Panel.stub(:validate_serial).with(any_args).and_return(true) + r = Panel.validate_element_serial [], :t + end + it 'シリアライズチェック依頼している' do + Panel.stub(:collect_element_value).with(any_args).and_return([]) + Panel.should_receive(:validate_serial).with(any_args).exactly(1) + Panel.stub(:validate_serial).with(any_args).and_return(true) + r = Panel.validate_element_serial [], :t + end + end + end + describe '従属データの検証に於いて' do + context 'つつがなく終わるとき' do + it 'trueを返している' do + @panel = FactoryGirl.build :panel, :author_id => @author.id + @panel.panel_pictures.build( + FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 0, :z => 0+1) + ) + @panel.panel_pictures.build( + FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 1, :z => 1+1) + ) + sb1 = @panel.speech_balloons.build( + FactoryGirl.attributes_for(:speech_balloon, :speech_balloon_template_id => @sbt.id, :t => 2, :z => 2+1) + ) + sb1.build_balloon( + FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id) + ) + sb1.build_speech( + FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id) + ) + sb1.boost + sb1.save! + sb2 = @panel.speech_balloons.build( + FactoryGirl.attributes_for(:speech_balloon, :speech_balloon_template_id => @sbt.id, :t => 3, :z => 3+1) + ) + sb2.build_balloon( + FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id) + ) + sb2.build_speech( + FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id) + ) + sb2.boost + sb2.save! + @gc = @panel.ground_colors.build( + FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 4, :z => 4+1) + ) + @gp = @panel.ground_pictures.build( + FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 5, :z => 5+1) + ) + r = @panel.validate_child + r.should be_true + end + end + context 'tシリアライズされていないとき' do + it 'falseを返している' do + @panel = FactoryGirl.build :panel, :author_id => @author.id + @panel.panel_pictures.build( + FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 0, :z => 0+1) + ) + @panel.panel_pictures.build( + FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 1, :z => 1+1) + ) + sb1 = @panel.speech_balloons.build( + FactoryGirl.attributes_for(:speech_balloon, :speech_balloon_template_id => @sbt.id, :t => 2, :z => 2+1) + ) + sb1.build_balloon( + FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id) + ) + sb1.build_speech( + FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id) + ) + sb1.boost + sb1.save! + sb2 = @panel.speech_balloons.build( + FactoryGirl.attributes_for(:speech_balloon, :speech_balloon_template_id => @sbt.id, :t => 4, :z => 3+1) + ) + sb2.build_balloon( + FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id) + ) + sb2.build_speech( + FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id) + ) + sb2.boost + sb2.save! + @gc = @panel.ground_colors.build( + FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 4, :z => 4+1) + ) + @gp = @panel.ground_pictures.build( + FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 5, :z => 5+1) + ) + r = @panel.validate_child + r.should be_false + end + end + context 'zシリアライズされていないとき' do + it 'falseを返している' do + @panel = FactoryGirl.build :panel, :author_id => @author.id + @panel.panel_pictures.build( + FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 0, :z => 0+1) + ) + @panel.panel_pictures.build( + FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 1, :z => 0+1) + ) + sb1 = @panel.speech_balloons.build( + FactoryGirl.attributes_for(:speech_balloon, :speech_balloon_template_id => @sbt.id, :t => 2, :z => 2+1) + ) + sb1.build_balloon( + FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id) + ) + sb1.build_speech( + FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id) + ) + sb1.boost + sb1.save! + sb2 = @panel.speech_balloons.build( + FactoryGirl.attributes_for(:speech_balloon, :speech_balloon_template_id => @sbt.id, :t => 3, :z => 3+1) + ) + sb2.build_balloon( + FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id) + ) + sb2.build_speech( + FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id) + ) + sb2.boost + sb2.save! + @gc = @panel.ground_colors.build( + FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 4, :z => 4+1) + ) + @gp = @panel.ground_pictures.build( + FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 5, :z => 5+1) + ) + r = @panel.validate_child + r.should be_false end end end - describe '関連テーブルプションに於いて' do - context 'オプションがないとき' do - it '4つの項目を含んでいる' do - r = Panel.show_include_opt - r.should have(4).items + describe '保存に於いて' do + before do + @attr = FactoryGirl.attributes_for :panel + @panel = Panel.new + @panel.supply_default + end + context 'つつがなく終わるとき' do + before do + Panel.any_instance.stub(:validate_child).with(any_args).and_return(true) + Panel.any_instance.stub(:save).with(any_args).and_return(true) end - it 'コミックを含んでいる' do - r = Panel.show_include_opt - r.has_key?(:comic).should be_true + it 'コマモデルに上書き補充を依頼している' do + Panel.any_instance.should_receive(:overwrite).exactly(1) + r = @panel.store @attr, @author end - it 'コマ絵を含んでいる' do - r = Panel.show_include_opt - r.has_key?(:panel_pictures).should be_true + it '保存を依頼している' do + Panel.any_instance.should_receive(:save).with(any_args).exactly(1) + @panel = FactoryGirl.build :panel, :author_id => @author.id + r = @panel.store @attr, @author end - it 'コマ絵は素材を含んでいる' do - r = Panel.show_include_opt - r[:panel_pictures].has_key?(:resource_picture).should be_true - end - it '素材は絵師を含んでいる' do - r = Panel.show_include_opt - r[:panel_pictures][:resource_picture].has_key?(:artist).should be_true - end - it '素材はライセンスを含んでいる' do - r = Panel.show_include_opt - r[:panel_pictures][:resource_picture].has_key?(:license).should be_true - end - it 'フキダシを含んでいる' do - r = Panel.show_include_opt - r.has_key?(:speech_balloons).should be_true - end - it 'フキダシはフキダシ枠を含んでいる' do - r = Panel.show_include_opt - r[:speech_balloons].has_key?(:balloons).should be_true - end - it 'フキダシはセリフを含んでいる' do - r = Panel.show_include_opt - r[:speech_balloons].has_key?(:speeches).should be_true - end - it '作家を含んでいる' do - r = Panel.show_include_opt - r.has_key?(:author).should be_true + it '従属データの検証を依頼している' do + Panel.any_instance.should_receive(:validate_child).with(any_args).exactly(1) + r = @panel.store @attr, @author end end - context 'オプションで原画を含ませたとき' do - it '5つの項目を含んでいる' do - r = Panel.show_include_opt(:include => {:test => {}}) - r.should have(5).items + context 'つつがなく終わるとき' do + before do + Panel.any_instance.stub(:validate_child).with(any_args).and_return(true) end - it 'testを含んでいる' do - r = Panel.show_include_opt(:include => {:test => {}}) - r.has_key?(:test).should be_true + it 'Trueを返す' do + r = @panel.store @attr, @author + r.should be_true end - end - end - describe 'json単体出力オプションに於いて' do - it 'includeキーを含んでいる' do - r = Panel.show_json_include_opt - r.has_key?(:include).should be_true - end - it '4つの項目を含んでいる' do - r = Panel.show_json_include_opt[:include] - r.should have(4).items - end - it 'コミックを含んでいる' do - r = Panel.show_json_include_opt[:include] - r.has_key?(:comic).should be_true - end - it 'コマ絵を含んでいる' do - r = Panel.show_json_include_opt[:include] - r.has_key?(:panel_pictures).should be_true - end - it 'コマ絵は素材を含んでいる' do - r = Panel.show_json_include_opt[:include] - r[:panel_pictures].has_key?(:resource_picture).should be_true + it '行が追加されている' do + Panel.any_instance.stub(:validate_child).with(any_args).and_return(true) + lambda { + r = @panel.store @attr, @author + }.should change(Panel, :count) end - it '素材は絵師を含んでいる' do - r = Panel.show_json_include_opt[:include] - r[:panel_pictures][:resource_picture].has_key?(:artist).should be_true - end - it '素材はライセンスを含んでいる' do - r = Panel.show_json_include_opt[:include] - r[:panel_pictures][:resource_picture].has_key?(:license).should be_true - end - it 'フキダシを含んでいる' do - r = Panel.show_include_opt - r.has_key?(:speech_balloons).should be_true end - it 'フキダシはフキダシ枠を含んでいる' do - r = Panel.show_include_opt - r[:speech_balloons].has_key?(:balloons).should be_true + context '不正なjsonデータのとき' do + before do end - it 'フキダシはセリフを含んでいる' do - r = Panel.show_include_opt - r[:speech_balloons].has_key?(:speeches).should be_true + it 'エラーメッセージがセットされている' do + r = @panel.store false, @author + @panel.errors[:base].should_not be_blank end - it '作家を含んでいる' do - r = Panel.show_json_include_opt[:include] - r.has_key?(:author).should be_true - end - end - describe '一覧取得に於いて' do - before do - @comic = Factory :comic, :author_id => @author.id - @panel = Factory :panel, :comic_id => @comic.id, :author_id => @author.id end - context 'page補正について' do - it '文字列から数値に変換される' do - Panel.page('8').should eq 8 - end - it 'nilの場合は1になる' do - Panel.page().should eq 1 + context '従属データの検証に失敗したとき' do + before do + Panel.any_instance.stub(:save).with(any_args).and_return(true) + Panel.any_instance.stub(:validate_child).with(any_args).and_return(false) end - it '0以下の場合は1になる' do - Panel.page('0').should eq 1 + it 'エラーメッセージがセットされている' do + r = @panel.store @attr, @author + @panel.errors[:base].should_not be_blank end end - context 'page_size補正について' do - it '文字列から数値に変換される' do - Panel.page_size('7').should eq 7 - end - it 'nilの場合はPanel.default_page_sizeになる' do - Panel.page_size().should eq Panel.default_page_size - end - it '0以下の場合はPanel.default_page_sizeになる' do - Panel.page_size('0').should eq Panel.default_page_size + context 'カラム値がFalseしたとき' do + before do + Panel.any_instance.stub(:validate_child).with(any_args).and_return(true) end - it 'Panel.max_page_sizeを超えた場合はPanel.max_page_sizeになる' do - Panel.page_size('1000').should eq Panel.max_page_size + it 'エラーメッセージがセットされている' do + r = @panel.store false, @author + @panel.errors.should_not be_empty end end - it 'リストを返す' do - pl = Panel.list - pl.should eq [@panel] - end - it '時系列で並んでいる' do - npl = Factory :panel, :comic_id => @comic.id, :author_id => @author.id, :t => 1, :updated_at => Time.now + 100 - pl = Panel.list - pl.should eq [npl, @panel] - end - context 'DBに5件あって1ページの件数を2件に変えたとして' do + end + + describe '要素の検証に於いて' do + before do + @panel = Panel.new + @panel.supply_default + @attr = FactoryGirl.attributes_for :panel +@sbattr = { + "speech_balloons_attributes" => { + "0" => { + "caption" => "大きな文字で","z" => "1","t" => "0", + "classname" => "CircleSpeechBalloon","speech_balloon_template_id" => @sbt.id, + "speech_attributes" => { + "content" => "カギッコ","x" => "20","y" => "20","width" => "-60","height" => "60", + "settings" => "","writing_format_id" => @writing_format.id + }, + "balloon_attributes" => { + "r" => "247","x" => "293","y" => "-2","width" => "200","height" => "200", + "system_picture_id" => @sp.id,"settings" => "" + } + } + }, + "publish" => "0" +} +@ppattr = { + "panel_pictures_attributes" => { + "4" => { + "caption" => "司会","x" => "a","y" => "99","z" => "1","t" => "0", + "width" => "156","height" => "245","link" => "","picture_id" => @p.id + } + }, + "publish" => "0" +} + end + context 'フキダシの幅がマイナスで検証に失敗したとき' do before do - @npl2 = Factory :panel, :comic_id => @comic.id, :author_id => @author.id, :t => 1, :updated_at => Time.now + 100 - @npl3 = Factory :panel, :comic_id => @comic.id, :author_id => @author.id, :t => 2, :updated_at => Time.now + 200 - @npl4 = Factory :panel, :comic_id => @comic.id, :author_id => @author.id, :t => 3, :updated_at => Time.now + 300 - @npl5 = Factory :panel, :comic_id => @comic.id, :author_id => @author.id, :t => 4, :updated_at => Time.now + 400 - Panel.stub(:default_page_size).and_return(2) - end - it '通常は2件を返す' do - pl = Panel.list - pl.should have(2).items + @attr.merge!(@sbattr) end - it 'page=1なら末尾2件を返す' do - #時系列で並んでいる - pl = Panel.list( {}, 1) - pl.should eq [@npl5, @npl4] + it 'エラーメッセージがセットされている' do + r = @panel.store @attr, @author + r.should be_false + @panel.errors.should_not be_empty end - it 'page=2なら中間2件を返す' do - pl = Panel.list({}, 2) - pl.should eq [@npl3, @npl2] + end + context 'コマ絵の横軸はアルファベットのため検証に失敗したとき' do + before do + @attr.merge!(@ppattr) end - it 'page=3なら先頭1件を返す' do - pl = Panel.list({}, 3) - pl.should eq [@panel] + it 'エラーメッセージがセットされている' do + r = @panel.store @attr, @author + r.should be_false + @panel.errors.should_not be_empty end end end - describe 'list関連テーブルプションに於いて' do - it 'includeキーを含んでいる' do - r = Panel.list_opt - r.has_key?(:include).should be_true - end - it '4つの項目を含んでいる' do - r = Panel.list_opt[:include] - r.should have(4).items - end - it 'コミックを含んでいる' do - r = Panel.list_opt[:include] - r.has_key?(:comic).should be_true - end - it 'コマ絵を含んでいる' do - r = Panel.list_opt[:include] - r.has_key?(:panel_pictures).should be_true + + describe '削除に於いて' do + before do + @scroll = FactoryGirl.create :scroll, :author_id => @author.id + @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1 + @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height + @sb = @panel.speech_balloons.build( + FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0) + ) + @sb.build_balloon( + FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id) + ) + @sb.build_speech( + FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id) + ) + @sb.boost + @sb.save! + @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) + ) end - it 'コマ絵は素材を含んでいる' do - r = Panel.list_opt[:include] - r[:panel_pictures].has_key?(:resource_picture).should be_true + context 'つつがなく終わるとき' do + it '自身を削除する' do + lambda { + r = @panel.destroy_with_elements + }.should change(Panel, :count).by(-1) + lambda { + r = Panel.find @panel.id + }.should raise_error end - it '素材は絵師を含んでいる' do - r = Panel.list_opt[:include] - r[:panel_pictures][:resource_picture].has_key?(:artist).should be_true - end - it '素材はライセンスを含んでいる' do - r = Panel.list_opt[:include] - r[:panel_pictures][:resource_picture].has_key?(:license).should be_true - end - it 'フキダシを含んでいる' do - r = Panel.show_include_opt - r.has_key?(:speech_balloons).should be_true - end - it 'フキダシはフキダシ枠を含んでいる' do - r = Panel.show_include_opt - r[:speech_balloons].has_key?(:balloons).should be_true + it '自身にリンクしているコマ要素をすべて削除する' do + lambda { + r = @panel.destroy_with_elements + }.should change(PanelPicture, :count).by(-1) + lambda { + r = PanelPicture.find @pp.id + }.should raise_error end - it 'フキダシはセリフを含んでいる' do - r = Panel.show_include_opt - r[:speech_balloons].has_key?(:speeches).should be_true + it '自身にリンクしているコマ要素をすべて削除する' do + lambda { + r = @panel.destroy_with_elements + }.should change(GroundPicture, :count).by(-1) + lambda { + r = GroundPicture.find @gp.id + }.should raise_error end - it '作家を含んでいる' do - r = Panel.list_opt[:include] - r.has_key?(:author).should be_true - end - end - describe 'json一覧出力オプションに於いて' do - it 'includeキーを含んでいる' do - r = Panel.list_json_opt - r.has_key?(:include).should be_true - end - it '4つの項目を含んでいる' do - r = Panel.list_json_opt[:include] - r.should have(4).items - end - it 'コミックを含んでいる' do - r = Panel.list_json_opt[:include] - r.has_key?(:comic).should be_true - end - it 'コマ絵を含んでいる' do - r = Panel.list_json_opt[:include] - r.has_key?(:panel_pictures).should be_true - end - it 'コマ絵は素材を含んでいる' do - r = Panel.list_json_opt[:include] - r[:panel_pictures].has_key?(:resource_picture).should be_true + it 'Trueを返す' do + r = @panel.destroy_with_elements + r.should be_true end - it '素材は絵師を含んでいる' do - r = Panel.list_json_opt[:include] - r[:panel_pictures][:resource_picture].has_key?(:artist).should be_true - end - it '素材はライセンスを含んでいる' do - r = Panel.list_json_opt[:include] - r[:panel_pictures][:resource_picture].has_key?(:license).should be_true - end - it 'フキダシを含んでいる' do - r = Panel.show_include_opt - r.has_key?(:speech_balloons).should be_true end - it 'フキダシはフキダシ枠を含んでいる' do - r = Panel.show_include_opt - r[:speech_balloons].has_key?(:balloons).should be_true + context '削除に失敗したとき' do + before do + PanelPicture.any_instance.stub(:destroy).with(any_args).and_return(false) end - it 'フキダシはセリフを含んでいる' do - r = Panel.show_include_opt - r[:speech_balloons].has_key?(:speeches).should be_true + it 'Falseを返す' do + r = @panel.destroy_with_elements + r.should be_false end - it '作家を含んでいる' do - r = Panel.list_json_opt[:include] - r.has_key?(:author).should be_true - end - end - - #異常データ検出 - #コマはコミックに従属しなくなったのでtで入れ替えるチェックは要らなくなった - #コマ絵とフキダシの整合チェックをする - describe 'id収集に於いて' do - context 'つつがなく終わるとき' do - it '第一パラメータで指定された配列中から第二引数のidを収集している' do - a = [[{:panel_id => 1, :a => 'a'}, {:panel_id => 2, :a => 'a'}], - [{:panel_id => 3, :a => 'a'}, {:panel_id => 4, :a => 'a'}]] - r = Panel.collect_element_value a, :panel_id - r.should eq [1, 2, 3, 4] + it 'ロールバックしている' do + lambda { + r = @panel.destroy_with_elements + }.should_not change(Panel, :count) + lambda { + r = @panel.destroy_with_elements + }.should_not change(PanelPicture, :count) end end - context 'Nil除外指示があるとき' do - it '収集したpanel_idのうちnilは除外している' do - a = [[{:panel_id => 1, :a => 'a'}, {:panel_id => 2, :a => 'a'}, {:panel_id => nil, :a => 'a'}], - [{:panel_id => 3, :a => 'a'}, {:panel_id => nil, :a => 'a'}, {:panel_id => 4, :a => 'a'}]] - r = Panel.collect_element_value a, :panel_id, true - r.should eq [1, 2, 3, 4] - end + end +=begin + describe 'id挿げ替え防止確認に於いて' 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 + end + it 'author,コマ要素を含んでいる' do + @panel2 = FactoryGirl.create :panel, :author_id => @author.id + @panel2.panel_pictures.create( + FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height) + ) + @panel2.save! end end describe 'id一致チェックに於いて' do @@ -695,7 +1501,7 @@ describe Panel do end describe 'idチェック単体に於いて' do before do -# @pp = Factory :panel_picture, :panel_id => @panel.id, :t => 1 +# @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1 end context 'つつがなく終わるとき' do it 'idを収集依頼している' do @@ -715,17 +1521,17 @@ describe Panel do #依頼チェックだけでは不安なので最低限のチェックを context 'コマ新規のとき' do it 'コマ絵で正常通過している' do - @panel = Factory.build :panel, :author_id => @author.id + @panel = FactoryGirl.build :panel, :author_id => @author.id @panel.panel_pictures.build( - Factory.attributes_for(:panel_picture, :panel_id => nil, :resource_picture_id => @rp.id, :t => nil) + FactoryGirl.attributes_for(:panel_picture, :panel_id => nil, :picture_id => @p.id, :t => nil) ) r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id r.should be_true end it 'フキダシで正常通過している' do - @panel = Factory.build :panel, :author_id => @author.id + @panel = FactoryGirl.build :panel, :author_id => @author.id @panel.speech_balloons.build( - Factory.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id) + FactoryGirl.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id) ) r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id r.should be_true @@ -733,17 +1539,17 @@ describe Panel do end context 'コマ既存のとき' do it 'コマ絵で正常通過している' do - @panel = Factory :panel, :author_id => @author.id + @panel = FactoryGirl.create :panel, :author_id => @author.id @panel.panel_pictures.build( - Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => nil) + FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => nil) ) r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id r.should be_true end it 'フキダシで正常通過している' do - @panel = Factory :panel, :author_id => @author.id + @panel = FactoryGirl.create :panel, :author_id => @author.id @panel.speech_balloons.build( - Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id) + FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id) ) r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id r.should be_true @@ -751,23 +1557,23 @@ describe Panel do end context 'フキダシ新規のとき' do it 'バルーンで正常通過している' do - @panel = Factory.build :panel, :author_id => @author.id + @panel = FactoryGirl.build :panel, :author_id => @author.id @panel.speech_balloons.build( - Factory.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id) + FactoryGirl.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id) ) @panel.speech_balloons.first.balloons.build( - Factory.attributes_for(:balloon, :speech_balloon_id => nil) + FactoryGirl.attributes_for(:balloon, :speech_balloon_id => nil) ) r = Panel.validate_element_id [@panel.speech_balloons.first.speeches, @panel.speech_balloons.first.balloons], :speech_balloon_id, @panel.speech_balloons.first.id r.should be_true end it 'セリフで正常通過している' do - @panel = Factory.build :panel, :author_id => @author.id + @panel = FactoryGirl.build :panel, :author_id => @author.id @panel.speech_balloons.build( - Factory.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id) + FactoryGirl.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id) ) @panel.speech_balloons.first.speeches.build( - Factory.attributes_for(:speech, :speech_balloon_id => nil) + FactoryGirl.attributes_for(:speech, :speech_balloon_id => nil) ) r = Panel.validate_element_id [@panel.speech_balloons.first.speeches, @panel.speech_balloons.first.balloons], :speech_balloon_id, @panel.speech_balloons.first.id r.should be_true @@ -776,46 +1582,46 @@ describe Panel do end describe 'idチェックリスト生成に於いて' do before do - @panel = Factory.build :panel, :author_id => @author.id + @panel = FactoryGirl.build :panel, :author_id => @author.id end context 'つつがなく終わるとき' do it 'コマ部品とフキダシ部品のトータル2を返す' do @panel.panel_pictures.build( - Factory.attributes_for(:panel_picture, :panel_id => nil, :resource_picture_id => @rp.id, :t => nil) + FactoryGirl.attributes_for(:panel_picture, :panel_id => nil, :picture_id => @p.id, :t => nil) ) @panel.speech_balloons.build( - Factory.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id) + FactoryGirl.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id) ) @panel.speech_balloons.first.balloons.build( - Factory.attributes_for(:balloon, :speech_balloon_id => nil) + FactoryGirl.attributes_for(:balloon, :speech_balloon_id => nil) ) @panel.speech_balloons.first.speeches.build( - Factory.attributes_for(:speech, :speech_balloon_id => nil) + FactoryGirl.attributes_for(:speech, :speech_balloon_id => nil) ) r = @panel.validate_id_list r.should have(2).items end it 'コマ部品とフキダシ部品[複数:2]のケースでトータル3を返す' do @panel.panel_pictures.build( - Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => nil) + FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => nil) ) sb1 = @panel.speech_balloons.build( - Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id) + FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id) ) sb1.balloons.build( - Factory.attributes_for(:balloon, :speech_balloon_id => sb1.id) + FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id) ) sb1.speeches.build( - Factory.attributes_for(:speech, :speech_balloon_id => sb1.id) + FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id) ) sb2 = @panel.speech_balloons.build( - Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id) + FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id) ) sb2.balloons.build( - Factory.attributes_for(:balloon, :speech_balloon_id => sb2.id) + FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb2.id) ) sb2.speeches.build( - Factory.attributes_for(:speech, :speech_balloon_id => sb2.id) + FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb2.id) ) r = @panel.validate_id_list r.should have(3).items @@ -824,145 +1630,27 @@ describe Panel do end describe 'idチェック複合に於いて' do before do - @panel = Factory.build :panel, :author_id => @author.id + @panel = FactoryGirl.build :panel, :author_id => @author.id end context 'つつがなく終わるとき' do it 'コマ部品とフキダシ部品の二回チェック依頼している' do Panel.should_receive(:validate_element_id).with(any_args).exactly(2) Panel.stub(:validate_element_id).with(any_args).and_return(true) @panel.panel_pictures.build( - Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => nil) + FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => nil) ) sb1 = @panel.speech_balloons.build( - Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id) + FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id) ) sb1.balloons.build( - Factory.attributes_for(:balloon, :speech_balloon_id => sb1.id) + FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id) ) sb1.speeches.build( - Factory.attributes_for(:speech, :speech_balloon_id => sb1.id) + FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id) ) r = Panel.validate_elements_id(@panel.validate_id_list) end end end - describe 'シリアライズチェックに於いて' do - context 'つつがなく終わるとき' do - it '0からシリアライズされているならTrueを返す' do - r = Panel.validate_t [0, 1, 2] - r.should be_true - end - it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do - r = Panel.validate_t [0, 2, 1] - r.should be_true - end - it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do - r = Panel.validate_t [ 2, 1, 4, 3, 0] - r.should be_true - end - end - context '異常なとき' do - it '0から始まらないならFalseを返す' do - r = Panel.validate_t [1, 2, 3] - r.should be_false - end - it '連続していないならFalseを返す' do - r = Panel.validate_t [0, 1, 2, 4] - r.should be_false - end - it '連続していないならFalseを返す' do - r = Panel.validate_t [0, 1, 2, 4, 5] - r.should be_false - end - end - end - describe 'tチェック単体に於いて' do - before do - end - context 'つつがなく終わるとき' do - it 'コマ絵とフキダシのtを収集依頼している' do - Panel.should_receive(:collect_element_value).with(any_args).exactly(1) - Panel.stub(:collect_element_value).with(any_args).and_return([]) - Panel.stub(:validate_t).with(any_args).and_return(true) - r = Panel.validate_element_t [], :t - end - it '収集したtをシリアライズチェック依頼している' do - Panel.stub(:collect_element_value).with(any_args).and_return([]) - Panel.should_receive(:validate_t).with(any_args).exactly(1) - Panel.stub(:validate_t).with(any_args).and_return(true) - r = Panel.validate_element_t [], :t - end - end - #実データでチェック - #依頼チェックだけでは不安なので最低限のチェックを - context '新規のとき' do - it 'コマ絵で正常通過している' do - @panel = Factory.build :panel, :author_id => @author.id - @panel.panel_pictures.build( - Factory.attributes_for(:panel_picture, :panel_id => nil, :resource_picture_id => @rp.id, :t => nil) - ) - r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t - r.should be_true - end - it 'フキダシで正常通過している' do - @panel = Factory.build :panel, :author_id => @author.id - @panel.speech_balloons.build( - Factory.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id, :t => nil) - ) - r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t - r.should be_true - end - end - context '既存のとき' do - it 'コマ絵で正常通過している' do - @panel = Factory :panel, :author_id => @author.id - @panel.panel_pictures.build( - Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => 0) - ) - r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t - r.should be_true - end - it 'フキダシで正常通過している' do - @panel = Factory :panel, :author_id => @author.id - @panel.speech_balloons.build( - Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0) - ) - r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t - r.should be_true - end - end - end - describe '複合チェックに於いて' do - context 'つつがなく終わるとき' do - it 'している' do - @panel = Factory.build :panel, :author_id => @author.id - @panel.panel_pictures.build( - Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => 0) - ) - @panel.panel_pictures.build( - Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => 1) - ) - sb1 = @panel.speech_balloons.build( - Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2) - ) - sb1.balloons.build( - Factory.attributes_for(:balloon, :speech_balloon_id => sb1.id) - ) - sb1.speeches.build( - Factory.attributes_for(:speech, :speech_balloon_id => sb1.id) - ) - sb2 = @panel.speech_balloons.build( - Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 3) - ) - sb2.balloons.build( - Factory.attributes_for(:balloon, :speech_balloon_id => sb2.id) - ) - sb2.speeches.build( - Factory.attributes_for(:speech, :speech_balloon_id => sb2.id) - ) - r = @panel.validate_child - r.should be_true - end - end - end +=end end