Skip to content
This repository has been archived by the owner on Jul 13, 2022. It is now read-only.

Commit

Permalink
Raise 404 if no district for meeting
Browse files Browse the repository at this point in the history
  • Loading branch information
hartsick committed Jul 1, 2020
1 parent 0eab605 commit 5f73f28
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/controllers/admin/meetings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def destroy
attr_reader :district

def set_police_district
@district = PoliceDistrict.find_by_slug(params[:police_district_id])
@district = PoliceDistrict.find_by_slug!(params[:police_district_id])
end

def meeting_params
Expand Down
23 changes: 19 additions & 4 deletions spec/controllers/admin/meetings_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
RSpec.describe Admin::MeetingsController, type: :controller do
let(:user) { FactoryBot.create(:user) }
let!(:district) { FactoryBot.create(:police_district, slug: 'oakland', timezone: 'Pacific Time (US & Canada)') }
let!(:meeting) { FactoryBot.create(:meeting, police_district: district, event_datetime: DateTime.new(2025,1,20,11,0,0,0)) }

context 'when user is signed in' do
before do
Expand Down Expand Up @@ -63,6 +64,12 @@
}
end

it 'returns 404 if district not present' do
expect do
post :update, params: { police_district_id: 'asldkfjaslkfdj', id: meeting.id }
end.to raise_exception(ActiveRecord::RecordNotFound)
end

it 'converts datetime from district timezone to UTC before storing' do
travel_to Date.parse('2020-06-03') do
expect do
Expand All @@ -73,10 +80,14 @@
end

describe '#edit' do
let!(:meeting) { FactoryBot.create(:meeting, police_district: district, event_datetime: DateTime.new(2025,1,20,11,0,0,0)) }

render_views

it 'returns 404 if district not present' do
expect do
post :edit, params: { police_district_id: 'asldkfjaslkfdj', id: meeting.id }
end.to raise_exception(ActiveRecord::RecordNotFound)
end

it 'converts time to district timezone, but strips timezone' do
travel_to Date.parse('2020-06-03') do
get :edit, params: { id: meeting.id, police_district_id: district.slug }
Expand All @@ -87,9 +98,13 @@
end

describe '#destroy' do
let!(:meeting) { FactoryBot.create(:meeting, police_district: district) }

context 'js request' do
it 'returns 404 if district not present' do
expect do
post :update, format: :js, params: { police_district_id: 'asldkfjaslkfdj', id: meeting.id }
end.to raise_exception(ActiveRecord::RecordNotFound)
end

it 'deletes the meeting' do
expect do
delete :destroy, format: :js, params: { police_district_id: district.slug, id: meeting.id }
Expand Down

0 comments on commit 5f73f28

Please sign in to comment.