before do\r
#すべての処理が正常パターンで通過すれば、一番深い分岐まで通る。\r
#それで外部のメソッド呼び出しだけに着目してテストする。\r
+ OriginalPicture.any_instance.stub(:save).and_return(true)\r
ResourcePicture.any_instance.stub(:new_picture).with(any_args).and_return(@p)\r
ResourcePicture.any_instance.stub(:store_picture_with_gif).with(any_args).and_return(true)\r
end\r
+ it '原画に保存を依頼している' do\r
+ OriginalPicture.any_instance.should_receive(:save).exactly(1)\r
+ r = @rp.store @imager\r
+ end\r
it '新規実素材の取得を依頼している' do\r
ResourcePicture.any_instance.should_receive(:new_picture).with(any_args).exactly(1)\r
r = @rp.store @imager\r
r = @rp.store @imager\r
r.should be_true\r
end\r
+ it '原画の停止日時をクリアする' do\r
+ r = @rp.store @imager\r
+ @rp.original_picture.stopped_at.should be_nil\r
+ end\r
+ it '原画の公開日時に現在時刻をセットする' do\r
+ lambda {\r
+ r = @rp.store @imager\r
+ }.should change(@rp.original_picture, :published_at)\r
+ end\r
it '実素材idから最新画像idを取得してセットしている' do\r
r = @rp.store @imager\r
@rp.picture_id.should eq @p.id\r
end\r
end\r
#以下から例外ケース。処理先頭から失敗させていく\r
+ context '原画の保存に失敗したとき' do\r
+ before do\r
+ OriginalPicture.any_instance.stub(:save).and_return(false)\r
+ end\r
+ it 'Falseを返す' do\r
+ r = @rp.unpublish\r
+ r.should be_false\r
+ end\r
+ it 'ロールバックしている' do\r
+ lambda {\r
+ r = @rp.unpublish\r
+ }.should_not change(ResourcePicture, :count)\r
+ end\r
+ end\r
context '画像オブジェクトの取得に失敗したとき' do\r
before do\r
@imager = false\r
end\r
context '事前チェックしておく' do\r
before do\r
+ OriginalPicture.any_instance.stub(:save).and_return(true)\r
ResourcePicture.any_instance.stub(:destroy).and_return(true)\r
PictureIO.resource_picture_io.stub(:delete).with(@rp.filename).and_return(true)\r
PictureIO.resource_picture_io.stub(:delete).with(@rp.filename, 'full').and_return(true)\r
end\r
+ it '原画に保存を依頼している' do\r
+ OriginalPicture.any_instance.should_receive(:save).exactly(1)\r
+ r = @rp.unpublish\r
+ end\r
it '素材モデルに削除を依頼している' do\r
ResourcePicture.any_instance.should_receive(:destroy).exactly(1)\r
r = @rp.unpublish\r
r = ResourcePicture.find @rp.id\r
}.should raise_error\r
end\r
+ it '原画の公開日時をクリアする' do\r
+ r = @rp.store @imager\r
+ @rp.original_picture.published_at.should be_nil\r
+ end\r
+ it '原画の停止日時に現在時刻をセットする' do\r
+ lambda {\r
+ r = @rp.unpublish\r
+ }.should change(@rp.original_picture, :stopped_at)\r
+ end\r
it 'Trueを返す' do\r
r = @rp.unpublish\r
r.should be_true\r
end\r
end\r
+ context '原画の保存に失敗したとき' do\r
+ before do\r
+ OriginalPicture.any_instance.stub(:save).and_return(false)\r
+ end\r
+ it 'Falseを返す' do\r
+ r = @rp.unpublish\r
+ r.should be_false\r
+ end\r
+ it 'ロールバックしている' do\r
+ lambda {\r
+ r = @rp.unpublish\r
+ }.should_not change(ResourcePicture, :count)\r
+ end\r
+ end\r
context '自身の削除に失敗したとき' do\r
before do\r
ResourcePicture.any_instance.stub(:destroy).with(any_args).and_return(false)\r