Fixed DeleteEventSchedules issue

Issues with DeleteEventSchedules method in conference controller:
1.It deletes EventSchedules of all the conferences that are not in the
hours range. Instead it should delete EventSchedules of those events
only that belong to that particular conference only.
2.If we set invalid start or end hour attribute of a conference then
also EventSchedules gets deleted even though conference is not
successfully updated.
Fixed both the issues and added test for the same.
This commit is contained in:
Siddhant Bajaj 2017-03-06 21:45:48 +05:30
parent ec71b111fe
commit 7ce816e146
3 changed files with 34 additions and 10 deletions

View file

@ -1639,4 +1639,23 @@ describe Conference do
expect(free_ticket.price_cents).to eq(0)
end
end
describe 'after_update' do
let(:conference) { create(:conference) }
let(:scheduled_event_before_conference) { create(:event_scheduled, program: conference.program, hour: conference.start_date + conference.start_hour.hours) }
let(:scheduled_event_after_conference) { create(:event_scheduled, program: conference.program, hour: conference.start_date + conference.end_hour.hours - 1.hour) }
let!(:scheduled_event_during_conference) { create(:event_scheduled, program: conference.program, hour: conference.start_date + conference.start_hour.hours + 3.hours) }
it 'delete event schedules that are not in hour ranges, when conference start hour is updated' do
scheduled_event_before_conference
conference.start_hour = conference.start_hour + 1
expect{ conference.save }.to change{ EventSchedule.count }.from(2).to(1)
end
it 'delete event schedules that are not in hour ranges, when conference end hour is updated' do
scheduled_event_after_conference
conference.end_hour = conference.end_hour - 2
expect{ conference.save }.to change{ EventSchedule.count }.from(2).to(1)
end
end
end