I'm new to RSpec and I want to test if-else condition of a controller, I searched on the internet but the found results are not properly satisfying my search query.
Here is my rails controller:
class ScheduleTimeSlotsController < ApplicationController
def get_available_schedules
if params[:for_date].to_date==Date.today
available_schedules=ScheduleTimeSlot.where(:doctor_id => params[:dr_id],:date=>params[:for_date].to_date,:status=>"vacant",:archive=>false).where("start_time >=?",Time.now.seconds_since_midnight).reorder(:start_time)
else
available_schedules=ScheduleTimeSlot.where(:doctor_id => params[:dr_id],:date=>params[:for_date].to_date,:status=>"vacant",:archive=>false).reorder(:start_time)
end
render :json =>{:available_schedules=>available_schedules}
end
end
I'm using ruby version 2.2.4 and rails version is 4.2.0
Please guide me that how do I write RSpec for this condition, with the help of an example.
Thanks in advance.