describe 'DELETE #destroy' do
context 'owned object' do
subject { -> { delete kurasu_event_path(kurasu, object) } }
it_behaves_like :response_status_check, 302
it_behaves_like :decrement_object_by_destroy, Event
it_behaves_like :redirect_to
it_behaves_like :flash_notice_message, 'イベントを削除しました.'
end
context 'now owned object' do
subject { -> { delete kurasu_event_path(kurasu, not_mine), params: {event: @attrs} } }
it_behaves_like :response_status_check, 302
it_behaves_like :redirect_to
it_behaves_like :flash_alert_message, 'イベントを削除する権限がありません.'
end
context 'now owned kurasu' do
subject { -> { delete kurasu_event_path(not_mine.kurasu, not_mine), params: {event: @attrs} } }
let(:return_path) { kurasus_path }
it_behaves_like :response_status_check, 302
it_behaves_like :redirect_to
it_behaves_like :flash_alert_message, 'イベントを削除する権限がありません.'
end
end
describe 'GET #show' do
context 'owned object' do
subject { -> { get kurasu_event_path(kurasu, object) } }
it_behaves_like :response_status_check, 200
it_behaves_like :response_body_includes, %w[イベント表示: 始業]
end
context 'now owned object' do
subject { -> { get kurasu_event_path(kurasu, not_mine) } }
it_behaves_like :response_status_check, 302
it_behaves_like :redirect_to
it_behaves_like :flash_alert_message, 'イベントを表示する権限がありません.'
end
context 'now owned kurasu' do
subject { -> { get kurasu_event_path(not_mine.kurasu, not_mine) } }
let(:return_path) { kurasus_path }
it_behaves_like :response_status_check, 302
it_behaves_like :redirect_to
it_behaves_like :flash_alert_message, 'イベントを表示する権限がありません.'
end
end
def destroy
redirect_to(kurasus_path, alert: alert_message(Event)) and return if @kurasu.nil?
redirect_to(kurasu_events_path(@kurasu, edit_mode: true), alert: alert_message(Event)) and return if @event.nil?
@event.destroy
redirect_to kurasu_events_path(@kurasu, edit_mode: true), notice: notice_message(Event)
end
def show
redirect_to(kurasus_path, alert: alert_message(Event)) and return if @kurasu.nil?
redirect_to(kurasu_events_path(@kurasu, edit_mode: true), alert: alert_message(Event)) and return if @event.nil?
end
- content_for :title do
- @title = "#{t '.title'}: #{@event.name} (#{@kurasu.name})"
DELETE #destroy
owned object
behaves like response_status_check
response should be 302
behaves like decrement_object_by_destroy
should change `Event.count` by -1
behaves like redirect_to
should redirect to "/kurasus/2901/events?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/2905/events?edit_mode=true"
behaves like flash_alert_message
should eq "イベントを削除する権限がありません."
now owned kurasu
behaves like response_status_check
response should be 302
behaves like redirect_to
should redirect to "/kurasus"
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 ["イベント表示:", "始業"]
now owned object
behaves like response_status_check
response should be 302
behaves like redirect_to
should redirect to "/kurasus/2919/events?edit_mode=true"
behaves like flash_alert_message
should eq "イベントを表示する権限がありません."
now owned kurasu
behaves like response_status_check
response should be 302
behaves like redirect_to
should redirect to "/kurasus"
behaves like flash_alert_message
should eq "イベントを表示する権限がありません."
長くなったので今日はここまで