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
#警告ケース
ResourcePicture.any_instance.should_receive(:save).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