+ end\r
+
+ describe '画像ファイルの作成・更新に於いて' do\r
+ before do
+ @op = Factory :original_picture, :artist_id => @artist.id
+ @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+ attr = {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => 'tester', :credit => '{}', :settings => {}.to_json.to_s}\r
+ @rp = Factory.build :resource_picture, attr
+ end
+ context '事前チェック' do
+ before do
+ #すべての処理が正常パターンで通過すれば、一番深い分岐まで通る。
+ #それで外部のメソッド呼び出しだけに着目してテストする。
+ @mgk = Mgk.new #一回目の本画像保存は与えたオブジェクトを使って保存する。
+ ResourcePicture.any_instance.stub(:store_picture).with(any_args).and_return(true)\r
+ ResourcePicture.any_instance.stub(:to_gif?).with(any_args).and_return(true)\r
+ class GifMgk < Mgk ; end #store_pictureは二回呼び出される。区別をつけるために\r
+ @gifmgk = GifMgk.new #パラメータを二種類用意する。\r
+ ResourcePicture.stub(:png_to_gif).with(any_args).and_return(@gifmgk)
+ end
+ it '画像ファイルの作成・更新機能で画像を保存している' do\r
+ ResourcePicture.any_instance.should_receive(:store_picture).with(@mgk).exactly(1)
+ res = @rp.store_picture_with_gif @mgk\r
+ end\r
+ it '自身にフォーマット変換対象かを問い合わせている' do
+ ResourcePicture.any_instance.should_receive(:to_gif?).with(any_args).exactly(1)
+ res = @rp.store_picture_with_gif @mgk\r
+ end\r
+ it '自身にGifフォーマット変換を依頼している' do
+ ResourcePicture.should_receive(:png_to_gif).with(any_args).exactly(1)
+ res = @rp.store_picture_with_gif @mgk\r
+ end\r
+ it '画像ファイルの作成・更新機能でgif画像を保存している' do\r
+ #二回目の保存はgif変換の結果を渡す。
+ ResourcePicture.any_instance.should_receive(:store_picture).with(@gifmgk).exactly(1)
+ res = @rp.store_picture_with_gif @mgk\r
+ end\r
+ end
+ context 'つつがなく終わるとき' do
+ before do
+ #すべての処理を正常パターンで通過させ、保存機能をチェックする。
+ @mgk = Mgk.new #一回目の本画像保存は与えたオブジェクトを使って保存する。
+ ResourcePicture.any_instance.stub(:store_picture).with(any_args).and_return(true)\r
+ ResourcePicture.any_instance.stub(:to_gif?).with(any_args).and_return(true)\r
+ class GifMgk < Mgk ; end #store_pictureは二回呼び出される。区別をつけるために\r
+ @gifmgk = GifMgk.new #パラメータを二種類用意する。\r
+ ResourcePicture.stub(:png_to_gif).with(any_args).and_return(@gifmgk)
+ end
+ it 'Trueを返す' do
+ res = @rp.store_picture_with_gif @mgk\r
+ res.should be_true\r
+ end\r
+ end
+ context 'gif変換なしで、つつがなく終わるとき' do
+ before do
+ #すべての処理を正常パターンで通過させ、保存機能をチェックする。
+ @mgk = Mgk.new #一回目の本画像保存は与えたオブジェクトを使って保存する。
+ ResourcePicture.any_instance.stub(:store_picture).with(any_args).and_return(true)\r
+ ResourcePicture.any_instance.stub(:to_gif?).with(any_args).and_return(false)\r
+ end
+ it 'Trueを返す' do
+ res = @rp.store_picture_with_gif @mgk\r
+ res.should be_true\r
+ end\r
+ it 'gif保存は呼ばれていない' do\r
+ ResourcePicture.any_instance.should_receive(:store_picture).with(any_args).exactly(1)
+ res = @rp.store_picture_with_gif @mgk\r
+ end\r
+ end
+ #以下から例外ケース。処理先頭から失敗させていく