RailsApp Rails RSpec 2018年 11月 29日
describe 'DELETE #destroy' do
context 'owned object' do
subject { -> { delete kurasu_path(object), params: {kurasu: @attrs} } }
it_behaves_like :response_status_check, 302
it_behaves_like :decrement_object_by_destroy, Kurasu
it_behaves_like :redirect_to
it_behaves_like :flash_notice_message, 'クラスを削除しました.'
end
context 'now owned object' do
subject { -> { delete kurasu_path(not_mine), params: {kurasu: @attrs} } }
it_behaves_like :redirect_to
it_behaves_like :flash_alert_message, 'クラスを削除する権限がありません.'
end
end
def destroy
redirect_to(kurasus_path, alert: alert_message(Kurasu)) and return if @kurasu.nil?
@kurasu.destroy
redirect_to kurasus_path, notice: notice_message(Kurasu)
end
describe 'GET #show' do
context 'owned object' do
subject { -> { get kurasu_path(object) } }
it_behaves_like :response_status_check, 200
it_behaves_like :response_body_includes, %w[クラス表示: 2300 (小林弘幸)]
end
context 'now owned object' do
subject { -> { get kurasu_path(not_mine) } }
it_behaves_like :response_status_check, 302
it_behaves_like :redirect_to
it_behaves_like :flash_alert_message, 'クラスを表示する権限がありません.'
end
end
def show
redirect_to(kurasus_path(edit_mode: true), alert: alert_message(Kurasu)) and return if @kurasu.nil?
end
DELETE #destroy
owned object
behaves like response_status_check
response should be 302
behaves like decrement_object_by_destroy
should change `Kurasu.count` by -1
behaves like redirect_to
should redirect to "/kurasus?edit_mode=true"
behaves like flash_notice_message
should eq "クラスを削除しました."
now owned object
behaves like response_status_check
response should be 302
behaves like redirect_to
should redirect to "/kurasus?edit_mode=true"
behaves like flash_alert_message
should eq "クラスを削除する権限がありません."
GET #show
owned object
behaves like response_status_check
response should be 200
behaves like response_body_includes
response body includes ["クラス表示:", "2300", "(小林弘幸)"]
now owned object
behaves like response_status_check
response should be 302
behaves like redirect_to
should redirect to "/kurasus?edit_mode=true"
behaves like flash_alert_message
should eq "クラスを表示する権限がありません."
長くなったので今日はここまで