sign_in @user
Story.stub(:edit).and_return(@story)
end
- context 'つつがなく終わるとき' do
+ context '事前チェックしておく' do
+ before do
+ Story.stub(:edit).with(any_args()).and_return @story
+ Story.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(true)
+ end
it 'ストーリーモデルに編集取得を問い合わせている' do
Story.should_receive(:edit).exactly(1)
delete :destroy, :id => @story.id
end
+ it 'モデルに削除を依頼する' do
+ Story.any_instance.should_receive(:destroy_and_shorten).exactly(1)
+ delete :destroy, :id => @story.id
+ end
it '@storyにアレを取得している' do
delete :destroy, :id => @story.id
assigns(:story).id.should eq(@story.id)
end
- it 'そのストーリーを一つのトランザクションで削除する' do
- lambda {
- delete :destroy, :id => @story.id
- }.should change(Story, :count)
+ end
+ context 'つつがなく終わるとき' do
+ before do
+ Story.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(true)
end
context 'html形式' do
it 'ステータスコード302 Foundを返す' do
delete :destroy, :id => @story.id
response.status.should eq 302
end
- it 'ストーリー一覧ページへ遷移する' do
+ it '閲覧ページへ遷移する' do
delete :destroy, :id => @story.id
- response.should redirect_to(story_path(@story.comic_id))
+ response.should redirect_to(:controller => 'stories', :action => :comic, :id => @story.comic_id)
end
end
context 'json形式' do
end
end
end
+ context '削除に失敗したとき' do
+ before do
+ Story.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(false)
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ delete :destroy, :id => @story.id
+ response.status.should eq 302
+ end
+ it 'そのコミックの詳細ページへ遷移する' do
+ delete :destroy, :id => @story.id
+ response.should redirect_to(story_path(@story))
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード422 unprocessable_entity を返す' do
+ delete :destroy, :id => @story.id, :format => :json
+ response.status.should eq 422
+ end
+ it '応答メッセージUnprocessable Entityを返す' do
+ delete :destroy, :id => @story.id, :format => :json
+ response.message.should match(/Unprocessable/)
+ end
+ end
+ end
=begin
context '対象ストーリーがないとき' do
end