I was seeing some weird issues with my tests so I wrote a quick debug test to check some results.
I have teachers
, students
and school_classes
.
debug_spec.rb
:
feature 'Debug school classes' do
before(:each) do
@teacher = create(:teacher)
@student = create(:student)
@teacher.school_classes << @student.private_class
@admin = create(:admin)
# visit sign_in_path
# fill_in 'Email', with: @admin.email
# click_button 'Sign in'
end
scenario 'DEBUG' do
puts 'S length: ' + @student.school_classes.length.to_s
puts 'T length: ' + @teacher.school_classes.length.to_s
puts 'S size: ' + @student.school_classes.size.to_s
puts 'T size: ' + @teacher.school_classes.size.to_s
puts 'S count: ' + @student.school_classes.count.to_s
puts 'T count: ' + @teacher.school_classes.count.to_s
puts 'S first.name: ' + @student.school_classes.first.name.to_s
puts 'T first.name: ' + @teacher.school_classes.first.name.to_s
puts 'T students: ' + @teacher.students.to_s
end
end
In the before
block Iām creating a teacher and a student from factories and assigning the student to the teacher. I get the following output:
Debug school classes
S length: 1
T length: 1
S size: 1
T size: 1
S count: 1
T count: 1
S first.name: Rocio Fisher
T first.name: Rocio Fisher
T students: [#<Student id: 1, first_name: "Rocio", last_name: "Fisher", family_id: 2, school_id: 1>]
This is exactly what I expect to see based on the associations and factories.
However when I uncomment the visit sign_in_path
line I see different results:
Debug school classes
S length: 1
T length: 1
S size: 1
T size: 1
S count: 0
T count: 0
S first.name: Jerad Gerhold
T first.name: Jerad Gerhold
T students: []
Note that Iām only including the visit
line, Iām not even signing the admin in yet.
What happened to .count
and why is my .students
relation empty?