@p = FactoryGirl.create :picture, :original_picture_id => @original_picture.id, :license_id => @license.id, :artist_id => @artist.id\r
@rp = FactoryGirl.build :resource_picture, :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id, :picture_id => @p.id\r
end\r
- it '素材を更新することはないので、Falseを返す' do\r
- @rp.own?(@author).should == false\r
+ context '事前チェックする' do\r
+ it '自身にロールリストからの絵師取得を依頼している' do\r
+ ResourcePicture.should_receive(:get_artist_from_roles).with(any_args).exactly(1)\r
+ r = @rp.own?([@author])\r
+ end\r
+ end\r
+ context 'ロール内絵師が取得できるとき' do\r
+ before do\r
+ end\r
+ it 'ロール内絵師のidが自身の絵師idと一致するなら許可する' do\r
+ ResourcePicture.stub(:get_artist_from_roles).with(any_args).and_return(@artist)\r
+ r = @rp.own?([@author])\r
+ r.should be_true\r
+ end\r
+ it 'ロール内絵師のidが自身の絵師idと一致しないならno' do\r
+ ResourcePicture.stub(:get_artist_from_roles).with(any_args).and_return(@other_artist)\r
+ @rp.own?(@other_artist).should be_false\r
+ end\r
+ end\r
+ context 'ロール内絵師が取得できないとき' do\r
+ before do\r
+ ResourcePicture.stub(:get_artist_from_roles).with(any_args).and_return(nil)\r
+ end\r
+ it 'Falseを返す' do\r
+ r = @rp.own?([@author])\r
+ r.should be_false\r
+ end\r
end\r
end\r
\r
@p = FactoryGirl.create :picture, :original_picture_id => @original_picture.id, :license_id => @license.id, :artist_id => @artist.id\r
@rp = FactoryGirl.build :resource_picture, :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id, :picture_id => @p.id\r
end\r
- context '検査対象がnil(ゲスト)のとき' do\r
- context 'クローズドモードのとき' do\r
- before do\r
- MagicNumber['run_mode'] = 1\r
- end\r
- it '不許可を返す。' do\r
- r = @rp.visible?(nil)\r
- r.should be_false\r
- end\r
- end\r
- context 'オープンモードのとき' do\r
- before do\r
- MagicNumber['run_mode'] = 0\r
- end\r
- it '許可する' do\r
- r = @rp.visible?(nil)\r
- r.should be_true\r
- end\r
- end\r
- end\r
- context '検査対象が作家のとき' do\r
- it '許可する' do\r
- r = @rp.visible?(@author)\r
- r.should == true\r
+ context 'オープンモードのとき' do\r
+ before do\r
+ MagicNumber['run_mode'] = 0\r
+ end\r
+ it '自身にゲスト用ロールチェックを問い合わせしている' do\r
+ ResourcePicture.any_instance.stub(:guest_role_check).and_return(true)\r
+ ResourcePicture.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)\r
+ r = @rp.visible?([@author])\r
+ end\r
+ it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do\r
+ ResourcePicture.any_instance.stub(:guest_role_check).and_return(false)\r
+ r = @rp.visible?([@author])\r
+ r.should be_false\r
end\r
end\r
- context '検査対象がそれ以外のとき' do\r
- it '不許可を返す。' do\r
- r = @rp.visible?(@admin)\r
+ context 'クローズドモードのとき' do\r
+ before do\r
+ MagicNumber['run_mode'] = 1\r
+ end\r
+ it '自身に素材読者用ロールチェックを問い合わせしている' do\r
+ ResourcePicture.any_instance.stub(:resource_reader_role_check).and_return(true)\r
+ ResourcePicture.any_instance.should_receive(:resource_reader_role_check).with(any_args).exactly(1)\r
+ r = @rp.visible?([@author])\r
+ end\r
+ it '素材読者用ロールチェックが失敗したとき、falseを返す' do\r
+ ResourcePicture.any_instance.stub(:resource_reader_role_check).and_return(false)\r
+ r = @rp.visible?([@author])\r
r.should be_false\r
end\r
end\r
+ context 'つつがなく終わるとき' do\r
+ before do\r
+ MagicNumber['run_mode'] = 1\r
+ ResourcePicture.any_instance.stub(:resource_reader_role_check).and_return(true)\r
+ end\r
+ it '許可する' do\r
+ r = @rp.visible?([@author])\r
+ r.should be_true\r
+ end\r
+ end\r
end\r
\r
describe 'ファイル名に於いて' do\r
before do\r
#すべての処理が正常パターンで通過すれば、一番深い分岐まで通る。\r
#それで外部のメソッド呼び出しだけに着目してテストする。\r
+ OriginalPicture.any_instance.stub(:save).and_return(true)\r
ResourcePicture.any_instance.stub(:new_picture).with(any_args).and_return(@p)\r
ResourcePicture.any_instance.stub(:store_picture_with_gif).with(any_args).and_return(true)\r
end\r
+ it '原画に保存を依頼している' do\r
+ OriginalPicture.any_instance.should_receive(:save).exactly(1)\r
+ r = @rp.store @imager\r
+ end\r
it '新規実素材の取得を依頼している' do\r
ResourcePicture.any_instance.should_receive(:new_picture).with(any_args).exactly(1)\r
r = @rp.store @imager\r
r = @rp.store @imager\r
r.should be_true\r
end\r
+ it '原画の停止日時をクリアする' do\r
+ r = @rp.store @imager\r
+ @rp.original_picture.stopped_at.should be_nil\r
+ end\r
+ it '原画の公開日時に現在時刻をセットする' do\r
+ lambda {\r
+ r = @rp.store @imager\r
+ }.should change(@rp.original_picture, :published_at)\r
+ end\r
it '実素材idから最新画像idを取得してセットしている' do\r
r = @rp.store @imager\r
@rp.picture_id.should eq @p.id\r
end\r
end\r
#以下から例外ケース。処理先頭から失敗させていく\r
+ context '原画の保存に失敗したとき' do\r
+ before do\r
+ OriginalPicture.any_instance.stub(:save).and_return(false)\r
+ end\r
+ it 'Falseを返す' do\r
+ r = @rp.unpublish\r
+ r.should be_false\r
+ end\r
+ it 'ロールバックしている' do\r
+ lambda {\r
+ r = @rp.unpublish\r
+ }.should_not change(ResourcePicture, :count)\r
+ end\r
+ end\r
context '画像オブジェクトの取得に失敗したとき' do\r
before do\r
@imager = false\r
@op = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
@p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
@rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id\r
+ PictureIO.resource_picture_io.stub(:exist?).with(@rp.filename).and_return(true)\r
+ PictureIO.resource_picture_io.stub(:exist?).with(@rp.filename, 'full').and_return(true)\r
end\r
context '事前チェックしておく' do\r
before do\r
+ OriginalPicture.any_instance.stub(:save).and_return(true)\r
ResourcePicture.any_instance.stub(:destroy).and_return(true)\r
PictureIO.resource_picture_io.stub(:delete).with(@rp.filename).and_return(true)\r
PictureIO.resource_picture_io.stub(:delete).with(@rp.filename, 'full').and_return(true)\r
end\r
+ it '原画に保存を依頼している' do\r
+ OriginalPicture.any_instance.should_receive(:save).exactly(1)\r
+ r = @rp.unpublish\r
+ end\r
it '素材モデルに削除を依頼している' do\r
ResourcePicture.any_instance.should_receive(:destroy).exactly(1)\r
r = @rp.unpublish\r
r = ResourcePicture.find @rp.id\r
}.should raise_error\r
end\r
+ it '原画の公開日時をクリアする' do\r
+ r = @rp.store @imager\r
+ @rp.original_picture.published_at.should be_nil\r
+ end\r
+ it '原画の停止日時に現在時刻をセットする' do\r
+ lambda {\r
+ r = @rp.unpublish\r
+ }.should change(@rp.original_picture, :stopped_at)\r
+ end\r
it 'Trueを返す' do\r
r = @rp.unpublish\r
r.should be_true\r
end\r
end\r
+ context '原画の保存に失敗したとき' do\r
+ before do\r
+ OriginalPicture.any_instance.stub(:save).and_return(false)\r
+ end\r
+ it 'Falseを返す' do\r
+ r = @rp.unpublish\r
+ r.should be_false\r
+ end\r
+ it 'ロールバックしている' do\r
+ lambda {\r
+ r = @rp.unpublish\r
+ }.should_not change(ResourcePicture, :count)\r
+ end\r
+ end\r
context '自身の削除に失敗したとき' do\r
before do\r
ResourcePicture.any_instance.stub(:destroy).with(any_args).and_return(false)\r