The test I’m writing is checking to see if I can delete an assignment or not. I thought I’d check for the presence of the link itself first:
describe "Deleting an assignment" do
before{ visit assignments_path }
it{ should have_selector('th', text: "Band Member") }
end
Now when I load the page itself it renders perfectly without any errors (haven’t tried pushing to Heroku yet), but the testing environment returns:
Failures:
1) Assignment pages Deleting an assignment
Failure/Error: before{ visit assignments_path }
ActionView::Template::Error:
undefined method `name' for nil:NilClass
the code that’s causing the error is in my assignment stub
<td><%= assignment.user.name + " " + assignment.user.surname%></td>
My assignments controller’s index action is simply:
def index
@assignments = Assignment.all
end
I can’t see anything obvious so any help would be appreciated. Thank you in advance!
It turns out that the first instance of a user created in the test environment was 31 not 1. This was because I was creating a set of 30 users in another test suite but deleting the users afterwards (hence why user 1 didn’t exist). I got around this by assigning the role using a call rather than hard coding what I thought was the ID.