end
it '@itemにリクエストしたスクロールを取得している' do
get :edit, id: @item_id
- @item = assigns(:item)
- expect(@item.is_a?(Scroll)).to be true
- expect(@item.new_record?).not_to be true
+ expect(assigns(:item).is_a?(Scroll)).to be true
+ expect(assigns(:item).new_record?).not_to be true
+ expect(assigns(:item)).to eq(@item)
end
it '@formに入力フォーム(Bucket)を取得している' do
get :edit, id: @item_id
it '@itemにリクエストしたアイテムを取得して, 更新している' do
allow_save Scroll
put_save @attr
- @item = assigns(:item)
- expect(@item.is_a?(Scroll)).to be true
- expect(@item.visible).to eq(0)
+ expect(assigns(:item).is_a?(Scroll)).to be true
+ expect(assigns(:item).visible).to eq(0)
+ expect(assigns(:item)).to eq(@item)
end
context 'html形式' do
it 'ステータスコード302 Foundを返して, 作成されたアイテムの表示ページへ遷移する' do
describe '削除に於いて' do
before do
- @scroll = FactoryGirl.create :scroll, :author => @author
- sign_in @user
+ @item = FactoryGirl.create :scroll_hello_with_scroll_panels, author: @author_yas
+ @item_id = @item.id
+ @attr = {:id => @item_id}
+ @attr_with_json = @attr.merge(:format => :json)
end
- context '事前チェックしておく' do
+ context '正常系の共通処理' do
before do
- Scroll.stub(:edit).with(any_args()).and_return @scroll
- Scroll.any_instance.stub(:destroy_with_scroll_panel).with(any_args()).and_return(true)
- end
- it 'スクロールモデルに編集取得を問い合わせている' do
- Scroll.should_receive(:edit).exactly(1)
- delete :destroy, :id => @scroll.id
+ sign_in @user_yas
end
- it 'モデルに削除を依頼する' do
- Scroll.any_instance.should_receive(:destroy_with_scroll_panel).exactly(1)
- delete :destroy, :id => @scroll.id
+ it 'コントローラのマニフェストからScrollモデルを@my_model_classに取得している' do
+ allow_destroy Scroll
+ destroy_save @attr
+ expect(assigns(:my_model_class)).to be Scroll
end
- it '@scrollにアレを取得している' do
- delete :destroy, :id => @scroll.id
- assigns(:scroll).id.should eq(@scroll.id)
+ it '@itemにリクエストしたアイテムを取得している' do
+ allow_destroy Scroll
+ destroy_save @attr
+ expect(assigns(:item).is_a?(Scroll)).to be true
+ expect(assigns(:item)).to eq(@item)
end
- end
- context '正常系の共通処理' do
- it '削除される' do
+ it '削除されている' do
lambda {
- delete :destroy, :id => @scroll.id
+ destroy_save @attr
}.should change Scroll, :count
end
+ it 'ぶら下がるリーフも削除されている' do
+ lambda {
+ destroy_save @attr
+ }.should change ScrollPanel, :count
+ end
context 'html形式' do
- before do
- Scroll.any_instance.stub(:destroy_with_scroll_panel).with(any_args()).and_return(true)
- end
- it 'ステータスコード302 Foundを返す' do
- delete :destroy, :id => @scroll.id
- response.status.should eq 302
- end
- it 'マイスクロールの一覧ページへ遷移する' do
- delete :destroy, :id => @scroll.id
- response.should redirect_to('/home/scrolls')
+ it 'ステータスコード302 Foundを返して, マイスクロールの一覧ページへ遷移する' do
+ destroy_save @attr
+ expect(response.status).to eq(302)
+ expect(response).to redirect_to '/home/scrolls'
end
end
context 'json形式' do
- before do
- Scroll.any_instance.stub(:destroy_with_scroll_panel).with(any_args()).and_return(true)
- end
- it 'ステータスコード200 OKを返す' do
- delete :destroy, :id => @scroll.id, :format => :json
- response.should be_success
- end
- it 'ページ本体は特に返さない' do
- delete :destroy, :id => @scroll.id, :format => :json
- response.body.should match /./
+ it 'ステータスコード200 OKを返して, ページ本体は特に返さない' do
+ destroy_save @attr_with_json
+ expect(response).to be_success
+ expect(response.message).to match /./
end
end
end
- context 'ユーザ権限がないとき' do
+ context '検証、保存に失敗したとき' do
before do
- sign_out @user
+ sign_in @user_yas
+ reject_destroy Scroll
end
context 'html形式' do
- it 'ステータスコード302 Foundを返す' do
- delete :destroy, :id => @scroll.id
- response.status.should eq 302
- end
- it 'サインインページへ遷移する' do
- delete :destroy, :id => @scroll.id
- response.body.should redirect_to '/users/sign_in'
+ it 'ステータスコード302 Foundを返して, そのスクロールの詳細ページへ遷移する' do
+ destroy_save @attr
+ expect(response.status).to eq(302)
+ expect(response).to redirect_to @item
end
end
context 'json形式' do
- it '応答メッセージにUnauthorizedを返す' do
- delete :destroy, :id => @scroll.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 => @scroll.id
- response.status.should eq 302
- end
- it 'サインインページへ遷移する' do
- delete :destroy, :id => @scroll.id
- response.body.should redirect_to '/users/sign_in'
+ it 'ステータスコード422 unprocessable_entityを返して, 応答メッセージUnprocessable Entityを返す' do
+ destroy_save @attr_with_json
+ expect(response.status).to eq(422)
+ expect(response.message).to match(/Unprocessable/)
end
end
end
- context 'ã\83¦ã\83¼ã\82¶ã\81 ã\81\8cä½\9c家ç\99»é\8c²ã\81\97ã\81¦ã\81\84ã\81ªã\81\84とき' do
+ context 'ã\82µã\82¤ã\83³ã\82¤ã\83³ã\81®ç\8a¶æ\85\8bã\81\8cä¾\8bå¤\96ç\9a\84ã\81ªとき' do
before do
- @author.destroy
+ allow_destroy Scroll
end
- context 'html形式' do
- it 'ステータスコード302 Foundを返す' do
- delete :destroy, :id => @scroll.id
- response.status.should eq 302
- end
- it '作家登録ページへ遷移する' do
- delete :destroy, :id => @scroll.id
- response.body.should redirect_to new_author_path
- end
- end
- end
- context '削除に失敗したとき' do
- before do
- Scroll.any_instance.stub(:destroy_with_scroll_panel).and_return(false)
+ it '創作活動してないROM専の読者には作家登録ページへ遷移する' do
+ sign_in @user_rom
+ destroy_save @attr
+ announce_regist_author_for_html
+ announce_regist_author_for_json :delete, @attr_with_json
end
- context 'html形式' do
- it 'ステータスコード302 Foundを返す' do
- delete :destroy, :id => @scroll.id
- response.status.should eq 302
- end
- it 'そのスクロールの詳細ページへ遷移する' do
- delete :destroy, :id => @scroll.id
- response.should redirect_to(scroll_path(@scroll))
- end
+ it 'ゲスト(サインインしていない)はサインインページに遷移する' do
+ destroy_save @attr
+ announce_sign_in_for_html
+ destroy_save @attr_with_json
+ announce_sign_in_for_json
end
- context 'json形式' do
- it 'ステータスコード422 unprocessable_entity を返す' do
- delete :destroy, :id => @scroll.id, :format => :json
- response.status.should eq 422
- end
- it '応答メッセージUnprocessable Entityを返す' do
- delete :destroy, :id => @scroll.id, :format => :json
- response.message.should match(/Unprocessable/)
- end
+ it 'ユーザではなく管理者でもサインインページに遷移する' do
+ sign_in @admin
+ destroy_save id: @item_id
+ announce_sign_in_for_html
+ destroy_save @attr_with_json
+ announce_sign_in_for_json
end
end
end