Mgk.any_instance.stub(:to_blob).with(any_args).and_return('data')
#原画ファイル削除だけは必ず成功するものとしておく
PictureIO::LocalPicture.any_instance.stub(:delete).with(any_args).and_return(true)
+ Picture.any_instance.stub(:subdirs).with(any_args).and_return(['', 'v', 'h', 'vh'])\r
+ Picture.any_instance.stub(:h).with(any_args).and_return('data')
+ Picture.any_instance.stub(:v).with(any_args).and_return('data')
+ Picture.any_instance.stub(:vh).with(any_args).and_return('data')
end\r
describe '検証に於いて' do
end\r
end
+ describe 'RMagick変換に於いて' do
+ 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
+ it '画像データをオブジェクト化している' do
+ Magick::Image.stub(:from_blob).and_return(['mgkobj'])
+ @rp.data_to_mgk('mgkbin').should eq 'mgkobj'
+ end
+ end
+ context '失敗するとき' do
+ it 'Falseを返す' do
+ Magick::Image.should_receive(:from_blob).with(any_args).and_raise('StandardError')
+ @rp.data_to_mgk('mgkbin').should be_false
+ end
+ it '全体エラーがセットされている' do
+ Magick::Image.should_receive(:from_blob).with(any_args).and_raise('StandardError')
+ lambda {
+ @rp.data_to_mgk('mgkbin')
+ }.should change(@rp.errors[:base], :count)
+ end
+ end
+ end
describe '画像オブジェクトの取得に於いて' do
before do
@op = Factory :original_picture, :artist_id => @artist.id
context '事前チェック' do
before do
OriginalPicture.any_instance.stub(:restore).with(any_args).and_return('data')\r
- OriginalPicture.any_instance.stub(:data_to_mgk).with(any_args).and_return(Mgk.new)
+ ResourcePicture.any_instance.stub(:data_to_mgk).with(any_args).and_return(Mgk.new)
end
it '原画から画像データを取得している' do
OriginalPicture.any_instance.should_receive(:restore).with(any_args).exactly(1)
res = @rp.op_mgk\r
end\r
- it '原画に原画データのRMagick変換を依頼している' do
- OriginalPicture.any_instance.should_receive(:data_to_mgk).with(any_args).exactly(1)
+ it '素材に原画データのRMagick変換を依頼している' do
+ ResourcePicture.any_instance.should_receive(:data_to_mgk).with(any_args).exactly(1)
res = @rp.op_mgk\r
end\r
end\r
context 'つつがなく終わるとき' do
#原画から画像データを取得する。\r
- #原画に原画データのRMagick変換を依頼し、画像オブジェクトを返す。 \r
+ #素材に原画データのRMagick変換を依頼し、画像オブジェクトを返す。 \r
before do
@mgk = Mgk.new\r
OriginalPicture.any_instance.stub(:restore).with(any_args).and_return('data')\r
- OriginalPicture.any_instance.stub(:data_to_mgk).with(any_args).and_return(@mgk)
+ ResourcePicture.any_instance.stub(:data_to_mgk).with(any_args).and_return(@mgk)
end
it '画像オブジェクトを返す' do
res = @rp.op_mgk\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
+ attr = {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => 'tester', \r
+ :credit => '{}', :settings => {:reverse => 1, :gif_convert => 1}.to_json.to_s}\r
@rp = Factory.build :resource_picture, attr
@mgk = Mgk.new
end
@mgk = Mgk.new #一回目の本画像保存は与えたオブジェクトを使って保存する。
ResourcePicture.any_instance.stub(:op_mgk).with(any_args).and_return(@mgk)\r
ResourcePicture.any_instance.stub(:new_picture).with(any_args).and_return(@p)\r
- 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)
+ ResourcePicture.any_instance.stub(:store_picture_with_gif).with(any_args).and_return(true)\r
end
it '素材に原画からのコピーデータをセットしている' do
ResourcePicture.any_instance.stub(:copy_data).with(any_args).and_return(true)\r
res = @rp.store\r
end\r
it '画像ファイルの作成・更新機能で画像を保存している' do\r
- ResourcePicture.any_instance.should_receive(:store_picture).with(@mgk).exactly(1)
- res = @rp.store\r
- end\r
- it '自身にフォーマット変換対象かを問い合わせている' do
- ResourcePicture.any_instance.should_receive(:to_gif?).with(any_args).exactly(1)
- res = @rp.store\r
- end\r
- it '自身にGifフォーマット変換を依頼している' do
- ResourcePicture.should_receive(:png_to_gif).with(any_args).exactly(1)
- res = @rp.store\r
- end\r
- it '画像ファイルの作成・更新機能でgif画像を保存している' do\r
- #二回目の保存はgif変換の結果を渡す。
- ResourcePicture.any_instance.should_receive(:store_picture).with(@gifmgk).exactly(1)
+ ResourcePicture.any_instance.should_receive(:store_picture_with_gif).with(@mgk).exactly(1)
res = @rp.store\r
end\r
end
@mgk = Mgk.new #一回目の本画像保存は与えたオブジェクトを使って保存する。
ResourcePicture.any_instance.stub(:op_mgk).with(any_args).and_return(@mgk)\r
ResourcePicture.any_instance.stub(:new_picture).with(any_args).and_return(@p)\r
- 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)
+ ResourcePicture.any_instance.stub(:store_picture_with_gif).with(any_args).and_return(true)\r
end
it 'Trueを返す' do
res = @rp.store\r
}.should change ResourcePicture, :count\r
end\r
end
- context 'gif変換なしで、つつがなく終わるとき' do
- before do
- #すべての処理を正常パターンで通過させ、保存機能をチェックする。
- @mgk = Mgk.new #一回目の本画像保存は与えたオブジェクトを使って保存する。
- ResourcePicture.any_instance.stub(:op_mgk).with(any_args).and_return(@mgk)\r
- ResourcePicture.any_instance.stub(:new_picture).with(any_args).and_return(@p)\r
- 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\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\r
- end\r
- end
#以下から例外ケース。処理先頭から失敗させていく
context '画像オブジェクトの取得に失敗したとき' do
before do
@rp.store
@rp.should be_a_new ResourcePicture\r
end
+ it '処理を中断してロールバックする' do
+ lambda {
+ res = @rp.store\r
+ }.should_not change Picture, :count\r
+ end
end
+ 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
+ #以下から例外ケース。処理先頭から失敗させていく
context '画像の保存に失敗したとき' do
before do
@mgk = Mgk.new #一回目の本画像保存は与えたオブジェクトを使って保存する。
- ResourcePicture.any_instance.stub(:op_mgk).with(any_args).and_return(@mgk)\r
- ResourcePicture.any_instance.stub(:new_picture).with(any_args).and_return(@p)\r
- ResourcePicture.any_instance.stub(:save).with(any_args).and_return(true)\r
ResourcePicture.any_instance.stub(:store_picture).with(any_args).and_return(false)\r
end
it 'Falseを返す' do
- res = @rp.store\r
+ res = @rp.store_picture_with_gif @mgk\r
res.should be_false\r
end\r
it 'gif変換判定は呼ばれていない' do\r
ResourcePicture.any_instance.should_not_receive(:to_gif?).with(any_args)
- res = @rp.store\r
+ res = @rp.store_picture_with_gif @mgk\r
end\r
end
context 'gif変換に失敗したとき' do
before do
@mgk = Mgk.new #一回目の本画像保存は与えたオブジェクトを使って保存する。
- ResourcePicture.any_instance.stub(:op_mgk).with(any_args).and_return(@mgk)\r
- ResourcePicture.any_instance.stub(:new_picture).with(any_args).and_return(@p)\r
- ResourcePicture.any_instance.stub(:save).with(any_args).and_return(true)\r
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
ResourcePicture.stub(:png_to_gif).with(any_args).and_return(false)
end
it 'Falseを返す' do
- res = @rp.store\r
+ res = @rp.store_picture_with_gif @mgk\r
res.should be_false\r
end\r
it 'gif画像の保存は呼ばれていない' do\r
#本画像の保存があるので、一度は呼ばれる\r
ResourcePicture.any_instance.should_receive(:store_picture).with(any_args).exactly(1)
- res = @rp.store\r
+ res = @rp.store_picture_with_gif @mgk\r
end\r
end
context 'gif画像の保存に失敗したとき' do
before do\r
@mgk = Mgk.new
- ResourcePicture.any_instance.stub(:op_mgk).with(any_args).and_return(@mgk)\r
- ResourcePicture.any_instance.stub(:new_picture).with(any_args).and_return(@p)\r
- ResourcePicture.any_instance.stub(:save).with(any_args).and_return(true)\r
ResourcePicture.any_instance.stub(:store_picture).with(@mgk).and_return(true)\r
ResourcePicture.any_instance.stub(:to_gif?).with(any_args).and_return(true)\r
class GifMgk < Mgk ; end #store_pictureは二回呼び出される。区別をつけるために\r
ResourcePicture.any_instance.stub(:store_picture).with(@gifmgk).and_return(false)\r
end
it 'Falseを返す' do
- res = @rp.store\r
+ res = @rp.store_picture_with_gif @mgk\r
res.should be_false\r
end\r
end