OSDN Git Service

t#29202:save with gif
[pettanr/pettanr.git] / spec / models / picture_spec.rb
index 76f8392..b1d55fa 100644 (file)
@@ -343,7 +343,8 @@ describe Picture do
       end
       it '画像ファイルの作成機能で画像を保存している' do
         mgk = Mgk.new   #一回目の本画像保存は与えたオブジェクトを使って保存する。
-        Picture.any_instance.should_receive(:store_picture).with(mgk).exactly(1)
+        Picture.any_instance.stub(:filename).with(any_args).and_return('1.png')
+        Picture.any_instance.should_receive(:store_picture).with(mgk, '1.png').exactly(1)
         res = @p.store(mgk)
       end
       it '自身にgifフォーマット変換対象かを問い合わせている' do
@@ -356,7 +357,8 @@ describe Picture do
       end
       it '画像ファイルの作成機能でgif画像を保存している' do
         #二回目の保存はgif変換の結果を渡す。
-        Picture.any_instance.should_receive(:store_picture).with(@gifmgk).exactly(1)
+        Picture.any_instance.stub(:gifname).with(any_args).and_return('1.gif')
+        Picture.any_instance.should_receive(:store_picture).with(@gifmgk, '1.gif').exactly(1)
         res = @p.store(Mgk.new)
       end
     end
@@ -454,13 +456,15 @@ describe Picture do
     context 'gif画像の保存に失敗したとき' do
       before do
         @mgk = Mgk.new
+        Picture.any_instance.stub(:filename).with(any_args).and_return('1.png')
+        Picture.any_instance.stub(:gifname).with(any_args).and_return('1.gif')
         Picture.any_instance.stub(:save).with(any_args).and_return(true)
-        Picture.any_instance.stub(:store_picture).with(@mgk).and_return(true)
+        Picture.any_instance.stub(:store_picture).with(@mgk, '1.png').and_return(true)
         Picture.any_instance.stub(:to_gif?).with(any_args).and_return(true)
         class GifMgk < Mgk ; end  #store_pictureは二回呼び出される。区別をつけるために
         @gifmgk = GifMgk.new      #パラメータを二種類用意する。
         Picture.stub(:png_to_gif).with(any_args).and_return(@gifmgk)
-        Picture.any_instance.stub(:store_picture).with(@gifmgk).and_return(false)
+        Picture.any_instance.stub(:store_picture).with(@gifmgk, '1.gif').and_return(false)
         @p = FactoryGirl.build :picture, :original_picture_id => @op.id, :license_id => @license.id
       end
       it 'Falseを返す' do
@@ -528,35 +532,35 @@ describe Picture do
       end
       it '画像ファイルの保存が4回呼ばれる' do
         PictureIO.picture_io.should_receive(:put).with(any_args).exactly(4)
-        res = @p.store_picture(Mgk.new)
+        res = @p.store_picture(Mgk.new, '1.png')
       end
       it '画像ファイルのベースへの保存が1回呼ばれる' do
-        PictureIO.picture_io.should_receive(:put).with('data', @p.filename, '').exactly(1)
-        res = @p.store_picture(Mgk.new)
+        PictureIO.picture_io.should_receive(:put).with('data', '1.png', '').exactly(1)
+        res = @p.store_picture(Mgk.new, '1.png')
       end
       it '画像ファイルの垂直反転への保存が1回呼ばれる' do
-        PictureIO.picture_io.should_receive(:put).with('data', @p.filename, 'v').exactly(1)
-        res = @p.store_picture(Mgk.new)
+        PictureIO.picture_io.should_receive(:put).with('data', '1.png', 'v').exactly(1)
+        res = @p.store_picture(Mgk.new, '1.png')
       end
       it '画像ファイルの水平反転への保存が1回呼ばれる' do
-        PictureIO.picture_io.should_receive(:put).with('data', @p.filename, 'h').exactly(1)
-        res = @p.store_picture(Mgk.new)
+        PictureIO.picture_io.should_receive(:put).with('data', '1.png', 'h').exactly(1)
+        res = @p.store_picture(Mgk.new, '1.png')
       end
       it '画像ファイルの垂直水平反転への保存が1回呼ばれる' do
-        PictureIO.picture_io.should_receive(:put).with('data', @p.filename, 'vh').exactly(1)
-        res = @p.store_picture(Mgk.new)
+        PictureIO.picture_io.should_receive(:put).with('data', '1.png', 'vh').exactly(1)
+        res = @p.store_picture(Mgk.new, '1.png')
       end
       it '垂直反転が1回呼ばれる' do
         Picture.any_instance.should_receive(:v).with(any_args).exactly(1)
-        res = @p.store_picture(Mgk.new)
+        res = @p.store_picture(Mgk.new, '1.png')
       end
       it '水平反転が1回呼ばれる' do
         Picture.any_instance.should_receive(:h).with(any_args).exactly(1)
-        res = @p.store_picture(Mgk.new)
+        res = @p.store_picture(Mgk.new, '1.png')
       end
       it '垂直水平反転が1回呼ばれる' do
         Picture.any_instance.should_receive(:vh).with(any_args).exactly(1)
-        res = @p.store_picture(Mgk.new)
+        res = @p.store_picture(Mgk.new, '1.png')
       end
     end
     context 'つつがなく終わるとき' do
@@ -565,7 +569,7 @@ describe Picture do
         PictureIO.picture_io.stub(:put).with(any_args).and_return(true)
       end
       it 'Trueを返す' do
-        res = @p.store_picture(Mgk.new)
+        res = @p.store_picture(Mgk.new, '1.png')
         res.should be_true
       end
     end
@@ -574,7 +578,7 @@ describe Picture do
         PictureIO.picture_io.stub(:put).with(any_args).and_return(false)
       end
       it 'Falseを返す' do
-        res = @p.store_picture(Mgk.new)
+        res = @p.store_picture(Mgk.new, '1.png')
         res.should be_false
       end
     end