end\r
end\r
end\r
+ \r
+ describe '削除に於いて' do\r
+ before do\r
+ @comic = FactoryGirl.create :comic, :author_id => @author.id\r
+ @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1\r
+ @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height\r
+ @sb = @panel.speech_balloons.create(\r
+ FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)\r
+ )\r
+ @gc = @panel.ground_colors.create(\r
+ FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :color_id => @color.id)\r
+ )\r
+ @gp = @panel.ground_pictures.create(\r
+ FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id)\r
+ )\r
+ @pc = @panel.panel_colors.create(\r
+ FactoryGirl.attributes_for(:panel_color, :panel_id => @panel.id, :code => 0xff0000)\r
+ )\r
+ end\r
+ context 'つつがなく終わるとき' do\r
+ it '自身を削除する' do\r
+ lambda {\r
+ r = @panel.destroy_with_elements\r
+ }.should change(Panel, :count).by(-1)\r
+ lambda {\r
+ r = Panel.find @panel.id\r
+ }.should raise_error\r
+ end\r
+ it '自身にリンクしているコマ要素をすべて削除する' do\r
+ lambda {\r
+ r = @panel.destroy_with_elements\r
+ }.should change(PanelPicture, :count).by(-1)\r
+ lambda {\r
+ r = PanelPicture.find @pp.id\r
+ }.should raise_error \r
+ end\r
+ it '自身にリンクしているコマ要素をすべて削除する' do\r
+ lambda {\r
+ r = @panel.destroy_with_elements\r
+ }.should change(GroundPicture, :count).by(-1)\r
+ lambda {\r
+ r = GroundPicture.find @gp.id\r
+ }.should raise_error \r
+ end\r
+ it 'Trueを返す' do\r
+ r = @panel.destroy_with_elements\r
+ r.should be_true\r
+ end\r
+ end\r
+ context '削除に失敗したとき' do\r
+ before do\r
+ PanelPicture.any_instance.stub(:destroy).with(any_args).and_return(false)\r
+ end\r
+ it 'Falseを返す' do\r
+ r = @panel.destroy_with_elements\r
+ r.should be_false\r
+ end\r
+ it 'ロールバックしている' do\r
+ lambda {\r
+ r = @panel.destroy_with_elements\r
+ }.should_not change(Panel, :count)\r
+ lambda {\r
+ r = @panel.destroy_with_elements\r
+ }.should_not change(PanelPicture, :count)\r
+ end\r
+ end\r
+ end\r
=begin\r
describe 'id挿げ替え防止確認に於いて' do\r
before do\r