let(:valid_attributes) {
{
"first_name" => "MyString",
"last_name" => "LastName",
"email" => "[email protected]",
"password" => "password12345",
"password_confirmation" => "password12345"
}
}
it "sets session when" do
post :create, {:user => valid_attributes}, valid_session
expect(session[:user_id]).to eq(valid_attributes.id)
end
when i run above test , it fails Failure/Error: expect(session[:user_id]).to eq(valid_attributes["id"])
expected: nil
got: 1
But when i change it to below code , it passes the test. But what is the difference between these two. Why first one is failing.
it "sets session when" do
post :create, {:user => valid_attributes}, valid_session
expect(session[:user_id]).to eq(User.find_by(email: valid_attributes["email"]).id)
end