end
end
+ describe '実素材id置換に於いて' do
+ before do
+ @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
+ @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+ @rpattr = {:original_picture_id => @op.id, :picture_id => 3, :license_id => @license.id, :artist_id => @artist.id, :artist_name => 'tester',
+ :credit => '{}', :settings => {:reverse => 1, :gif_convert => 1}.to_json.to_s}
+ end
+ context '事前チェックする' do
+ before do
+ Picture.stub(:head).with(any_args).and_return(@p)
+ end
+ it '実素材にhead取得を問い合わせている' do
+ Picture.should_receive(:head).with(any_args).exactly(1)
+ r = ProviderOriginalPicture.replace_picture @provider.id, @rpattr
+ end
+ end
+ context 'つつがなく終わるとき' do
+ before do
+ Picture.stub(:head).with(any_args).and_return(@p)
+ end
+ it 'trueを返す' do
+ r = ProviderOriginalPicture.replace_picture @provider.id, @rpattr
+ r.should be_true
+ end
+ it 'カラム値の実素材idを借手側の実素材のidで置き換える' do
+ r = ProviderOriginalPicture.replace_picture @provider.id, @rpattr
+ @rpattr['picture_id'].should eq @p.id
+ end
+ end
+ context '借手側の実素材がなかったとき' do
+ before do
+ Picture.stub(:head).with(any_args).and_return(nil)
+ end
+ it 'falseを返す' do
+ r = ProviderOriginalPicture.replace_picture @provider.id, @rpattr
+ r.should be_false
+ end
+ end
+ end
+
describe '原画id置換に於いて' do
before do
@op = FactoryGirl.create :original_picture, :artist_id => @artist.id
end
end
+ describe '素材停止に於いて' do
+ before do
+ @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
+ @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+ rpattr = {:original_picture_id => @op.id, :picture_id => @p.id, :license_id => @license.id, :artist_id => @artist.id, :artist_name => 'tester',
+ :credit => '{}', :settings => {:reverse => 1, :gif_convert => 1}.to_json.to_s}
+ @rp = FactoryGirl.create :resource_picture, rpattr
+ end
+ context '貸手側原画のカラム値の停止日時が設定されているとき' do
+ before do
+ @pop = ProviderOriginalPicture.create :provider_id => @provider.id, :providers_original_picture_id => 1, :demanders_original_picture_id => @op.id
+ @stopped_op = FactoryGirl.build :original_picture, :artist_id => @artist.id, :stopped_at => Time.now + 400
+ @stopped_op_attr = @stopped_op.attributes
+ ResourcePicture.any_instance.stub(:unpublish).with(any_args).and_return(true)
+ end
+ context '対照表から素材を取得できるとき' do
+ before do
+ @stopped_op = FactoryGirl.build :original_picture, :artist_id => @artist.id, :stopped_at => Time.now + 400
+ end
+ it '素材に停止を依頼している' do
+ ResourcePicture.any_instance.should_receive(:unpublish).with(any_args).exactly(1)
+ r = ProviderOriginalPicture.unpublish_resource_picture @pop, @stopped_op_attr
+ end
+ end
+ context '対照表から原画を取得できないとき' do
+ before do
+ @pop = ProviderOriginalPicture.new
+ end
+ it '素材に停止を依頼していない' do
+ ResourcePicture.any_instance.should_not_receive(:unpublish).with(any_args)
+ r = ProviderOriginalPicture.unpublish_resource_picture @pop, @stopped_op_attr
+ end
+ end
+ context '対照表から素材を取得できないとき' do
+ before do
+ @rp.destroy
+ end
+ it '素材に停止を依頼していない' do
+ ResourcePicture.any_instance.should_not_receive(:unpublish).with(any_args)
+ r = ProviderOriginalPicture.unpublish_resource_picture @pop, @stopped_op_attr
+ end
+ end
+ end
+ context '貸手側原画のカラム値の停止日時が設定されていないとき' do
+ before do
+ @pop = ProviderOriginalPicture.create :provider_id => @provider.id, :providers_original_picture_id => 1, :demanders_original_picture_id => @op.id
+ @stopped_op = FactoryGirl.build :original_picture, :artist_id => @artist.id, :stopped_at => nil
+ @stopped_op_attr = @stopped_op.attributes
+ ResourcePicture.any_instance.stub(:unpublish).with(any_args).and_return(true)
+ end
+ it '素材に停止を依頼していない' do
+ ResourcePicture.any_instance.should_not_receive(:unpublish).with(any_args)
+ r = ProviderOriginalPicture.unpublish_resource_picture @pop, @stopped_op_attr
+ end
+ end
+ context 'つつがなく終わるとき' do
+ before do
+ @pop = ProviderOriginalPicture.create :provider_id => @provider.id, :providers_original_picture_id => 1, :demanders_original_picture_id => @op.id
+ @stopped_op = FactoryGirl.build :original_picture, :artist_id => @artist.id, :stopped_at => Time.now + 400
+ @stopped_op_attr = @stopped_op.attributes
+ ResourcePicture.any_instance.stub(:unpublish).with(any_args).and_return(true)
+ end
+ it 'trueを返す' do
+ r = ProviderOriginalPicture.unpublish_resource_picture @pop, @stopped_op_attr
+ r.should be_true
+ end
+ end
+ context '素材停止に失敗したとき' do
+ before do
+ @pop = ProviderOriginalPicture.create :provider_id => @provider.id, :providers_original_picture_id => 1, :demanders_original_picture_id => @op.id
+ @stopped_op = FactoryGirl.build :original_picture, :artist_id => @artist.id, :stopped_at => Time.now + 400
+ @stopped_op_attr = @stopped_op.attributes
+ ResourcePicture.any_instance.stub(:unpublish).with(any_args).and_return(false)
+ end
+ it 'falseを返す' do
+ r = ProviderOriginalPicture.unpublish_resource_picture @pop, @stopped_op_attr
+ r.should be_false
+ end
+ end
+ end
+
describe '原画インポートに於いて' do
before do
@op = FactoryGirl.create :original_picture, :artist_id => @artist.id
before do
ProviderOriginalPicture.stub(:get_one).with(any_args).and_return(ProviderOriginalPicture.new)
ProviderOriginalPicture.stub(:replace_artist).with(any_args).and_return(true)
+ ProviderOriginalPicture.stub(:unpublish_resource_picture).with(any_args).and_return(true)
ProviderOriginalPicture.any_instance.stub(:modify_original_picture).with(any_args).and_return(@op)
OriginalPicture.any_instance.stub(:valid?).with(any_args).and_return(true)
ProviderOriginalPicture.any_instance.stub(:save).with(any_args).and_return(true)
ProviderOriginalPicture.should_receive(:replace_artist).with(any_args).exactly(1)
r = ProviderOriginalPicture.import_original_pictures @provider.id, [@op.attributes]
end
- it '対照表に原画同期を依頼してしている' do
+ it '素材停止を依頼している' do
+ ProviderOriginalPicture.should_receive(:unpublish_resource_picture).with(any_args).exactly(1)
+ r = ProviderOriginalPicture.import_original_pictures @provider.id, [@op.attributes]
+ end
+ it '対照表に原画同期を依頼している' do
ProviderOriginalPicture.any_instance.should_receive(:modify_original_picture).with(any_args).exactly(1)
r = ProviderOriginalPicture.import_original_pictures @provider.id, [@op.attributes]
end
end
context '複数インポートのとき' do
before do
+ #前回インポートで貸手からもらった素材
+ @other_p = FactoryGirl.create :picture, :original_picture_id => @other_op.id, :license_id => @license.id, :artist_id => @artist.id
+ rpattr = {:original_picture_id => @other_op.id, :picture_id => @other_p.id, :license_id => @license.id, :artist_id => @artist.id, :artist_name => 'tester',
+ :credit => '{}', :settings => {:reverse => 1, :gif_convert => 1}.to_json.to_s}
+ @other_rp = FactoryGirl.create :resource_picture, rpattr
+ #対照表も用意されている
+ @pop = ProviderOriginalPicture.create :provider_id => @provider.id, :providers_original_picture_id => @other_op.id, :demanders_original_picture_id => @other_op.id
+ #これが今回停止される
+ @other_op_attr = @other_op.attributes
+ @other_op_attr['stopped_at'] = Time.now - 100
+ @other_op_attr['created_at'] = Time.now - 100
+ @other_op_attr['updated_at'] = Time.now - 100
ProviderOriginalPicture.stub(:replace_artist).with(any_args).and_return(true)
end
it '空っぽの配列を返す' do
- r = ProviderOriginalPicture.import_original_pictures @provider.id, [@op.attributes, @other_op.attributes]
+ r = ProviderOriginalPicture.import_original_pictures @provider.id, [@op.attributes, @other_op_attr]
r.should be_empty
end
- it '対照表が追加される' do
+ it '新規分の対照表が追加される' do
lambda {
- r = ProviderOriginalPicture.import_original_pictures @provider.id, [@op.attributes, @other_op.attributes]
- }.should change(ProviderOriginalPicture, :count).by(2)
+ r = ProviderOriginalPicture.import_original_pictures @provider.id, [@op.attributes, @other_op_attr]
+ }.should change(ProviderOriginalPicture, :count)
+ end
+ it '停止された素材が削除される' do
+ lambda {
+ r = ProviderOriginalPicture.import_original_pictures @provider.id, [@op.attributes, @other_op_attr]
+ }.should change(ResourcePicture, :count)
+ end
+ it '原画の日時は貸手と一致しており、素材停止の影響を受けていない' do
+ r = ProviderOriginalPicture.import_original_pictures @provider.id, [@op.attributes, @other_op_attr]
+ @other_op.reload
+ @other_op.updated_at.should eq @other_op_attr['updated_at']
end
end
#警告ケース
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)
+ ProviderOriginalPicture.stub(:replace_picture).with(any_args).and_return(true)
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(:replace_license).with(any_args).exactly(1)
r = ProviderOriginalPicture.import_resource_pictures @provider.id, [@attr]
end
+ it '実素材id置換を依頼している' do
+ ProviderOriginalPicture.should_receive(:replace_picture).with(any_args).exactly(1)
+ r = ProviderOriginalPicture.import_resource_pictures @provider.id, [@attr]
+ end
it '画像データをデコードしている' do
Base64.should_receive(:decode64).with(any_args).exactly(1)
r = ProviderOriginalPicture.import_resource_pictures @provider.id, [@attr]
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
+ 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
+ context '素材のカラム値を取得できないとき' do
+ before do
+ @attr['resource_picture'] = nil
+ ProviderOriginalPicture.stub(:import_resource_picture).with(any_args).and_return(nil)
+ end
+ it '素材インポートを依頼していない' do
+ ProviderOriginalPicture.should_not_receive(:import_resource_picture).with(any_args)
+ r = ProviderOriginalPicture.import_resource_pictures @provider.id, [@attr]
+ end
+ end
end
context 'つつがなく終わるとき' do
before do
r.should_not be_empty
end
end
+ context '実素材id置換に失敗したとき' 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)
+ ProviderOriginalPicture.stub(:replace_picture).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]
+ 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]
ProviderOriginalPicture.stub(:import_pictures).with(any_args).and_return([])
ProviderOriginalPicture.stub(:import_resource_pictures).with(any_args).and_return([])
end
- it '各失敗したカラム値をHashで返す' do
+ it 'ImportResultを返す' do
r = ProviderOriginalPicture.import @provider.id, [@opattr], [@pattr]
- r[:original_pictures].should be_empty
- r[:pictures].should be_empty
- r[:resource_pictures].should be_empty
+ r.is_a?(ImportResult).should be_true
+ r.should be_success
end
end
#警告ケース
ProviderOriginalPicture.stub(:import_pictures).with(any_args).and_return([])
ProviderOriginalPicture.stub(:import_resource_pictures).with(any_args).and_return([])
end
- it '失敗した原画のカラム値を配列でoriginal_picturesに追加している' do
+ it '結果が失敗している' do
r = ProviderOriginalPicture.import @provider.id, [@opattr], [@pattr]
- r[:original_pictures].should_not be_empty
- r[:pictures].should be_empty
- r[:resource_pictures].should be_empty
+ r.should_not be_success
+ r.is_a?(OriginalPictureImportResult).should be_true
+ r.failures.should_not be_empty
end
end
context '実素材インポートに失敗したとき' do
ProviderOriginalPicture.stub(:import_pictures).with(any_args).and_return([@pattr])
ProviderOriginalPicture.stub(:import_resource_pictures).with(any_args).and_return([])
end
- it '失敗した原画のカラム値を配列でpicturesに追加している' do
+ it '結果が失敗している' do
r = ProviderOriginalPicture.import @provider.id, [@opattr], [@pattr]
- r[:original_pictures].should be_empty
- r[:pictures].should_not be_empty
- r[:resource_pictures].should be_empty
+ r.should_not be_success
+ r.is_a?(PictureImportResult).should be_true
+ r.failures.should_not be_empty
end
end
context '素材インポートに失敗したとき' do
ProviderOriginalPicture.stub(:import_pictures).with(any_args).and_return([])
ProviderOriginalPicture.stub(:import_resource_pictures).with(any_args).and_return([@rpattr])
end
- it '失敗した原画のカラム値を配列でresource_picturesに追加している' do
+ it '結果が失敗している' do
r = ProviderOriginalPicture.import @provider.id, [@opattr], [@pattr]
- r[:original_pictures].should be_empty
- r[:pictures].should be_empty
- r[:resource_pictures].should_not be_empty
+ r.should_not be_success
+ r.is_a?(ResourcePictureImportResult).should be_true
+ r.failures.should_not be_empty
end
end
end