X-Git-Url: http://git.osdn.net/view?p=pettanr%2Fpettanr.git;a=blobdiff_plain;f=spec%2Fmodels%2Fpanel_spec.rb;h=b319970cca5e5d68f5b3c63dc9755bf69160dba7;hp=ea6374ba317b8756576552a1fa9d68353c3f323a;hb=9618822ebe6f87ffde3376b0ab88c0be36880659;hpb=71209c73f0d3e471680ace7d03ad4489273a1f02 diff --git a/spec/models/panel_spec.rb b/spec/models/panel_spec.rb index ea6374ba..b319970c 100644 --- a/spec/models/panel_spec.rb +++ b/spec/models/panel_spec.rb @@ -1163,6 +1163,73 @@ 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, :color_id => @color.id) + ) + @gp = @panel.ground_pictures.create( + FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id) + ) + @pc = @panel.panel_colors.create( + FactoryGirl.attributes_for(:panel_color, :panel_id => @panel.id, :code => 0xff0000) + ) + 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