end
def self.modify_picture attr
- p = Picture.find_by_original_picture_id_and_revision(attr['original_picture_id'], attr['revision']) || Picture.new
- p.attributes = attr
- p
+ pc = Picture.find_by_original_picture_id_and_revision(attr['original_picture_id'], attr['revision']) || Picture.new
+ pc.attributes = attr
+ pc
end
def self.modify_resource_picture attr
imager = PettanImager.load(picture_data)
return providers_resource_picture_attr unless imager
resource_picture = ProviderOriginalPicture.modify_resource_picture providers_resource_picture_attr
- return providers_resource_picture_attr unless resource_picture.store(imager)
+ return providers_resource_picture_attr unless resource_picture.store_picture_with_gif(imager)
+ return providers_resource_picture_attr unless resource_picture.save
nil
end
Base64.stub(:decode64).with(any_args).and_return("abc\ndef\nghi")
PettanImager.stub(:load).with("abc\ndef\nghi").and_return(@imager)
ProviderOriginalPicture.stub(:modify_resource_picture).with(any_args).and_return(@rp)
- ResourcePicture.any_instance.stub(:store).with(any_args).and_return(true)
+ ResourcePicture.any_instance.stub(:store_picture_with_gif).with(any_args).and_return(true)
+ ResourcePicture.any_instance.stub(:save).with(any_args).and_return(true)
end
it '原画id置換を依頼している' do
ProviderOriginalPicture.should_receive(:replace_original_picture).with(any_args).exactly(1)
ProviderOriginalPicture.should_receive(:modify_resource_picture).with(any_args).exactly(1)
r = ProviderOriginalPicture.import_resource_pictures @provider.id, [@attr]
end
+ it '素材にgif付き画像ファイルの作成・更新を依頼している' do
+ ResourcePicture.any_instance.should_receive(:store_picture_with_gif).with(any_args).exactly(1)
+ r = ProviderOriginalPicture.import_resource_pictures @provider.id, [@attr]
+ end
it '素材を保存している' do
- ResourcePicture.any_instance.should_receive(:store).with(any_args).exactly(1)
+ ResourcePicture.any_instance.should_receive(:save).with(any_args).exactly(1)
r = ProviderOriginalPicture.import_resource_pictures @provider.id, [@attr]
end
end
r.should_not be_empty
end
end
+ context 'gif付き画像ファイルの作成・更新に失敗したとき' do
+ before do
+ ProviderOriginalPicture.stub(:replace_original_picture).with(any_args).and_return(true)
+ ProviderOriginalPicture.stub(:replace_artist).with(any_args).and_return(true)
+ ProviderOriginalPicture.stub(:replace_license).with(any_args).and_return(true)
+ PettanImager.stub(:load).with(any_args).and_return(@imager)
+ ProviderOriginalPicture.stub(:modify_resource_picture).with(any_args).and_return(@rp)
+ ResourcePicture.any_instance.stub(:store_picture_with_gif).with(any_args).and_return(false)
+ end
+ it '結果に素材のカラム値を追加している' do
+ r = ProviderOriginalPicture.import_resource_pictures @provider.id, [@attr]
+ r.should_not be_empty
+ end
+ end
context '素材の保存に失敗したとき' do
before do
ProviderOriginalPicture.stub(:replace_original_picture).with(any_args).and_return(true)
ProviderOriginalPicture.stub(:replace_license).with(any_args).and_return(true)
PettanImager.stub(:load).with(any_args).and_return(@imager)
ProviderOriginalPicture.stub(:modify_resource_picture).with(any_args).and_return(@rp)
- ResourcePicture.any_instance.stub(:store).with(any_args).and_return(false)
+ ResourcePicture.any_instance.stub(:store_picture_with_gif).with(any_args).and_return(true)
+ ResourcePicture.any_instance.stub(:save).with(any_args).and_return(false)
end
it '結果に素材のカラム値を追加している' do
r = ProviderOriginalPicture.import_resource_pictures @provider.id, [@attr]