I'm having trouble testing this code in rspec - based on the error the test gives me, I know the test is written (more or less) correctly - as the data it's expecting is correct, it's just not getting it for some reason. I should also note that the code works in the browser.
edit: apologies if this was unclear. In this controller (evaluations_controller
), the user iterates through each student in a given group and evaluates their progress against a set of goals. In the new action, @student = groups.student.first
- when evaluation data for that student has been saved successfully in the create action, the student_id incremented by 1, and the new student_id is passed to the new action again (so the next student can be evaluated) - this loops until there are no more students.
What I'm trying to test is that the student_id is being successfully incremented after evaluation has been saved in the create action.
Code:
def create
...
if @evaluation.save
@id = params[:student_id]
@id = @id.to_i + 1
redirect_to evaluate_path({ student_group_id: @student_group, student_id: @id})
else
...
end
end
Rspec test:
it "should load the next student" do
#set @id to current student.id +1
@id = @student.id
@id = @id.to_i + 1
#post :create
post :create, {student_group_id: @student_group, student_id: @student, evaluation: @attr}
controller.params[:student_id].should eql @id
end
Error:
Failure/Error: controller.params[:student_id].should eql @id expected: 2 got: "1"