X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=spec%2Fmodels%2Fpanel_spec.rb;h=002f9dd18037a057ef65ff18699a22e6a36fe96f;hb=9f6a95c6c89ca7d7671fa019f122e31215aa1bcd;hp=76996f972eb34859841e592e03315354effdb11a;hpb=809beb5cd929c25f2d0ea1c3edd536d8d682c3a4;p=pettanr%2Fpettanr.git diff --git a/spec/models/panel_spec.rb b/spec/models/panel_spec.rb index 76996f97..002f9dd1 100644 --- a/spec/models/panel_spec.rb +++ b/spec/models/panel_spec.rb @@ -3,46 +3,52 @@ require 'spec_helper' #コマ describe Panel do before do - Factory :admin - @license = Factory :license - @user = Factory( :user_yas) + FactoryGirl.create :admin + @sp = FactoryGirl.create :system_picture + @lg = FactoryGirl.create :license_group + @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id + @color = FactoryGirl.create :color + @user = FactoryGirl.create( :user_yas) @author = @user.author - @artist = Factory :artist_yas, :author_id => @author.id - @other_user = Factory( :user_yas) + @artist = FactoryGirl.create :artist_yas, :author_id => @author.id + @other_user = FactoryGirl.create( :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 + @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 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 - end - it 'テストデータの確認' do - @panel.comic_id = @comic.id - @panel.should be_valid - end - end + context 'オーソドックスなデータのとき' do + it '下限データが通る' do + @panel.width = 1 + @panel.height = 1 + @panel.border = 0 + @panel.x = -99999 + @panel.y = -99999 + @panel.z = 1 + @panel.publish = 0 + @panel.should be_valid + end + it '上限データが通る' do + @panel.width = 99999 + @panel.height = 99999 + @panel.border = 99999 + @panel.x = 99999 + @panel.y = 99999 + @panel.z = 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 +67,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 +85,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 @@ -111,13 +103,6 @@ describe Panel do 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 - end it '数値でなければ失敗する' do @panel.x = 'a' @panel.should_not be_valid @@ -132,13 +117,6 @@ describe Panel do 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 it '数値でなければ失敗する' do @panel.y = 'a' @panel.should_not be_valid @@ -153,13 +131,6 @@ describe Panel do end end context 'zを検証するとき' do - before do - @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id - end - it 'テストデータの確認' do - @panel.z = '1' - @panel.should be_valid - end it '数値でなければ失敗する' do @panel.z = 'a' @panel.should_not be_valid @@ -173,35 +144,7 @@ describe Panel do @panel.should_not be_valid end end - context 'tを検証するとき' do - before do - @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id - end - it 'テストデータの確認' do - @panel.t = '1' - @panel.should be_valid - end - it '数値でなければ失敗する' do - @panel.t = 'a' - @panel.should_not be_valid - end - it '0なら通る' do - @panel.t = '0' - @panel.should be_valid - end - it '負でも失敗する' do - @panel.t = -1 - @panel.should_not be_valid - end - end context 'author_idを検証するとき' do - before do - @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id - end - it 'テストデータの確認' do - @panel.author_id = @author.id - @panel.should be_valid - end it 'nullなら失敗する' do @panel.author_id = nil @panel.should_not be_valid @@ -210,104 +153,48 @@ describe Panel do @panel.author_id = 'a' @panel.should_not be_valid end - it '存在する絵師でなければ失敗する' do + it '存在する作家でなければ失敗する' do @panel.author_id = 0 @panel.should_not be_valid end end + context '公開フラグを検証するとき' do + it '数値でなければ失敗する' do + @panel.publish = 'a' + @panel.should_not be_valid + end + end context '全体を検証するとき' do before do - @panel = Factory :panel, :author_id => @author.id, :comic_id => @comic.id + @panel = FactoryGirl.create :panel, :author_id => @author.id end end end - describe 'データ補充に於いて' do + describe 'デフォルト値補充に於いて' do before do - @comic = Factory :comic, :author_id => @author.id - @panel = Factory.build :panel, :comic_id => @comic.id - end - context 'widthを補充' do - it '空の時はコミックから補充する' do - @panel.width = nil - @panel.supply_default @author - @panel.width.should eq @comic.width - end - it '空の時でもコミックが不在なら補充しない' do - @panel.width = nil - @panel.comic_id = nil - @panel.supply_default @author - @panel.width.should be_nil - end - it '空でない時は変化しない' do - @panel.width = 45 - lambda { - @panel.supply_default @author - }.should_not change @panel, :width - end + @panel = FactoryGirl.build :panel, :author_id => @author.id end - context 'heightを補充' do - it '空の時はコミックから補充する' do - @panel.height = nil - @panel.supply_default @author - @panel.height.should eq @comic.height - end - it '空の時でもコミックが不在なら補充しない' do - @panel.height = nil - @panel.comic_id = nil - @panel.supply_default @author - @panel.height.should be_nil - end - it '空でない時は変化しない' do - @panel.height = 87 - lambda { - @panel.supply_default @author - }.should_not change @panel, :height - end + it 'borderは2を補充する' do + @panel.border = nil + @panel.supply_default + @panel.border.should eq 2 end - context 'borderを補充' do - it '空の時は0を補充する' do - @panel.border = nil - @panel.supply_default @author - @panel.border.should eq 0 - end - it '空でない時は変化しない' do - @panel.border = 1 - lambda { - @panel.supply_default @author - }.should_not change @panel, :border - end + it 'publishは0を補充する' do + @panel.publish = nil + @panel.supply_default + @panel.publish.should eq 0 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 - end - it '空でコミック初のコマなら0を補充する' do - @panel.t = nil - @panel.supply_default @author - @panel.t.should eq 0 - 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 - end - it '空でない時は変化しない' do - @panel.t = 1 - lambda { - @panel.supply_default @author - }.should_not change @panel, :t - 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.supply_default @author + @panel.overwrite @author @panel.author_id.should eq @author.id end end @@ -316,176 +203,53 @@ describe Panel do describe '作者判定に於いて' do before do - @comic = Factory :comic, :author_id => @author.id end it '自作のコマならyes' do - panel = Factory :panel, :author_id => @author.id, :comic_id => @comic.id + panel = FactoryGirl.create :panel, :author_id => @author.id panel.own?(@author).should == true end it '他人のコマならno' do - panel = Factory :panel, :author_id => @other_author.id, :comic_id => @comic.id - panel.own?(@author).should == false + panel = FactoryGirl.create :panel, :author_id => @author.id + panel.own?(@other_author).should == false end it '作家が不明ならno' do - panel = Factory :panel, :author_id => @author.id, :comic_id => @comic.id + panel = FactoryGirl.create :panel, :author_id => @author.id panel.own?(nil).should == false end end + describe '閲覧許可に於いて' do before do - @comic = Factory :comic, :author_id => @author.id end - it '自作の公開コミックのコマを見るときは許可する' do - Comic.any_instance.stub(:visible?).and_return(true) - panel = Factory :panel, :author_id => @author.id, :comic_id => @comic.id + it '自作のコマを見るときは許可する' do + Panel.any_instance.stub(:own?).and_return(true) + Panel.any_instance.stub(:publish?).and_return(true) + panel = FactoryGirl.create :panel, :author_id => @author.id panel.visible?(@author).should == true end - it '自作のコマは非公開コミックでも許可する' do - Comic.any_instance.stub(:visible?).and_return(false) - panel = Factory :panel, :author_id => @author.id, :comic_id => @comic.id + it '自作のコマは非公開でも許可する' do + Panel.any_instance.stub(:own?).and_return(true) + Panel.any_instance.stub(:publish?).and_return(false) + panel = FactoryGirl.create :panel, :author_id => @author.id panel.visible?(@author).should == true end - it '他人のコマでも公開コミックなら許可する' do - Comic.any_instance.stub(:visible?).and_return(true) - panel = Factory :panel, :author_id => @other_author.id, :comic_id => @comic.id + it '他人のコマでも公開なら許可する' do + Panel.any_instance.stub(:own?).and_return(false) + Panel.any_instance.stub(:publish?).and_return(true) + panel = FactoryGirl.create :panel, :author_id => @author.id panel.visible?(@author).should == true end - it '他人のコマで非公開コミックなら許可しない' do - Comic.any_instance.stub(:visible?).and_return(false) - panel = Factory :panel, :author_id => @other_author.id, :comic_id => @comic.id + it '他人のコマで非公開なら許可しない' do + Panel.any_instance.stub(:own?).and_return(false) + Panel.any_instance.stub(:publish?).and_return(false) + panel = FactoryGirl.create :panel, :author_id => @author.id panel.visible?(@author).should == false 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 - it '指定のコマを返す' do - Comic.any_instance.stub(:visible?).and_return(true) - pl = Panel.show @panel.id, @author - pl.should eq @panel - end - context '他人の非公開コミックのコマを開こうとしたとき' do - it '403Forbidden例外を返す' do - Panel.any_instance.stub(:visible?).and_return(false) - lambda{ - Panel.show @panel.id, @author - }.should raise_error(ActiveRecord::Forbidden) - end - end - context '存在しないコマを開こうとしたとき' do - it '404RecordNotFound例外を返す' do - lambda{ - Panel.show 110, @author - }.should raise_error(ActiveRecord::RecordNotFound) - end - end - end - describe '関連テーブルプションに於いて' do - context 'オプションがないとき' do - it '4つの項目を含んでいる' do - r = Panel.show_include_opt - r.should have(4).items - end - it 'コミックを含んでいる' do - r = Panel.show_include_opt - r.has_key?(:comic).should be_true - end - it 'コマ絵を含んでいる' do - r = Panel.show_include_opt - r.has_key?(:panel_pictures).should be_true - 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 - end - end - context 'オプションで原画を含ませたとき' do - it '5つの項目を含んでいる' do - r = Panel.show_include_opt(:include => {:test => {}}) - r.should have(5).items - end - it 'testを含んでいる' do - r = Panel.show_include_opt(:include => {:test => {}}) - r.has_key?(:test).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 - 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 - end - it 'フキダシはセリフを含んでいる' do - r = Panel.show_include_opt - r[:speech_balloons].has_key?(:speeches).should be_true - 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 + @panel = FactoryGirl.create :panel, :author_id => @author.id end context 'page補正について' do it '文字列から数値に変換される' do @@ -513,20 +277,26 @@ describe Panel do end end it 'リストを返す' do - pl = Panel.list - pl.should eq [@panel] + r = Panel.list + r.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] + #公開コミックは(他人のコミックであっても)含んでいる + 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 = 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 + @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 '通常は2件を返す' do @@ -535,131 +305,799 @@ describe Panel do end it 'page=1なら末尾2件を返す' do #時系列で並んでいる - pl = Panel.list( {}, 1) + pl = Panel.list 1 pl.should eq [@npl5, @npl4] end it 'page=2なら中間2件を返す' do - pl = Panel.list({}, 2) + pl = Panel.list 2 pl.should eq [@npl3, @npl2] end it 'page=3なら先頭1件を返す' do - pl = Panel.list({}, 3) + pl = Panel.list 3 pl.should eq [@panel] end 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 '件数0は全件(5件)を返す' do + r = Panel.list 5, 0 + r.should have(5).items + 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 + it '6つの項目を含んでいる' do r = Panel.list_opt[:include] - r.has_key?(:comic).should be_true + r.should have(6).items end it 'コマ絵を含んでいる' do r = Panel.list_opt[:include] r.has_key?(:panel_pictures).should be_true end - it 'コマ絵は素材を含んでいる' do + it 'コマ絵は実素材を含んでいる' do r = Panel.list_opt[:include] - r[:panel_pictures].has_key?(:resource_picture).should be_true + r[:panel_pictures].has_key?(:picture).should be_true end - it '素材は絵師を含んでいる' do + it '実素材は絵師を含んでいる' do r = Panel.list_opt[:include] - r[:panel_pictures][:resource_picture].has_key?(:artist).should be_true + r[:panel_pictures][:picture].has_key?(:artist).should be_true end - it '素材はライセンスを含んでいる' do + it '実素材はライセンスを含んでいる' do r = Panel.list_opt[:include] - r[:panel_pictures][:resource_picture].has_key?(:license).should be_true + r[:panel_pictures][:picture].has_key?(:license).should be_true end it 'フキダシを含んでいる' do - r = Panel.show_include_opt + r = Panel.list_opt[:include] r.has_key?(:speech_balloons).should be_true end it 'フキダシはフキダシ枠を含んでいる' do - r = Panel.show_include_opt + r = Panel.list_opt[:include] r[:speech_balloons].has_key?(:balloons).should be_true end it 'フキダシはセリフを含んでいる' do - r = Panel.show_include_opt + r = Panel.list_opt[:include] r[:speech_balloons].has_key?(:speeches).should be_true end + it '景色画像を含んでいる' do + r = Panel.list_opt[:include] + r.has_key?(:ground_pictures).should be_true + end + it '景色画像は実素材を含んでいる' do + r = Panel.list_opt[:include] + r[:ground_pictures].has_key?(:picture).should be_true + end + it '実素材は絵師を含んでいる' do + r = Panel.list_opt[:include] + r[:ground_pictures][:picture].has_key?(:artist).should be_true + end + it '実素材はライセンスを含んでいる' do + r = Panel.list_opt[:include] + r[:ground_pictures][:picture].has_key?(:license).should be_true + end + it '間接色を含んでいる' do + r = Panel.list_opt[:include] + r.has_key?(:ground_colors).should be_true + end + it '間接色は色を含んでいる' do + r = Panel.list_opt[:include] + r[:ground_colors].has_key?(:color).should be_true + end + it '景色を含んでいる' do + r = Panel.list_opt[:include] + r.has_key?(:panel_colors).should be_true + end it '作家を含んでいる' do r = Panel.list_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 + end + it 'リストを返す' do + pl = Panel.mylist @author + pl.should eq [@panel] + end + 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 '通常は2件を返す' do + pl = Panel.list 1, 2 + pl.should have(2).items + end + it 'page=1なら末尾2件を返す' do + #時系列で並んでいる + pl = Panel.mylist @author, 1, 2 + pl.should eq [@npl5, @npl4] + end + 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 'DBに5件あって1ページの件数を0件に変えたとして' 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 '通常は全件(5件)を返す' do + r = Panel.mylist @author, 5, 0 + r.should have(5).items + 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.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 + Panel.any_instance.stub(:visible?).and_return(true) + pl = Panel.show @panel.id, @author + pl.should eq @panel + end + context '閲覧許可が出なかったとき' do + it '403Forbidden例外を返す' do + Panel.any_instance.stub(:visible?).and_return(false) + lambda{ + Panel.show @panel.id, @author + }.should raise_error(ActiveRecord::Forbidden) + end + end + 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.list_json_opt + r = Panel.show_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 + it '6つの項目を含んでいる' do + r = Panel.show_opt[:include] + r.should have(6).items end it 'コマ絵を含んでいる' do - r = Panel.list_json_opt[:include] + r = Panel.show_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 'コマ絵は実素材を含んでいる' do + r = Panel.show_opt[:include] + r[:panel_pictures].has_key?(:picture).should be_true end - it '素材は絵師を含んでいる' do - r = Panel.list_json_opt[:include] - r[:panel_pictures][:resource_picture].has_key?(:artist).should be_true + it '実素材は絵師を含んでいる' do + r = Panel.show_opt[:include] + r[:panel_pictures][: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 + it '実素材はライセンスを含んでいる' do + r = Panel.show_opt[:include] + r[:panel_pictures][:picture].has_key?(:license).should be_true end it 'フキダシを含んでいる' do - r = Panel.show_include_opt + r = Panel.show_opt[:include] r.has_key?(:speech_balloons).should be_true end it 'フキダシはフキダシ枠を含んでいる' do - r = Panel.show_include_opt + r = Panel.show_opt[:include] r[:speech_balloons].has_key?(:balloons).should be_true end it 'フキダシはセリフを含んでいる' do - r = Panel.show_include_opt + r = Panel.show_opt[:include] r[:speech_balloons].has_key?(:speeches).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[:ground_colors].has_key?(:color).should be_true + end + it '景色を含んでいる' do + r = Panel.show_opt[:include] + r.has_key?(:panel_colors).should be_true + end it '作家を含んでいる' do - r = Panel.list_json_opt[:include] + r = Panel.show_opt[:include] r.has_key?(:author).should be_true end end - - #異常データ検出 - #コマはコミックに従属しなくなったのでtで入れ替えるチェックは要らなくなった - #コマ絵とフキダシの整合チェックをする - describe 'id収集に於いて' do + 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.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 'リストを返している' 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 + end + it '景色素材と景色カラーと景色カラーコードを含んでいない' do + r = @panel.parts_element + r.include?(@gc).should_not be_true + r.include?(@gp).should_not be_true + r.include?(@pc).should_not be_true + 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.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 + 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.parts + end + end + it 'リストを返している' do + r = @panel.parts + r.is_a?(Array).should be_true + r.size.should eq 2 + end + it 'tでソートしている' do + r = @panel.parts + r[0].should eq @sb + r[1].should eq @pp + end + context 'さらに末尾にフキダシを追加したとき' do + before do + @sb2 = @panel.speech_balloons.create( + FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2) + ) + @panel.reload + end + it 'tでソートしている' do + r = @panel.parts + r[0].should eq @sb + r[1].should eq @pp + r[2].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.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 'リストを返している' do + r = @panel.grounds + r.is_a?(Array).should be_true + end + it '景色素材と景色カラーと景色カラーコードを合わせている' do + r = @panel.grounds + r.include?(@gc).should be_true + r.include?(@gp).should be_true + r.include?(@pc).should be_true + end + it 'コマ絵とフキダシを含んでいない' do + r = @panel.grounds + r.include?(@pp).should_not be_true + r.include?(@sb).should_not be_true + 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.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 + context 'つつがなく終わるとき' do + it 'コマ部品を利用している' do + Panel.any_instance.stub(:parts).with(any_args).and_return([]) + Panel.any_instance.should_receive(:parts).with(any_args).exactly(1) + r = @panel.panel_elements + end + it 'コマ地を利用している' do + Panel.any_instance.stub(:grounds).with(any_args).and_return([]) + Panel.any_instance.should_receive(:grounds).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 'コマ絵とフキダシを合わせている' do + r = @panel.panel_elements + r.include?(@pp).should be_true + r.include?(@sb).should be_true + end + it '景色素材と景色カラーと景色カラーコードを合わせている' do + r = @panel.panel_elements + r.include?(@gc).should be_true + r.include?(@gp).should be_true + r.include?(@pc).should be_true + end + it 'tでソートしている[t順にソートできる部品の方が優先順位は高い。]' do + r = @panel.panel_elements + r[0].should eq @sb + r[1].should eq @pp + 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.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 + context 'つつがなく終わるとき' do + before do + Panel.stub(:elm_json_opt).with(@pp).and_return({}) + Panel.stub(:elm_json_opt).with(@sb).and_return({}) + Panel.stub(:elm_json_opt).with(@gp).and_return({}) + Panel.stub(:elm_json_opt).with(@gc).and_return({}) + Panel.stub(:elm_json_opt).with(@pc).and_return({}) + end + it 'コマ要素のjson出力オプションにコマ絵json出力オプションを依頼している' do + Panel.should_receive(:elm_json_opt).with(@pp).exactly(1) + r = @panel.elements + end + it 'コマ要素のjson出力オプションにフキダシjson出力オプションを依頼している' do + Panel.should_receive(:elm_json_opt).with(@sb).exactly(1) + r = @panel.elements + end + it 'コマ要素のjson出力オプションに景色素材json出力オプションを依頼している' do + Panel.should_receive(:elm_json_opt).with(@gp).exactly(1) + r = @panel.elements + end + it 'コマ要素のjson出力オプションに景色カラーjson出力オプションを依頼している' do + Panel.should_receive(:elm_json_opt).with(@gc).exactly(1) + r = @panel.elements + end + it 'コマ要素のjson出力オプションに景色カラーコードjson出力オプションを依頼している' do + Panel.should_receive(:elm_json_opt).with(@pc).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.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 + 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?('balloons').should be_true + sb.has_key?('speeches').should be_true + #t:1 + end + end + describe '検証値収集に於いて' do context 'つつがなく終わるとき' do - it '第一パラメータで指定された配列中から第二引数のidを収集している' do - a = [[{:panel_id => 1, :a => 'a'}, {:panel_id => 2, :a => 'a'}], + 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 a, :panel_id + 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 - 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 + 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 '検証値収集を依頼している' 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 'シリアライズチェック依頼している' 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 + 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) + ) + @panel.panel_pictures.build( + FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 1) + ) + sb1 = @panel.speech_balloons.build( + FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2) + ) + sb1.balloons.build( + FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id) + ) + sb1.speeches.build( + FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id) + ) + sb2 = @panel.speech_balloons.build( + FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 3) + ) + sb2.balloons.build( + FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb2.id) + ) + sb2.speeches.build( + FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb2.id) + ) + r = @panel.validate_child + r.should be_true + end + end + context 'シリアライズされていないとき' 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) + ) + @panel.panel_pictures.build( + FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 1) + ) + sb1 = @panel.speech_balloons.build( + FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2) + ) + sb1.balloons.build( + FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id) + ) + sb1.speeches.build( + FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id) + ) + sb2 = @panel.speech_balloons.build( + FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 4) + ) + sb2.balloons.build( + FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb2.id) + ) + sb2.speeches.build( + FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb2.id) + ) + r = @panel.validate_child + r.should be_false + end + end + end + 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 + Panel.any_instance.should_receive(:overwrite).exactly(1) + r = @panel.store @attr, @author + end + it '従属データの検証を依頼している' do + Panel.any_instance.should_receive(:validate_child).with(any_args).exactly(1) + r = @panel.store @attr, @author + end + 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 + end + context 'つつがなく終わるとき' do + before do + Panel.any_instance.stub(:validate_child).with(any_args).and_return(true) + end + it 'Trueを返す' do + r = @panel.store @attr, @author + r.should be_true + end + 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 + end + context '従属データの検証に失敗したとき' do + before do + Panel.any_instance.stub(:validate_child).with(any_args).and_return(false) + end + it 'エラーメッセージがセットされている' do + r = @panel.store @attr, @author + @panel.errors.should_not be_empty + end + end + context 'カラム値がFalseしたとき' do + before do + Panel.any_instance.stub(:validate_child).with(any_args).and_return(true) end + it 'エラーメッセージがセットされている' do + r = @panel.store false, @author + @panel.errors.should_not be_empty + end + 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! + p @panel2 + p @panel2.panel_pictures end end describe 'id一致チェックに於いて' do @@ -695,7 +1133,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 +1153,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 +1171,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 +1189,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 +1214,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 +1262,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