i.has_key?('author').should be_true
end
end
+
+ describe '削除に於いて' do
+ before do
+ @comic = FactoryGirl.create :comic, :author_id => @author.id
+ @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
+ @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
+ @other_comic = FactoryGirl.create :comic, :author_id => @author.id
+ @other_story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @other_comic.id, :panel_id => @panel.id
+ end
+ context 'つつがなく終わるとき' do
+ it '自身を削除する' do
+ lambda {
+ r = @comic.destroy_with_story
+ }.should change(Comic, :count).by(-1)
+ lambda {
+ r = Comic.find @comic.id
+ }.should raise_error
+ end
+ it '自身にリンクしているストーリーをすべて削除する' do
+ lambda {
+ r = @comic.destroy_with_story
+ }.should change(Story, :count).by(-1)
+ lambda {
+ r = Story.find @story.id
+ }.should raise_error
+ end
+ it 'Trueを返す' do
+ r = @comic.destroy_with_story
+ r.should be_true
+ end
+ end
+ context '削除に失敗したとき' do
+ before do
+ Story.any_instance.stub(:destroy).with(any_args).and_return(false)
+ end
+ it 'Falseを返す' do
+ r = @comic.destroy_with_story
+ r.should be_false
+ end
+ it 'ロールバックしている' do
+ lambda {
+ r = @comic.destroy_with_story
+ }.should_not change(Comic, :count)
+ lambda {
+ r = @comic.destroy_with_story
+ }.should_not change(Story, :count)
+ end
+ end
+ end
end