end
end
+ def replace_system_picture attr
+ d = attr["system_picture"]
+ return nil if d.blank?
+ sp = SystemPicture.store Base64.decode64(d.to_s)
+ return false unless sp
+ attr["system_picture_id"] = sp.id
+ attr.delete "system_picture"
+ true
+ end
+
def modify_object(name, attr, key = 'name')
c = 'find_by_' + key.to_s
r = self.__send__ c, name
@f = File.expand_path(File.dirname(__FILE__) + '/import.json')
end
+ describe 'システム画像置換に於いて' do
+ before do
+ @attr = {"system_picture" => 'DAt'}
+ @sp = Factory :system_picture
+ end
+ context 'つつがなく終わるとき' do
+ it 'システム画像に保存を依頼している' do
+ SystemPicture.stub(:store).with(any_args).and_return(@sp)
+ SystemPicture.should_receive(:store).with(any_args).exactly(1)
+ r = Import.replace_system_picture(@attr)
+ end
+ it 'system_pictureキーを削除している' do
+ SystemPicture.stub(:store).with(any_args).and_return(@sp)
+ r = Import.replace_system_picture(@attr)
+ @attr.has_key?("system_picture").should be_false
+ end
+ it 'system_picture_idキーを追加している' do
+ SystemPicture.stub(:store).with(any_args).and_return(@sp)
+ r = Import.replace_system_picture(@attr)
+ @attr.has_key?("system_picture_id").should be_true
+ end
+ it '値はシステム画像オブジェクトのidとしている' do
+ SystemPicture.stub(:store).with(any_args).and_return(@sp)
+ r = Import.replace_system_picture(@attr)
+ @attr["system_picture_id"].should eq @sp.id
+ end
+ it 'trueを返す' do
+ SystemPicture.stub(:store).with(any_args).and_return(@sp)
+ r = Import.replace_system_picture(@attr)
+ r.should be_true
+ end
+ end
+ context '例外ケース' do
+ it 'カラム値にsystem_pictureキーがなければnilを返す' do
+ @a = {}
+ SystemPicture.stub(:store).with(any_args).and_return(@sp)
+ r = Import.replace_system_picture(@a)
+ r.should be_nil
+ end
+ it 'カラム値のsystem_pictureキーの値が空ならばnilを返す' do
+ @a = {"system_picture" => ''}
+ SystemPicture.stub(:store).with(any_args).and_return(@sp)
+ r = Import.replace_system_picture(@a)
+ r.should be_nil
+ end
+ it 'システム画像の保存が失敗(False)ならFalseを返す' do
+ SystemPicture.stub(:store).with(any_args).and_return(false)
+ r = Import.replace_system_picture(@attr)
+ r.should be_false
+ end
+ end
+ end
describe '対象オブジェクトの更新準備に於いて' do
context 'つつがなく終わるとき' do
before do