end
end
+ describe '削除に於いて' do
+ before do
+ @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+ @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
+ sign_in @user
+ end
+ context '事前チェックしておく' do
+ before do
+ ResourcePicture.stub(:edit).with(any_args()).and_return @rp
+ ResourcePicture.any_instance.stub(:unpublish).with(any_args()).and_return(true)
+ end
+ it '素材モデルに編集取得を問い合わせている' do
+ ResourcePicture.should_receive(:edit).exactly(1)
+ delete :destroy, :id => @rp.id
+ end
+ it 'モデルに削除を依頼する' do
+ ResourcePicture.any_instance.should_receive(:unpublish).exactly(1)
+ delete :destroy, :id => @rp.id
+ end
+ it '@resource_pictureにアレを取得している' do
+ delete :destroy, :id => @rp.id
+ assigns(:resource_picture).id.should eq(@rp.id)
+ end
+ end
+ context 'つつがなく終わるとき' do
+ it '削除される' do
+ lambda {
+ delete :destroy, :id => @rp.id
+ }.should change ResourcePicture, :count
+ end
+ context 'html形式' do
+ before do
+ ResourcePicture.any_instance.stub(:unpublish).with(any_args()).and_return(true)
+ end
+ it 'ステータスコード302 Foundを返す' do
+ delete :destroy, :id => @rp.id
+ response.status.should eq 302
+ end
+ it 'マイ素材の一覧ページへ遷移する' do
+ delete :destroy, :id => @rp.id
+ response.should redirect_to('/home/resource_picture')
+ end
+ end
+ context 'json形式' do
+ before do
+ ResourcePicture.any_instance.stub(:unpublish).with(any_args()).and_return(true)
+ end
+ it 'ステータスコード200 OKを返す' do
+ delete :destroy, :id => @rp.id, :format => :json
+ response.should be_success
+ end
+ it 'ページ本体は特に返さない' do
+ delete :destroy, :id => @rp.id, :format => :json
+ response.body.should match /./
+ end
+ end
+ end
+ context '作家権限がないとき' do
+ before do
+ sign_out @user
+ end
+ it 'ステータスコード302 Foundを返す' do
+ delete :destroy, :id => @rp.id
+ response.status.should eq 302
+ end
+ context 'html形式' do
+ it 'サインインページへ遷移する' do
+ delete :destroy, :id => @rp.id
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it '応答メッセージにUnauthorizedを返す' do
+ delete :destroy, :id => @rp.id, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ context '削除に失敗したとき' do
+ before do
+ ResourcePicture.any_instance.stub(:unpublish).and_return(false)
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ delete :destroy, :id => @rp.id
+ response.status.should eq 302
+ end
+ it 'その素材の詳細ページへ遷移する' do
+ delete :destroy, :id => @rp.id
+ response.should redirect_to(resource_picture_path(@rp))
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード422 unprocessable_entity を返す' do
+ delete :destroy, :id => @rp.id, :format => :json
+ response.status.should eq 422
+ end
+ it '応答メッセージUnprocessable Entityを返す' do
+ delete :destroy, :id => @rp.id, :format => :json
+ response.message.should match(/Unprocessable/)
+ end
+ end
+ end
+ end
+
end