attr['credit_pictures'] = attr['credit_pictures'].to_json
l = License.modify_object name, attr
if r == false
- l.errors.add :base, 'system picture can not create'
+ l.errors.add :base, SystemPicture.model_name.human + I18n.t('errors.not_create')
else
l.save
end
r.save
#取っておいたライセンスデータとidでライセンス作成
if (c = License.stores(lattr, r.id)) > 0
- r.errors.add :base, 'licenses can not create'
+ r.errors.add :base, License.model_name.human + I18n.t('errors.not_create')
end
r
end
def store(imager)
unless imager
- self.errors.add :base, 'illegal picture data'
+ self.errors.add :base, I18n.t('errors.invalid_image')
return false
end
res = false
self.attributes = {:ext => imager.ext, :width => imager.width, :height => imager.height, :filesize => imager.filesize, :md5 => imager.md5}
OriginalPicture.transaction do
if res = self.save
- if res = PictureIO.original_picture_io.put(imager.binary, self.filename)
- res = true
- else
- self.errors.add :base, 'original picture io does not work'
+ begin
+ res = PictureIO.original_picture_io.put(imager.binary, self.filename)
+ rescue PictureIO::Error
+ res = false
+ self.errors.add :base, I18n.t('picture_io.error')
raise ActiveRecord::Rollback
end
end
def store attr, au
if attr == false
- self.errors.add :base, 'invalid json'
+ self.errors.add :base, I18n.t('errors.invalid_json')
return false
end
self.attributes = attr
res = false
Panel.transaction do
unless validate_child
- self.errors.add :base , 'invalid time'
+ self.errors.add :base, I18n.t('errors.invalid_t')
raise ActiveRecord::Rollback
end
res = self.save
pc.overwrite self
r = pc.store imager
return pc if r
- self.errors.add :base, 'picture does not create' + pc.errors.full_messages.join("\n")
+ self.errors.add :base, Picture.model_name.human + I18n.t('errors.not_create')
false
end
if res = self.store_picture(imager, self.filename)
if self.to_gif?
if gifimager = imager.to_gif
- res = self.store_picture(gifimager, self.gifname)
+ if res = self.store_picture(gifimager, self.gifname)
+ else
+ self.errors.add :base, I18n.t('picture_io.error')
+ end
else
- self.errors.add :base, 'picture data can not conv to gif'
+ self.errors.add :base, I18n.t('errors.not_convert')
res = false
end
end
else
- self.errors.add :base, 'resource picture io does not work'
+ self.errors.add :base, I18n.t('picture_io.error')
end
res
end
res = false
thumbnail_imager = self.flag_thumbnail >= 0 ? imager.to_thumbnail : imager
return false unless thumbnail_imager
- return false unless PictureIO.resource_picture_io.put(thumbnail_imager.binary, fn)
- return false unless PictureIO.resource_picture_io.put(imager.binary, fn, 'full')
- true
+ begin
+ PictureIO.resource_picture_io.put(thumbnail_imager.binary, fn)
+ PictureIO.resource_picture_io.put(imager.binary, fn, 'full')
+ res = true
+ rescue PictureIO::Error
+ res = false
+ end
+ res
end
def restore(subdir = nil)
res = false
SystemPicture.transaction do
if res = self.save
- if res = PictureIO.system_picture_io.put(imager.binary, self.filename)
- res = true
- else
- self.errors.add :base, 'system picture io does not work'
+ begin
+ res = PictureIO.system_picture_io.put(imager.binary, self.filename)
+ rescue PictureIO::Error
+ res = false
+ self.errors.add :base, I18n.t('picture_io.error')
raise ActiveRecord::Rollback
end
end
<% if @artist -%>
<%= form_tag( original_pictures_path , { :multipart => true, :method => :post }) do %>
+ <% if @original_picture -%>
+ <%= render 'system/error_explanation', :obj => @original_picture %>
+ <% end -%>
<%= file_field_tag "original_picture[file]" %>
<%= submit_tag t 'original_pictures.upload' -%>
<% end -%>
ja:
+ errors:
+ not_create: が作成できません。
+ invalid_json: 不正なjsonデータです。
+ invalid_t: コマ要素の話順が不正です。
+ not_convert: Gif画像へのコンバートに失敗しました。
+ invalid_image: 画像として読み込めませんでした。
activerecord:
models:
user: ユーザ
provider_original_picture:
created_at: 作成
updated_at: 更新
+ picture_io:
+ error: 画像保管庫との手続きで異常が発生しました。
select_items:
comic:
visible:
begin
res = File.exist?(dir(subdir) + filename)
rescue
- res = false
+ raise PictureIO::Error
end
res
end
f.write bindata
end
rescue
- res = false
+ raise PictureIO::Error
end
res
end
bindata += f.read
end
rescue
- bindata = false
+ raise PictureIO::Error
end
bindata
end
begin
File.delete(dir(subdir) + filename)
rescue
- res = false
+ raise PictureIO::Error
end
res
end
class PictureIO
-
+ class Error < StandardError
+ end
+
def self.original_picture_io
@@original_picture_io
end
begin
res = AWS::S3::S3Object.exist?(dir(subdir) + filename, base)
rescue
- res = false
+ raise PictureIO::Error
end
res
end
begin
AWS::S3::S3Object.store(dir(subdir) + filename, bindata, base)
rescue
- res = false
+ raise PictureIO::Error
end
res
end
bindata += st if st
end
rescue
- bindata = false
+ raise PictureIO::Error
end
bindata
end
begin
AWS::S3::S3Object.delete(dir(subdir) + filename, base)
rescue
- res = false
+ raise PictureIO::Error
end
res
end
end
end
context 'ファイルがないとき' do
- it 'falseが返る' do
- @io.exist?('not.exist').should be_false
+ it 'PictureIO::Error例外が発生する' do
+ File.stub(:exist?).with(any_args()).and_raise(StandardError)
+ lambda {
+ @io.exist?('not.exist')
+ }.should raise_error(PictureIO::Error)
end
end
end
end
end
context '例外が発生するとき' do
- it 'falseが返る' do
+ it 'PictureIO::Error例外が発生する' do
File.stub(:open).with(any_args()).and_raise(StandardError)
- @io.get('test.get').should be_false
+ lambda {
+ r = @io.get('test.get')
+ }.should raise_error(PictureIO::Error)
end
end
end
end
end
context '例外が発生するとき' do
- it 'falseが返る' do
+ it 'PictureIO::Error例外が発生する' do
File.stub(:open).with(any_args()).and_raise(StandardError)
- @io.put('bindata', 'test.put').should be_false
+ lambda {
+ @io.put('bindata', 'test.put')
+ }.should raise_error(PictureIO::Error)
end
end
end
end
end
context '例外が発生するとき' do
- it 'falseが返る' do
+ it 'PictureIO::Error例外が発生する' do
File.stub(:delete).with(any_args()).and_raise(StandardError)
- @io.delete('test.del.not.exist').should be_false
+ lambda {
+ @io.delete('test.del.not.exist')
+ }.should raise_error(PictureIO::Error)
end
end
end
end
end
context '例外が発生するとき' do
- it 'falseが返る' do
+ it 'PictureIO::Error例外が発生する' do
AWS::S3::S3Object.stub(:exist?).with(any_args()).and_raise(StandardError)
- @io.exist?('test.get').should be_false
+ lambda {
+ @io.exist?('test.get')
+ }.should raise_error(PictureIO::Error)
end
end
end
end
end
context '例外が発生するとき' do
- it 'falseが返る' do
+ it 'PictureIO::Error例外が発生する' do
AWS::S3::S3Object.stub(:get).with(any_args()).and_raise(StandardError)
- @io.get('test.get').should be_false
+ lambda {
+ @io.get('test.get')
+ }.should raise_error(PictureIO::Error)
end
end
end
end
end
context '例外が発生するとき' do
- it 'falseが返る' do
+ it 'PictureIO::Error例外が発生する' do
AWS::S3::S3Object.stub(:store).with(any_args()).and_raise(StandardError)
- @io.put('bindata', 'test.put').should be_false
+ lambda {
+ @io.put('bindata', 'test.put')
+ }.should raise_error(PictureIO::Error)
end
end
end
end
end
context '例外が発生するとき' do
- it 'falseが返る' do
+ it 'PictureIO::Error例外が発生する' do
AWS::S3::S3Object.stub(:delete).with(any_args()).and_raise(StandardError)
- @io.delete('test.del.not.exist').should be_false
+ lambda {
+ @io.delete('test.del.not.exist')
+ }.should raise_error(PictureIO::Error)
end
end
end
end
context '検証、保存に失敗した' do
before do
+ OriginalPicture.any_instance.stub(:restore).with(any_args()).and_return(@imager.binary)
+ PettanImager.stub(:load).with(@imager.binary).and_return(@imager)
ResourcePicture.any_instance.stub(:store).and_return(false)
end
it "未保存の素材を保持している" do
@l.license_group_id = ''
@l.should_not be_valid
end
- it '数値でなければ失敗する' do\r
- @l.license_group_id = 'a'\r
- @l.should_not be_valid\r
- end\r
- it '存在するライセンスグループでなければ失敗する' do\r
- @l.license_group_id = 0\r
- @l.should_not be_valid\r
- end\r
+ it '数値でなければ失敗する' do
+ @l.license_group_id = 'a'
+ @l.should_not be_valid
+ end
+ it '存在するライセンスグループでなければ失敗する' do
+ @l.license_group_id = 0
+ @l.should_not be_valid
+ end
end
context 'nameを検証するとき' do
it 'nullなら失敗する' do
@l.should_not be_valid
end
it 'url形式でないなら失敗する' do
- @l.url = 'a'*200\r
- @l.should_not be_valid\r
+ @l.url = 'a'*200
+ @l.should_not be_valid
end
end
context 'system_picture_idを検証するとき' do
@l.system_picture_id = ''
@l.should_not be_valid
end
- it '数値でなければ失敗する' do\r
- @l.system_picture_id = 'a'\r
- @l.should_not be_valid\r
- end\r
- it '存在するシステム画像でなければ失敗する' do\r
- @l.system_picture_id = 0\r
- @l.should_not be_valid\r
- end\r
+ it '数値でなければ失敗する' do
+ @l.system_picture_id = 'a'
+ @l.should_not be_valid
+ end
+ it '存在するシステム画像でなければ失敗する' do
+ @l.system_picture_id = 0
+ @l.should_not be_valid
+ end
end
end
@l = FactoryGirl.create :license, :name => 'peta2.0', :license_group_id => @lg.id, :system_picture_id => @sp.id
@lg2 = FactoryGirl.create :license_group, :name => 'pubdm'
end
- context 'つつがなく終わるとき' do\r
- it '一覧取得オプションを利用している' do\r
- License.stub(:list_opt).with(any_args).and_return({})\r
- License.should_receive(:list_opt).with(any_args).exactly(1)\r
+ context 'つつがなく終わるとき' do
+ it '一覧取得オプションを利用している' do
+ License.stub(:list_opt).with(any_args).and_return({})
+ License.should_receive(:list_opt).with(any_args).exactly(1)
r = License.list
- end\r
- end\r
+ end
+ end
it 'リストを返す' do
l = License.list
l.should eq [@l]
@lg = FactoryGirl.create :license_group
@l = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
end
- context 'つつがなく終わるとき' do\r
- it '単体取得オプションを利用している' do\r
- License.stub(:show_opt).with(any_args).and_return({})\r
- License.should_receive(:show_opt).with(any_args).exactly(1)\r
+ context 'つつがなく終わるとき' do
+ it '単体取得オプションを利用している' do
+ License.stub(:show_opt).with(any_args).and_return({})
+ License.should_receive(:show_opt).with(any_args).exactly(1)
r = License.show @l.id
- end\r
- end\r
+ end
+ end
it '指定のライセンスを返す' do
l = License.show @l.id
l.should eq @l
end
- context '存在しないライセンスを開こうとしたとき' do\r
- it '404RecordNotFound例外を返す' do\r
- lambda{\r
- License.show 110\r
- }.should raise_error(ActiveRecord::RecordNotFound)\r
- end\r
- end\r
+ context '存在しないライセンスを開こうとしたとき' do
+ it '404RecordNotFound例外を返す' do
+ lambda{
+ License.show 110
+ }.should raise_error(ActiveRecord::RecordNotFound)
+ end
+ end
end
describe '単体取得オプションに於いて' do
it 'includeキーを含んでいる' do
context '原画の保存に失敗したとき' do
before do
OriginalPicture.any_instance.stub(:save).with(any_args).and_return(true)
- PictureIO.original_picture_io.stub(:put).with(any_args).and_return(false)
+ PictureIO.original_picture_io.stub(:put).with(any_args).and_raise(PictureIO::Error)
end
it 'falseを返す' do
@op.store(@imager).should be_false
}.should change(Panel, :count)\r
end\r
end\r
+ context '不正なjsonデータのとき' do\r
+ before do\r
+ end\r
+ it 'エラーメッセージがセットされている' do\r
+ r = @panel.store false, @author\r
+ @panel.errors[:base].should_not be_blank\r
+ end\r
+ end\r
context '従属データの検証に失敗したとき' do\r
before do\r
Panel.any_instance.stub(:validate_child).with(any_args).and_return(false)\r
end\r
it 'エラーメッセージがセットされている' do\r
r = @panel.store @attr, @author\r
- @panel.errors.should_not be_empty\r
+ @panel.errors[:base].should_not be_blank\r
end\r
end\r
context 'カラム値がFalseしたとき' do\r
r = @rp.store_picture_with_gif @imager\r
r.should be_false\r
end\r
+ it '全体エラーメッセージがセットされている' do\r
+ lambda {\r
+ r = @rp.store_picture_with_gif @imager\r
+ }.should change(@rp.errors[:base], :count)\r
+ end\r
it 'gif変換判定は呼ばれていない' do\r
ResourcePicture.any_instance.should_not_receive(:to_gif?).with(any_args)\r
r = @rp.store_picture_with_gif @imager\r
r = @rp.store_picture_with_gif @imager\r
r.should be_false\r
end\r
+ it '全体エラーメッセージがセットされている' do\r
+ lambda {\r
+ r = @rp.store_picture_with_gif @imager\r
+ }.should change(@rp.errors[:base], :count)\r
+ end\r
it 'gif画像の保存は呼ばれていない' do\r
#本画像の保存があるので、一度は呼ばれる\r
ResourcePicture.any_instance.should_receive(:store_picture).with(any_args).exactly(1)\r
r = @rp.store_picture_with_gif @imager\r
r.should be_false\r
end\r
+ it '全体エラーメッセージがセットされている' do\r
+ lambda {\r
+ r = @rp.store_picture_with_gif @imager\r
+ }.should change(@rp.errors[:base], :count)\r
+ end\r
end\r
end\r
\r
ResourcePicture.any_instance.stub(:flag_thumbnail).with(any_args).and_return(1)\r
@tmbimager = @imager.to_thumbnail\r
ImagerTest.any_instance.stub(:to_thumbnail).with(any_args).and_return(@tmbimager)\r
- PictureIO.resource_picture_io.stub(:put).with(@tmbimager.binary, '1.gif').and_return(false)\r
+ PictureIO.resource_picture_io.stub(:put).with(@tmbimager.binary, '1.gif').and_raise(PictureIO::Error)\r
end\r
it 'Falseを返す' do\r
r = @rp.store_picture(@imager, '1.gif')\r
@tmbimager = @imager.to_thumbnail\r
ImagerTest.any_instance.stub(:to_thumbnail).with(any_args).and_return(@tmbimager)\r
PictureIO.resource_picture_io.stub(:put).with(@tmbimager.binary, '1.gif').and_return(true)\r
- PictureIO.resource_picture_io.stub(:put).with(@imager.binary, '1.gif', 'full').and_return(false)\r
+ PictureIO.resource_picture_io.stub(:put).with(@imager.binary, '1.gif', 'full').and_raise(PictureIO::Error)\r
end\r
it 'Falseを返す' do\r
r = @rp.store_picture(@imager, '1.gif')\r
@sp3 = FactoryGirl.create :system_picture, :updated_at => Time.now + 200
@sp4 = FactoryGirl.create :system_picture, :updated_at => Time.now + 300
@sp5 = FactoryGirl.create :system_picture, :updated_at => Time.now + 400
- SystemPicture.stub(:default_page_size).and_return(2)\r
+ SystemPicture.stub(:default_page_size).and_return(2)
end
it '通常は2件を返す' do
r = SystemPicture.list
@sp3 = FactoryGirl.create :system_picture, :updated_at => Time.now + 200
@sp4 = FactoryGirl.create :system_picture, :updated_at => Time.now + 300
@sp5 = FactoryGirl.create :system_picture, :updated_at => Time.now + 400
- SystemPicture.stub(:default_page_size).and_return(2)\r
+ SystemPicture.stub(:default_page_size).and_return(2)
end
it '件数0は全件(5件)を返す' do
r = SystemPicture.list 5, 0
r = @sp.store @imager
end
end
+ context '画像データの保存に失敗したとき' do
+ before do
+ PictureIO.system_picture_io.stub(:put).with(any_args).and_raise(PictureIO::Error)
+ end
+ it 'falseを返す' do
+ r = @sp.store @imager
+ r.should be_false
+ end
+ it '更新されていない' do
+ r = @sp.store @imager
+ @sp.should be_a_new SystemPicture
+ end
+ it '全体エラーメッセージがセットされている' do
+ r = @sp.store @imager
+ @sp.errors[:base].should_not be_blank
+ end
+ end
end
describe '置換に於いて' do