X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=spec%2Fcontrollers%2Fresource_pictures_controller_spec.rb;h=d9b7e70d76d679f2b7f8beee6033eb24afd0172e;hb=0bdfae60dc58932c99849c31d36ee5d7715db782;hp=0854814d7a9377e9d7a5cff2b905976c5e3005a6;hpb=2bd8e046bbbdd6d620af0637c3291cc7d787b0c5;p=pettanr%2Fpettanr.git diff --git a/spec/controllers/resource_pictures_controller_spec.rb b/spec/controllers/resource_pictures_controller_spec.rb index 0854814d..d9b7e70d 100644 --- a/spec/controllers/resource_pictures_controller_spec.rb +++ b/spec/controllers/resource_pictures_controller_spec.rb @@ -5,6 +5,7 @@ require 'spec_helper' describe ResourcePicturesController do before do @admin = FactoryGirl.create :admin + @demand_user = FactoryGirl.create :demand_user @sp = FactoryGirl.create :system_picture @lg = FactoryGirl.create :license_group @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id @@ -14,6 +15,7 @@ describe ResourcePicturesController do @op = FactoryGirl.create :original_picture, :artist_id => @artist.id end +if MagicNumber['run_mode'] == 1 describe '一覧表示に於いて' do before do @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id @@ -57,6 +59,10 @@ describe ResourcePicturesController do assigns(:resource_pictures).should have_at_least(3).items end context 'html形式' do + it '@paginateにページ制御を取得している' do + get :index + assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true + end it 'ステータスコード200 OKを返す' do get :index response.should be_success @@ -93,7 +99,7 @@ describe ResourcePicturesController do end end end - context '作家権限がないとき' do + context 'ユーザ権限がないとき' do before do sign_out @user end @@ -118,6 +124,35 @@ describe ResourcePicturesController do end end end + context 'ユーザ権限はないが管理者権限があるとき' do + before do + sign_out @user + sign_in @admin + end + it 'ステータスコード200 OKを返す' do + get :index + response.should be_success + end + end + context 'ユーザ権限はないが借手権限があるとき' do + before do + sign_out @user + sign_in @demand_user + end + it 'ステータスコード200 OKを返す' do + get :index + response.should be_success + end + end + context 'ユーザだが作家登録していないとき' do + before do + @author.destroy + end + it 'ステータスコード200 OKを返す' do + get :index + response.should be_success + end + end end describe '単体表示に於いて' do @@ -125,7 +160,9 @@ describe ResourcePicturesController 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 - ResourcePicture.stub(:show).with(@rp.id.to_s, @author).and_return(@rp) + ResourcePicture.stub(:show).with(@rp.id.to_s, [@user, nil, nil]).and_return(@rp) + ResourcePicture.stub(:show).with(@rp.id.to_s, [nil, @admin, nil]).and_return(@rp) + ResourcePicture.stub(:show).with(@rp.id.to_s, [nil, nil, @demand_user]).and_return(@rp) end context 'つつがなく終わるとき' do it '素材モデルに単体取得を問い合わせている' do @@ -225,7 +262,7 @@ describe ResourcePicturesController do end end end - context '作家権限がないとき' do + context 'ユーザ権限がないとき' do before do sign_out @user end @@ -250,6 +287,35 @@ describe ResourcePicturesController do end end end + context 'ユーザ権限はないが管理者権限があるとき' do + before do + sign_out @user + sign_in @admin + end + it 'ステータスコード200 OKを返す' do + get :show, :id => @rp.id + response.should be_success + end + end + context 'ユーザ権限はないが借手権限があるとき' do + before do + sign_out @user + sign_in @demand_user + end + it 'ステータスコード200 OKを返す' do + get :show, :id => @rp.id + response.should be_success + end + end + context 'ユーザだが作家登録していないとき' do + before do + @author.destroy + end + it 'ステータスコード200 OKを返す' do + get :show, :id => @rp.id + response.should be_success + end + end =begin context '対象素材がないとき' do before do @@ -322,7 +388,9 @@ describe ResourcePicturesController 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 - ResourcePicture.stub(:show).with(@rp.id.to_s, @author).and_return(@rp) + ResourcePicture.stub(:show).with(@rp.id.to_s, [@user, nil, nil]).and_return(@rp) + ResourcePicture.stub(:show).with(@rp.id.to_s, [nil, @admin, nil]).and_return(@rp) + ResourcePicture.stub(:show).with(@rp.id.to_s, [nil, nil, @demand_user]).and_return(@rp) end context 'つつがなく終わるとき' do it '素材モデルに単体取得を問い合わせている' do @@ -365,7 +433,7 @@ describe ResourcePicturesController do end end end - context '作家権限がないとき' do + context 'ユーザ権限がないとき' do before do sign_out @user end @@ -390,6 +458,35 @@ describe ResourcePicturesController do end end end + context 'ユーザ権限はないが管理者権限があるとき' do + before do + sign_out @user + sign_in @admin + end + it 'ステータスコード200 OKを返す' do + get :credit, :id => @rp.id + response.should be_success + end + end + context 'ユーザ権限はないが借手権限があるとき' do + before do + sign_out @user + sign_in @demand_user + end + it 'ステータスコード200 OKを返す' do + get :credit, :id => @rp.id + response.should be_success + end + end + context 'ユーザだが作家登録していないとき' do + before do + @author.destroy + end + it 'ステータスコード200 OKを返す' do + get :credit, :id => @rp.id + response.should be_success + end + end =begin context '対象素材がないとき' do before do @@ -532,7 +629,7 @@ describe ResourcePicturesController do end end end - context '作家権限がないとき' do + context 'ユーザ権限がないとき' do before do sign_out @user end @@ -560,9 +657,41 @@ describe ResourcePicturesController do end end end - context '作家が絵師でないとき' do + context 'ユーザ権限はないが管理者権限があるとき' do + before do + sign_out @user + sign_in @admin + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + get :new, @attr + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + get :new, @attr + response.body.should redirect_to '/users/sign_in' + end + end + end + context 'ユーザ権限はないが借手権限があるとき' do + before do + sign_out @user + sign_in @demand_user + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + get :new, @attr + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + get :new, @attr + response.body.should redirect_to '/users/sign_in' + end + end + end + context 'ユーザが絵師でないとき' do before do - Author.any_instance.stub(:artist?).and_return(false) + @artist.destroy end context 'html形式' do it 'ステータスコード302 Foundを返す' do @@ -592,6 +721,9 @@ describe ResourcePicturesController do before do @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @op.id, :license_group_id => 0}, :resource_picture => {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => @artist.name, :credit => '{}', :settings => '{}' }} + OriginalPicture.stub(:edit).with(@op.id.to_s, @artist).and_return(@op) + OriginalPicture.stub(:edit).with(@newop.id.to_s, @artist).and_return(@newop) + OriginalPicture.any_instance.stub(:restore).with(any_args()).and_return(@imager.binary) end context 'html形式' do it '例外404 not_foundを返す' do @@ -785,7 +917,7 @@ describe ResourcePicturesController do }.should_not change(ResourcePicture, :count) end end - context '作家権限がないとき' do + context 'ユーザ権限がないとき' do before do sign_out @user end @@ -813,9 +945,41 @@ describe ResourcePicturesController do end end end - context '作家が絵師でないとき' do + context 'ユーザ権限はないが管理者権限があるとき' do + before do + sign_out @user + sign_in @admin + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + post :create, @attr + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + post :create, @attr + response.body.should redirect_to '/users/sign_in' + end + end + end + context 'ユーザ権限はないが借手権限があるとき' do + before do + sign_out @user + sign_in @demand_user + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + post :create, @attr + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + post :create, @attr + response.body.should redirect_to '/users/sign_in' + end + end + end + context 'ユーザが絵師でないとき' do before do - Author.any_instance.stub(:artist?).and_return(false) + @artist.destroy end context 'html形式' do it 'ステータスコード302 Foundを返す' do @@ -828,10 +992,8 @@ describe ResourcePicturesController do end end context 'json形式' do - before do - @attr.merge!({:format => :json}) - end it '例外403 forbiddenを返す' do + @attr.merge!({:format => :json}) lambda{ post :create, @attr }.should raise_error(ActiveRecord::Forbidden) @@ -840,6 +1002,8 @@ describe ResourcePicturesController do 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 @@ -872,4 +1036,548 @@ describe ResourcePicturesController do 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 + before do + ResourcePicture.any_instance.stub(:unpublish).with(any_args()).and_return(true) + 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('/home/resource_picture') + end + end + context 'json形式' do + 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 + 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.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 + sign_out @user + sign_in @admin + 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.body.should redirect_to '/users/sign_in' + end + end + end + context 'ユーザ権限はないが借手権限があるとき' do + before do + sign_out @user + sign_in @demand_user + 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.body.should redirect_to '/users/sign_in' + end + end + end + context 'ユーザが絵師でないとき' do + before do + @artist.destroy + 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 new_artist_path + end + end + context 'json形式' do + it '例外403 forbiddenを返す' do + lambda{ + delete :destroy, :id => @rp.id, :format => :json + }.should raise_error(ActiveRecord::Forbidden) + 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 + +else + 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 + ResourcePicture.stub(:list).and_return([@rp, @rp, @rp]) + end + context 'つつがなく終わるとき' do + context 'html形式' do + it 'ステータスコード200 OKを返す' do + get :index + response.should be_success + end + it 'indexテンプレートを描画する' do + get :index + response.should render_template("index") + end + end + context 'json形式' do + it 'ステータスコード200 OKを返す' do + get :index, :format => :json + response.should be_success + end + it 'jsonデータを返す' do + get :index, :format => :json + lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) + end + end + end + context 'ユーザ権限がないとき' do + before do + sign_out @user + end + context 'html形式' do + it 'ステータスコード200 OKを返す' do + get :index + response.should be_success + end + it 'indexテンプレートを描画する' do + get :index + response.should render_template("index") + end + end + context 'json形式' do + it 'ステータスコード200 OKを返す' do + get :index, :format => :json + response.should be_success + end + it 'jsonデータを返す' do + get :index, :format => :json + lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) + end + end + 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 + ResourcePicture.stub(:show).with(@rp.id.to_s, [nil, nil, nil]).and_return(@rp) + ResourcePicture.stub(:show).with(@rp.id.to_s, [@user, nil, nil]).and_return(@rp) + ResourcePicture.stub(:show).with(@rp.id.to_s, [nil, @admin, nil]).and_return(@rp) + ResourcePicture.stub(:show).with(@rp.id.to_s, [nil, nil, @demand_user]).and_return(@rp) + end + context 'つつがなく終わるとき' do + context 'html形式' do + it 'ステータスコード200 OKを返す' do + get :show, :id => @rp.id + response.should be_success + end + it 'showテンプレートを描画する' do + get :show, :id => @rp.id + response.should render_template("show") + end + end + context 'json形式' do + it 'ステータスコード200 OKを返す' do + get :show, :id => @rp.id, :format => :json + response.should be_success + end + it 'jsonデータを返す' do + get :show, :id => @rp.id, :format => :json + lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) + end + end + end + context 'ユーザ権限がないとき' do + before do + sign_out @user + end + context 'html形式' do + it 'ステータスコード200 OKを返す' do + get :show, :id => @rp.id + response.should be_success + end + it 'showテンプレートを描画する' do + get :show, :id => @rp.id + response.should render_template("show") + end + end + context 'json形式' do + it 'ステータスコード200 OKを返す' do + get :show, :id => @rp.id, :format => :json + response.should be_success + end + it 'jsonデータを返す' do + get :show, :id => @rp.id, :format => :json + lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) + end + end + end + end + + describe '素材数取得に於いて' do + before do + ResourcePicture.should_receive(:visible_count).and_return(3) +# sign_in @user + end + context 'つつがなく終わるとき' do + it 'ステータスコード200 OKを返す' do + get :count, :format => :json + response.should be_success + end + context 'json形式' do + it 'jsonデータを返す' do + get :count, :format => :json + lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) + end + end + 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 + ResourcePicture.stub(:show).with(@rp.id.to_s, [nil, nil, nil]).and_return(@rp) + ResourcePicture.stub(:show).with(@rp.id.to_s, [@user, nil, nil]).and_return(@rp) + ResourcePicture.stub(:show).with(@rp.id.to_s, [nil, @admin, nil]).and_return(@rp) + ResourcePicture.stub(:show).with(@rp.id.to_s, [nil, nil, @demand_user]).and_return(@rp) + end + context 'つつがなく終わるとき' do + context 'html形式' do + it 'ステータスコード200 OKを返す' do + get :credit, :id => @rp.id + response.should be_success + end + it 'creditテンプレートを描画する' do + get :credit, :id => @rp.id + response.should render_template("credit") + end + end + context 'json形式' do + it 'ステータスコード200 OKを返す' do + get :credit, :id => @rp.id, :format => :json + response.should be_success + end + it 'jsonデータを返す' do + get :credit, :id => @rp.id, :format => :json + lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) + end + end + end + context 'ユーザ権限がないとき' do + before do + sign_out @user + end + context 'html形式' do + it 'ステータスコード200 OKを返す' do + get :credit, :id => @rp.id + response.should be_success + end + it 'creditテンプレートを描画する' do + get :credit, :id => @rp.id + response.should render_template("credit") + end + end + context 'json形式' do + it 'ステータスコード200 OKを返す' do + get :credit, :id => @rp.id, :format => :json + response.should be_success + end + it 'jsonデータを返す' do + get :credit, :id => @rp.id, :format => :json + lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) + end + end + end + end + + #原画にライセンスを与えるため際の確認フォーム + describe '新規作成フォーム表示に於いて' do + before do + sign_in @user + @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 + @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @op.id, :license_group_id => @lg.id}, + :resource_picture => {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => @artist.name, :credit => '{}', :settings => '{}' }} + @newop = FactoryGirl.create :original_picture, :artist_id => @artist.id + @newattr = {:original_picture_id => @newop.id, :original_picture_license_group => {:original_picture_id => @newop.id, :license_group_id => @lg.id}, + :resource_picture => {:original_picture_id => @newop.id, :license_id => @license.id, :artist_name => @artist.name, :credit => '{}', :settings => '{}' }} + @imager = ImagerTest.load("abc\ndef\nghi") + end + context 'つつがなく終わるとき' do + before do + OriginalPicture.stub(:edit).with(@op.id.to_s, @artist).and_return(@op) + OriginalPicture.stub(:edit).with(@newop.id.to_s, @artist).and_return(@newop) + OriginalPicture.any_instance.stub(:restore).with(any_args()).and_return(@imager.binary) + PettanImager.stub(:load).with(@imager.binary).and_return(@imager) + LicenseGroup.stub(:show).with(@lg.id).and_return(@lg) + ResourcePicture.any_instance.stub(:overwrite).with(@op).and_return(true) + ResourcePicture.any_instance.stub(:overwrite).with(@newop).and_return(true) + end + context 'html形式' do + it 'ステータスコード200 OKを返す' do + get :new, @attr + response.should be_success + end + it 'ページテンプレートnewを描画する' do + get :new, @attr + response.should render_template("new") + end + end + context 'js形式' do + before do + @attr.merge!({:format => :js}) + end + it 'ステータスコード200 OKを返す' do + get :new, @attr + response.should be_success + end + it '部分テンプレートnew.jsを描画する' do + get :new, @attr + response.should render_template("new") + end + end + end + context 'ユーザ権限がないとき' do + before do + sign_out @user + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + get :new, @attr + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + get :new, @attr + response.body.should redirect_to '/users/sign_in' + end + end + context 'js形式' do + before do + @attr.merge!({:format => :js}) + end + it 'ステータスコード401 Unauthorizedを返す' do + get :new, @attr + response.status.should eq 401 + end + it '応答メッセージにUnauthorizedを返す' do + get :new, @attr + response.message.should match(/Unauthorized/) + end + end + end + end + + describe '新規作成に於いて' do + before do + sign_in @user + @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 + @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @op.id, :license_group_id => @lg.id}, + :resource_picture => {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => @artist.name, :credit => '{}', :settings => '{"new":0}' }} + @newop = FactoryGirl.create :original_picture, :artist_id => @artist.id + @newattr = {:original_picture_id => @newop.id, :original_picture_license_group => {:original_picture_id => @newop.id, :license_group_id => @lg.id}, + :resource_picture => {:original_picture_id => @newop.id, :license_id => @license.id, :artist_name => @artist.name, :credit => '{}', :settings => '{"new":1}' }} + @imager = ImagerTest.load("abc\ndef\nghi") + end + context 'つつがなく終わるとき[ライセンスを与えようとしている原画が素材を作成してない]' do + before do + OriginalPicture.stub(:edit).with(@newop.id.to_s, @artist).and_return(@newop) + OriginalPicture.any_instance.stub(:restore).with(any_args()).and_return(@imager.binary) + PettanImager.stub(:load).with(@imager.binary).and_return(@imager) + LicenseGroup.stub(:show).with(@lg.id).and_return(@lg) + ResourcePicture.any_instance.stub(:store).with(@imager).and_return { + assigns(:resource_picture).attributes = @newattr[:resource_picture] + assigns(:resource_picture).overwrite @newop + assigns(:resource_picture).picture_id = @p.id + assigns(:resource_picture).save! + true + } + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + post :create, @newattr + response.status.should eq 302 + end + it '作成された素材の表示ページへ遷移する' do + post :create, @newattr + response.should redirect_to(ResourcePicture.last) + end + end + context 'json形式' do + before do + @newattr.merge!({:format => :json}) + end + it 'ステータスコード200 OKを返す' do + post :create, @newattr + response.should be_success + end + it '作成された素材をjsonデータで返す' do + post :create, @newattr + lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) + end + end + end + context 'ユーザ権限がないとき' do + before do + sign_out @user + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + post :create, @newattr + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + post :create, @newattr + response.body.should redirect_to '/users/sign_in' + end + end + 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.any_instance.stub(:unpublish).with(any_args()).and_return(true) + 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('/home/resource_picture') + end + end + context 'json形式' do + 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 + end + +end end