X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=spec%2Fmodels%2Fpanel_spec.rb;h=7542b2070a9a9bc2004581b00d9d81398b2054e9;hb=bf89ae0a5c0f77ce2e9782b28023ff8ac521c501;hp=01f947026c294df9d1b4ac827f41acfeec2b7a0e;hpb=e994abdaf74bc9d7c62d28f4e5a2caaffbc2fb48;p=pettanr%2Fpettanr.git diff --git a/spec/models/panel_spec.rb b/spec/models/panel_spec.rb index 01f94702..7542b207 100644 --- a/spec/models/panel_spec.rb +++ b/spec/models/panel_spec.rb @@ -3,16 +3,15 @@ require 'spec_helper' #コマ describe Panel do before do - FactoryGirl.create :admin + @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 @user = FactoryGirl.create( :user_yas) - @author = @user.author + @author = FactoryGirl.create :author, :user_id => @user.id @artist = FactoryGirl.create :artist_yas, :author_id => @author.id @other_user = FactoryGirl.create( :user_yas) - @other_author = @other_user.author + @other_author = FactoryGirl.create :author, :user_id => @other_user.id @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id @op = FactoryGirl.create :original_picture, :artist_id => @artist.id @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id @@ -25,29 +24,29 @@ describe Panel do @panel = FactoryGirl.build :panel, :author_id => @author.id 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 'オーソドックスなデータのとき' 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 it 'nullなら失敗する' do @panel.width = nil @@ -171,6 +170,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,49 +216,116 @@ describe Panel do end - describe '作者判定に於いて' do + describe '所持判定に於いて' do before do + @panel = FactoryGirl.create :panel, :author_id => @author.id end - it '自作のコマならyes' do - panel = FactoryGirl.create :panel, :author_id => @author.id - 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 = FactoryGirl.create :panel, :author_id => @author.id - 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 = FactoryGirl.create :panel, :author_id => @author.id - 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 + @comic = FactoryGirl.create :comic, :author_id => @author.id + @panel = FactoryGirl.create :panel, :author_id => @author.id + @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id end - 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 + context 'オープンモードのとき' do + before do + MagicNumber['run_mode'] = 0 + 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 - 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 - 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 - 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 + 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) + 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 be_false + end + it '他人のコマでも公開なら許可する' do + Panel.any_instance.stub(:own?).and_return(false) + Panel.any_instance.stub(:publish?).and_return(true) + r = @panel.visible?([@author]) + r.should be_true + end end end @@ -281,7 +363,7 @@ describe Panel do r.should eq [@panel] end it '時系列で並んでいる' do - #公開コミックは(他人のコミックであっても)含んでいる + #公開コミックは(他人のコミックであっても)含んでいる npl = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100 r = Panel.list r.should eq [npl, @panel] @@ -317,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 @@ -427,15 +424,15 @@ describe Panel do pl = Panel.mylist @author pl.should eq [npl, @panel] end - context 'DBに5件あって1ページの件数を2件に変えたとして' do - before do + 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 + 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 @@ -451,20 +448,174 @@ describe Panel 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 + end + + describe '他作家のコマ一覧取得に於いて' do + before do + @panel = FactoryGirl.create :panel, :author_id => @author.id + @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1 + end + it 'リストを返す' do + r = Panel.himlist @other_author + r.should eq [@other_panel] + end + it '時系列で並んでいる' do + npl = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100 + r = Panel.himlist @other_author + r.should eq [npl, @other_panel] + end + it '公開コマに限る' do + npl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 0 + r = Panel.himlist @other_author + r.should eq [@other_panel] + end + context 'DBに5件あって1ページの件数を2件に変えたとして' do + before do + @other_panel2 = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100 + @other_panel3 = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 200 + @other_panel4 = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 300 + @other_panel5 = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 400 + end + it '通常は2件を返す' do + pl = Panel.himlist @other_author, 1, 2 + pl.should have(2).items + end + it 'page=1なら末尾2件を返す' do + #時系列で並んでいる + pl = Panel.himlist @other_author, 1, 2 + pl.should eq [@other_panel5, @other_panel4] + end + it 'page=2なら中間2件を返す' do + pl = Panel.himlist @other_author, 2, 2 + pl.should eq [@other_panel3, @other_panel2] + end + it 'page=3なら先頭1件を返す' do + pl = Panel.himlist @other_author, 3, 2 + pl.should eq [@other_panel] + end + end + end + + describe 'コマ一覧ページ制御に於いて' do + 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 @@ -475,12 +626,12 @@ describe Panel 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 + 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 + r = Panel.show @panel.id, @author end end it '指定のコマを返す' do @@ -512,12 +663,12 @@ describe Panel 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 + 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 + r = Panel.edit @panel.id, @author end end it '指定のコマを返す' do @@ -546,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] @@ -572,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 @@ -594,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 @@ -622,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 @@ -636,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 @@ -657,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 @@ -677,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 @@ -695,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 @@ -743,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 @@ -759,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 @@ -795,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 @@ -811,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) @@ -821,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 @@ -847,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 @@ -878,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 @@ -905,6 +1038,39 @@ describe Panel do j.first.has_key?('p').should be_true end end + + describe 'ライセンス素材に於いて' do + before do + #コマを作成しておく。 + @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id + @p2 = FactoryGirl.create :picture, :original_picture_id => @op2.id, :license_id => @license.id, :artist_id => @artist.id + @rp2 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op2.id, :picture_id => @p2.id + @panel = FactoryGirl.create :panel, :author_id => @author.id + @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height, :picture_id => @p.id + @sb = @panel.speech_balloons.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, :t => 2) + ) + @gp = @panel.ground_pictures.create( + FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p2.id, :t => 3) + ) + @panel.reload + end + context '事前チェック' do + end + context 'つつがなく終わるとき' do + end + it '連想配列(値は実素材、キーは実素材id)を返している' do + r = @panel.licensed_pictures + r.is_a?(Hash).should be_true + r.should have(2).items + r[@pp.picture_id].should eq @p + r[@gp.picture_id].should eq @p2 + end + end + describe '検証値収集に於いて' do context 'つつがなく終わるとき' do it '第一パラメータで指定された配列中から第二引数のカラム値を収集している' do @@ -924,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 @@ -974,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 @@ -1036,8 +1261,8 @@ describe Panel do describe '保存に於いて' do before do @attr = FactoryGirl.attributes_for :panel - @panel = Panel.new - @panel.supply_default + @panel = Panel.new + @panel.supply_default end context 'つつがなく終わるとき' do before do @@ -1048,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 @@ -1073,13 +1298,22 @@ describe Panel do }.should change(Panel, :count) end end + context '不正なjsonデータのとき' do + before do + end + it 'エラーメッセージがセットされている' do + r = @panel.store false, @author + @panel.errors[:base].should_not be_blank + end + 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 r = @panel.store @attr, @author - @panel.errors.should_not be_empty + @panel.errors[:base].should_not be_blank end end context 'カラム値がFalseしたとき' do @@ -1092,6 +1326,70 @@ describe Panel do end end end + + describe '削除に於いて' do + before do + @comic = FactoryGirl.create :comic, :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( + 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) + ) + @gp = @panel.ground_pictures.create( + FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id) + ) + end + context 'つつがなく終わるとき' do + it '自身を削除する' do + lambda { + r = @panel.destroy_with_elements + }.should change(Panel, :count).by(-1) + lambda { + r = Panel.find @panel.id + }.should raise_error + end + it '自身にリンクしているコマ要素をすべて削除する' do + lambda { + r = @panel.destroy_with_elements + }.should change(PanelPicture, :count).by(-1) + lambda { + r = PanelPicture.find @pp.id + }.should raise_error + end + it '自身にリンクしているコマ要素をすべて削除する' do + lambda { + r = @panel.destroy_with_elements + }.should change(GroundPicture, :count).by(-1) + lambda { + r = GroundPicture.find @gp.id + }.should raise_error + end + it 'Trueを返す' do + r = @panel.destroy_with_elements + r.should be_true + end + end + context '削除に失敗したとき' do + before do + PanelPicture.any_instance.stub(:destroy).with(any_args).and_return(false) + end + it 'Falseを返す' do + r = @panel.destroy_with_elements + r.should be_false + end + it 'ロールバックしている' do + lambda { + r = @panel.destroy_with_elements + }.should_not change(Panel, :count) + lambda { + r = @panel.destroy_with_elements + }.should_not change(PanelPicture, :count) + end + end + end =begin describe 'id挿げ替え防止確認に於いて' do before do @@ -1118,8 +1416,6 @@ describe Panel do 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