X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=spec%2Fmodels%2Fpanel_spec.rb;h=20afa074a0d3cc98a229fbb57b1e6b5058afc1f0;hb=refs%2Fheads%2Fv06sheet;hp=b319970cca5e5d68f5b3c63dc9755bf69160dba7;hpb=9618822ebe6f87ffde3376b0ab88c0be36880659;p=pettanr%2Fpettanr.git diff --git a/spec/models/panel_spec.rb b/spec/models/panel_spec.rb index b319970c..20afa074 100644 --- a/spec/models/panel_spec.rb +++ b/spec/models/panel_spec.rb @@ -3,11 +3,12 @@ require 'spec_helper' #コマ describe Panel do before do + 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 - @color = FactoryGirl.create :color + @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 @@ -17,7 +18,7 @@ describe Panel do @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 + @sbt = FactoryGirl.create :speech_balloon_template, "name" => "circle@pettan.com", "classname" => "CircleSpeechBalloon", "caption" => "cc", "system_picture_id" => @sp.id, "settings" => '{}' end describe '検証に於いて' do @@ -30,9 +31,6 @@ describe Panel 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 @@ -40,9 +38,6 @@ describe Panel 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 @@ -102,48 +97,6 @@ describe Panel do @panel.should be_valid end end - context 'xを検証するとき' do - it '数値でなければ失敗する' do - @panel.x = '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 - end - end - context 'yを検証するとき' do - it '数値でなければ失敗する' do - @panel.y = 'a' - @panel.should_not be_valid - end - it '0なら通る' do - @panel.y = '0' - @panel.should be_valid - end - it '負でも通る' do - @panel.y = -1 - @panel.should be_valid - end - end - context 'zを検証するとき' do - it '数値でなければ失敗する' do - @panel.z = 'a' - @panel.should_not be_valid - end - it '0なら失敗する' do - @panel.z = '0' - @panel.should_not be_valid - end - it '負なら失敗する' do - @panel.z = -1 - @panel.should_not be_valid - end - end context 'author_idを検証するとき' do it 'nullなら失敗する' do @panel.author_id = nil @@ -171,6 +124,22 @@ describe Panel do 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 + + end + describe 'デフォルト値補充に於いて' do before do @panel = FactoryGirl.build :panel, :author_id => @author.id @@ -201,75 +170,115 @@ describe Panel do end - describe '作者判定に於いて' do + describe '所持判定に於いて' do before do @panel = FactoryGirl.create :panel, :author_id => @author.id end - it '自作のコマならyes' do - @panel.own?(@author).should == true + context '事前チェックする' do + it '自身にロールリストからの作家取得を依頼している' do + Panel.should_receive(:get_author_from_roles).with(any_args).exactly(1) + r = @panel.own?([@author]) + end end - it '他人のコマならno' do - @panel.own?(@other_author).should == false + context 'ロール内作家が取得できるとき' do + before do + end + 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 'ロール内作家の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 - it 'パラメータが作家でないならno' do - @panel.own?(nil).should == false + context 'ロール内作家が取得できないとき' do + before do + Panel.stub(:get_author_from_roles).with(any_args).and_return(nil) + end + it 'Falseを返す' do + r = @panel.own?([@author]) + r.should be_false + end 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 '検査対象がnil(ゲスト)のとき' do - context 'クローズドモードのとき' do - before do - MagicNumber['run_mode'] = 1 - end - it '不許可を返す。' do - r = @panel.visible?(nil) - r.should be_false - end + context 'オープンモードのとき' do + before do + MagicNumber['run_mode'] = 0 end - context 'オープンモードのとき' do - before do - MagicNumber['run_mode'] = 0 - end - it '公開コマなら許可する' do - Panel.any_instance.stub(:publish?).and_return(true) - r = @panel.visible?(nil) - r.should be_true - end - it '非公開コマなら許可しない' do - Panel.any_instance.stub(:publish?).and_return(false) - r = @panel.visible?(nil) - r.should be_false - end + 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 'ゲスト用ロールチェックが失敗したとき、falseを返す' do + Panel.any_instance.stub(:guest_role_check).and_return(false) + r = @panel.visible?([@author]) + r.should be_false end end - context '検査対象が作家のとき' do - it '自分のコマなら許可する' do + context 'クローズドモードのとき' do + before do + MagicNumber['run_mode'] = 1 + end + 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 '読者用ロールチェックが失敗したとき、falseを返す' do + Panel.any_instance.stub(:reader_role_check).and_return(false) + r = @panel.visible?([@author]) + r.should be_false + end + end + context '事前チェックする' do + before do + 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.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) - r = @panel.visible?(@author) - r.should == true + Panel.any_instance.should_receive(:publish?).with(any_args).exactly(1) + r = @panel.visible?([@author]) + end + end + context 'つつがなく終わるとき' do + before do + 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 == 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 == true - end - end - context '検査対象がそれ以外のとき' do - it '不許可を返す。' do - r = @panel.visible?(@admin) - r.should be_false + r = @panel.visible?([@author]) + r.should be_true end end end @@ -344,91 +353,6 @@ describe Panel do 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 '一覧取得オプションに於いて' do - it 'includeキーを含んでいる' do - r = Panel.list_opt - r.has_key?(:include).should be_true - end - it '6つの項目を含んでいる' do - r = Panel.list_opt[:include] - r.should have(6).items - end - it 'コマ絵を含んでいる' do - r = Panel.list_opt[:include] - r.has_key?(:panel_pictures).should be_true - end - it 'コマ絵は実素材を含んでいる' do - r = Panel.list_opt[:include] - r[:panel_pictures].has_key?(:picture).should be_true - end - it '実素材は絵師を含んでいる' do - r = Panel.list_opt[:include] - r[:panel_pictures][:picture].has_key?(:artist).should be_true - end - it '実素材はライセンスを含んでいる' do - r = Panel.list_opt[:include] - r[:panel_pictures][:picture].has_key?(:license).should be_true - end - it 'フキダシを含んでいる' do - r = Panel.list_opt[:include] - r.has_key?(:speech_balloons).should be_true - end - it 'フキダシはフキダシ枠を含んでいる' do - r = Panel.list_opt[:include] - r[:speech_balloons].has_key?(:balloons).should be_true - end - it 'フキダシはセリフを含んでいる' do - 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 @@ -462,7 +386,7 @@ describe Panel do @npl5 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 400 end it '通常は2件を返す' do - pl = Panel.list 1, 2 + pl = Panel.mylist @author, 1, 2 pl.should have(2).items end it 'page=1なら末尾2件を返す' do @@ -479,21 +403,175 @@ describe Panel do pl.should eq [@panel] end end - context 'DBに5件あって1ページの件数を0件に変えたとして' do + 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 - @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 - Author.stub(:default_panel_page_size).and_return(2) + @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 '通常は全件(5件)を返す' do - r = Panel.mylist @author, 5, 0 - r.should have(5).items + 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 + before do + Panel.stub(:count).with(any_args).and_return(100) + end + it 'ページ制御を返す' do + r = Panel.list_paginate + r.is_a?(Kaminari::PaginatableArray).should be_true + end + 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 'ページ件数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 + 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 + 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 'ページ件数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 + 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 + 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 + r = Panel.list_opt + 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 @@ -573,9 +651,9 @@ describe Panel do r = Panel.show_opt r.has_key?(:include).should be_true end - it '6つの項目を含んでいる' do + it '5つの項目を含んでいる' do r = Panel.show_opt[:include] - r.should have(6).items + r.should have(5).items end it 'コマ絵を含んでいる' do r = Panel.show_opt[:include] @@ -599,17 +677,17 @@ describe Panel do end it 'フキダシはフキダシ枠を含んでいる' do r = Panel.show_opt[:include] - r[:speech_balloons].has_key?(:balloons).should be_true + r[:speech_balloons].has_key?(:balloon).should be_true end it 'フキダシはセリフを含んでいる' do r = Panel.show_opt[:include] - r[:speech_balloons].has_key?(:speeches).should be_true + r[:speech_balloons].has_key?(:speech).should be_true end - it '景色画像を含んでいる' do + it '絵地を含んでいる' do r = Panel.show_opt[:include] r.has_key?(:ground_pictures).should be_true end - it '景色画像は実素材を含んでいる' do + it '絵地は実素材を含んでいる' do r = Panel.show_opt[:include] r[:ground_pictures].has_key?(:picture).should be_true end @@ -621,18 +699,10 @@ describe Panel do r = Panel.show_opt[:include] r[:ground_pictures][:picture].has_key?(:license).should be_true end - it '間接色を含んでいる' do + 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.show_opt[:include] r.has_key?(:author).should be_true @@ -645,17 +715,22 @@ describe Panel 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( + @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, :color_id => @color.id) + 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) - ) - @pc = @panel.panel_colors.create( - FactoryGirl.attributes_for(:panel_color, :panel_id => @panel.id, :code => 0xff0000) + FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 3) ) @panel.reload end @@ -663,34 +738,36 @@ describe Panel do r = @panel.parts_element r.is_a?(Array).should be_true end - it 'コマ絵とフキダシを合わせている' do + 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 + r.include?(@gc).should be_true + r.include?(@gp).should be_true end end - describe 'コマ部品に於いて' do + + describe 'z順コマ部品に於いて' 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) + @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, :color_id => @color.id) + 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) - ) - @pc = @panel.panel_colors.create( - FactoryGirl.attributes_for(:panel_color, :panel_id => @panel.id, :code => 0xff0000) + FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 3, :z => 4) ) @panel.reload end @@ -698,97 +775,74 @@ describe Panel 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 + r = @panel.zorderd_elements end end it 'リストを返している' do - r = @panel.parts + r = @panel.zorderd_elements r.is_a?(Array).should be_true - r.size.should eq 2 + r.size.should eq 4 end - it 'tでソートしている' do - r = @panel.parts + 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.create( - FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2) + @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 'tでソートしている' do - r = @panel.parts + it 'zでソートしている' do + r = @panel.zorderd_elements r[0].should eq @sb r[1].should eq @pp - r[2].should eq @sb2 + r[2].should eq @gc + r[3].should eq @gp + r[4].should eq @sb2 end end end - describe 'コマ地に於いて' do + 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( + @sb = @panel.speech_balloons.build( 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) + @sb.build_balloon( + FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.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) + @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, :color_id => @color.id) + 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) - ) - @pc = @panel.panel_colors.create( - FactoryGirl.attributes_for(:panel_color, :panel_id => @panel.id, :code => 0xff0000) + 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).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) + 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 @@ -796,21 +850,36 @@ describe Panel 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 + 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 @@ -818,46 +887,46 @@ describe Panel 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( + @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, :color_id => @color.id) + 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) - ) - @pc = @panel.panel_colors.create( - FactoryGirl.attributes_for(:panel_color, :panel_id => @panel.id, :code => 0xff0000) + FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 3) ) @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 + 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出力オプションにフキダシjson出力オプションを依頼している' do - Panel.should_receive(:elm_json_opt).with(@sb).exactly(1) + it 'コマ絵にjson出力オプションを依頼している' do + PanelPicture.should_receive(:json_opt_for_panel).exactly(1) r = @panel.elements end - it 'コマ要素のjson出力オプションに景色素材json出力オプションを依頼している' do - Panel.should_receive(:elm_json_opt).with(@gp).exactly(1) + it 'フキダシにjson出力オプションを依頼している' do + SpeechBalloon.should_receive(:json_opt_for_panel).exactly(1) r = @panel.elements end - it 'コマ要素のjson出力オプションに景色カラーjson出力オプションを依頼している' do - Panel.should_receive(:elm_json_opt).with(@gc).exactly(1) + it '絵地にjson出力オプションを依頼している' do + GroundPicture.should_receive(:json_opt_for_panel).exactly(1) r = @panel.elements end - it 'コマ要素のjson出力オプションに景色カラーコードjson出力オプションを依頼している' do - Panel.should_receive(:elm_json_opt).with(@pc).exactly(1) + it '色地にjson出力オプションを依頼している' do + GroundColor.should_receive(:json_opt_for_panel).exactly(1) r = @panel.elements end end @@ -871,17 +940,22 @@ describe Panel 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( + @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, :color_id => @color.id) + 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) - ) - @pc = @panel.panel_colors.create( - FactoryGirl.attributes_for(:panel_color, :panel_id => @panel.id, :code => 0xff0000) + FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 3) ) @panel.reload end @@ -905,8 +979,8 @@ describe Panel do #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 + sb.has_key?('balloon').should be_true + sb.has_key?('speech').should be_true #t:1 end end @@ -941,17 +1015,22 @@ describe Panel do @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.create( + @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, :color_id => @color.id) + 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) - ) - @pc = @panel.panel_colors.create( - FactoryGirl.attributes_for(:panel_color, :panel_id => @panel.id, :code => 0xff0000) + FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p2.id, :t => 3) ) @panel.reload end @@ -987,48 +1066,58 @@ describe Panel do describe 'シリアライズチェックに於いて' do context 'つつがなく終わるとき' do it '0からシリアライズされているならTrueを返す' do - r = Panel.validate_t [0, 1, 2] + r = Panel.validate_serial [0, 1, 2] r.should be_true end it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do - r = Panel.validate_t [0, 2, 1] + r = Panel.validate_serial [0, 2, 1] r.should be_true end it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do - r = Panel.validate_t [ 2, 1, 4, 3, 0] + 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_t [1, 2, 3] + r = Panel.validate_serial [1, 2, 3] r.should be_false end it '連続していないならFalseを返す' do - r = Panel.validate_t [0, 1, 2, 4] + r = Panel.validate_serial [0, 1, 2, 4] r.should be_false end it '連続していないならFalseを返す' do - r = Panel.validate_t [0, 1, 2, 4, 5] + r = Panel.validate_serial [0, 1, 2, 4, 5] r.should be_false end end end - describe 'tチェック単体に於いて' do + 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_t).with(any_args).and_return(true) - r = Panel.validate_element_t [], :t + 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_t).with(any_args).exactly(1) - Panel.stub(:validate_t).with(any_args).and_return(true) - r = Panel.validate_element_t [], :t + 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 @@ -1037,59 +1126,120 @@ describe Panel 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) + 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) + 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, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2) + FactoryGirl.attributes_for(:speech_balloon, :speech_balloon_template_id => @sbt.id, :t => 2, :z => 2+1) ) - sb1.balloons.build( - FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id) + sb1.build_balloon( + FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id) ) - sb1.speeches.build( - FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.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, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 3) + FactoryGirl.attributes_for(:speech_balloon, :speech_balloon_template_id => @sbt.id, :t => 3, :z => 3+1) ) - sb2.balloons.build( - FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb2.id) + sb2.build_balloon( + FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id) ) - sb2.speeches.build( - FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb2.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 'シリアライズされていないとき' do + 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) + 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) + 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, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2) + FactoryGirl.attributes_for(:speech_balloon, :speech_balloon_template_id => @sbt.id, :t => 2, :z => 2+1) ) - sb1.balloons.build( - FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id) + sb1.build_balloon( + FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id) ) - sb1.speeches.build( - FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.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, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 4) + FactoryGirl.attributes_for(:speech_balloon, :speech_balloon_template_id => @sbt.id, :t => 4, :z => 3+1) ) - sb2.balloons.build( - FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb2.id) + sb2.build_balloon( + FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id) ) - sb2.speeches.build( - FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb2.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 @@ -1111,15 +1261,15 @@ describe Panel 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 + it '従属データの検証を依頼している' do + Panel.any_instance.should_receive(:validate_child).with(any_args).exactly(1) + r = @panel.store @attr, @author + end end context 'つつがなく終わるとき' do before do @@ -1146,6 +1296,7 @@ describe Panel do end 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 'エラーメッセージがセットされている' do @@ -1164,23 +1315,82 @@ describe Panel do end 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 + @attr.merge!(@sbattr) + end + it 'エラーメッセージがセットされている' do + r = @panel.store @attr, @author + r.should be_false + @panel.errors.should_not be_empty + end + end + context 'コマ絵の横軸はアルファベットのため検証に失敗したとき' do + before do + @attr.merge!(@ppattr) + end + it 'エラーメッセージがセットされている' do + r = @panel.store @attr, @author + r.should be_false + @panel.errors.should_not be_empty + end + end + end + describe '削除に於いて' do before do - @comic = FactoryGirl.create :comic, :author_id => @author.id + @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.create( + @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, :color_id => @color.id) + 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) ) - @pc = @panel.panel_colors.create( - FactoryGirl.attributes_for(:panel_color, :panel_id => @panel.id, :code => 0xff0000) - ) end context 'つつがなく終わるとき' do it '自身を削除する' do