X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=spec%2Fmodels%2Fpanel_spec.rb;h=7542b2070a9a9bc2004581b00d9d81398b2054e9;hb=bf89ae0a5c0f77ce2e9782b28023ff8ac521c501;hp=308bc3b470914f534a55a08acb48a6988b65379a;hpb=3b695342f170cafcc457f8042056fc8eb73bc0f2;p=pettanr%2Fpettanr.git diff --git a/spec/models/panel_spec.rb b/spec/models/panel_spec.rb index 308bc3b4..7542b207 100644 --- a/spec/models/panel_spec.rb +++ b/spec/models/panel_spec.rb @@ -7,7 +7,6 @@ describe Panel do @sp = FactoryGirl.create :system_picture @lg = FactoryGirl.create :license_group @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id - @color = FactoryGirl.create :color @user = FactoryGirl.create( :user_yas) @author = FactoryGirl.create :author, :user_id => @user.id @artist = FactoryGirl.create :artist_yas, :author_id => @author.id @@ -400,91 +399,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 @@ -518,7 +432,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 @@ -535,21 +449,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 '通常は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 '通常は全件(5件)を返す' do - r = Panel.mylist @author, 5, 0 - r.should have(5).items + 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 @@ -629,9 +697,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] @@ -655,17 +723,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 @@ -677,18 +745,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 @@ -705,13 +765,10 @@ describe Panel do 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) + 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 @@ -719,16 +776,12 @@ 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 @@ -740,13 +793,10 @@ describe Panel do 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) + 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 @@ -760,17 +810,19 @@ describe Panel do it 'リストを返している' do r = @panel.parts r.is_a?(Array).should be_true - r.size.should eq 2 + r.size.should eq 4 end it 'tでソートしている' do r = @panel.parts 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) + FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 4) ) @panel.reload end @@ -778,43 +830,63 @@ describe Panel do r = @panel.parts 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 '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 + @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 0, :z => 2, :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) + FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 1, :z => 1) ) @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 + context 'つつがなく終わるとき' do + it 'コマ部品集合を利用している' do + Panel.any_instance.stub(:parts_element).with(any_args).and_return([]) + Panel.any_instance.should_receive(:parts_element).with(any_args).exactly(1) + r = @panel.zorderd_elements + end + end it 'リストを返している' do - r = @panel.grounds + r = @panel.zorderd_elements r.is_a?(Array).should be_true + r.size.should eq 4 end - it '景色素材と景色カラーと景色カラーコードを合わせている' do - r = @panel.grounds - r.include?(@gc).should be_true - r.include?(@gp).should be_true - r.include?(@pc).should be_true + 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 - it 'コマ絵とフキダシを含んでいない' do - r = @panel.grounds - r.include?(@pp).should_not be_true - r.include?(@sb).should_not be_true + 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 => 4, :z => 5) + ) + @panel.reload + end + it 'zでソートしている' do + r = @panel.zorderd_elements + r[0].should eq @sb + r[1].should eq @pp + r[2].should eq @gc + r[3].should eq @gp + r[4].should eq @sb2 + end end end describe 'コマ要素に於いて' do @@ -826,13 +898,10 @@ describe Panel do 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) + 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 @@ -842,31 +911,17 @@ describe Panel do 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 + 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 end describe 'コマ要素のjson出力に於いて' do @@ -878,13 +933,10 @@ describe Panel do 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) + 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 @@ -894,7 +946,6 @@ describe Panel do 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) @@ -904,18 +955,14 @@ describe Panel do Panel.should_receive(:elm_json_opt).with(@sb).exactly(1) r = @panel.elements end - it 'コマ要素のjson出力オプションに景色素材json出力オプションを依頼している' do + it 'コマ要素のjson出力オプションに絵地json出力オプションを依頼している' do Panel.should_receive(:elm_json_opt).with(@gp).exactly(1) r = @panel.elements end - it 'コマ要素のjson出力オプションに景色カラーjson出力オプションを依頼している' do + 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 @@ -930,14 +977,17 @@ describe Panel do @sb = @panel.speech_balloons.create( FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0) ) + @sb.create_balloon( + FactoryGirl.attributes_for(:balloon, :speech_balloon_id => @sb.id) + ) + @sb.create_speech( + FactoryGirl.attributes_for(:speech, :speech_balloon_id => @sb.id) + ) @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 @@ -961,8 +1011,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 @@ -1001,13 +1051,10 @@ describe Panel do 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) + 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 @@ -1043,48 +1090,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 @@ -1093,60 +1150,109 @@ 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, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2, :z => 2+1) ) - sb1.balloons.build( + sb1.build_balloon( FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id) ) - sb1.speeches.build( + sb1.build_speech( 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) + FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 3, :z => 3+1) ) - sb2.balloons.build( + sb2.build_balloon( FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb2.id) ) - sb2.speeches.build( + sb2.build_speech( FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb2.id) ) + @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, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2, :z => 2+1) ) - sb1.balloons.build( + sb1.build_balloon( FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id) ) - sb1.speeches.build( + sb1.build_speech( 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) + FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 4, :z => 3+1) ) - sb2.balloons.build( + sb2.build_balloon( FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb2.id) ) - sb2.speeches.build( + sb2.build_speech( + FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb2.id) + ) + @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, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2, :z => 2+1) + ) + sb1.build_balloon( + FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id) + ) + sb1.build_speech( + 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, :z => 3+1) + ) + sb2.build_balloon( + FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb2.id) + ) + sb2.build_speech( FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb2.id) ) + @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 @@ -1167,15 +1273,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 @@ -1202,6 +1308,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 @@ -1229,14 +1336,11 @@ describe Panel do 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) + 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