railstutorial.org - Hartl Rails Tutorial Chap.11.1.2 test issue -
having issue @ beginning of chap 11. after testing green @ end of chap 10, added listing 11.2 tests/models/micropost_test.rb
require 'test_helper'
class microposttest < activesupport::testcase
def setup @users = users(:michael) # code not idiomatically correct. @micropost = micropost.new(content: "lorem ipsum", user_id: @user.id) end test "should valid" assert @micropost.valid? end test "user id should present" @micropost.user_id = nil assert_not @micropost.valid? end
end
and predictably got red. added validations listing 11.4 app/model/s/micropost.rb `
class micropost < activerecord::base belongs_to :user validates :user_id, presence: true end
the problem continue following errors on test:
error["test_should_be_valid", microposttest, 0.255918787] test_should_be_valid#microposttest (0.26s) nomethoderror: nomethoderror: undefined method id' nil:nilclass test/models/micropost_test.rb:8:in
setup' test/models/micropost_test.rb:8:in `setup'
error["test_user_id_should_be_present", microposttest, 0.260151448] test_user_id_should_be_present#microposttest (0.26s) nomethoderror: nomethoderror: undefined method id' nil:nilclass test/models/micropost_test.rb:8:in
setup' test/models/micropost_test.rb:8:in `setup'
can steer me in right direction? thank you!
i think error in line :
@users = users(:michael)
it should @user without s
@user = users(:michael)
because using variable @user in line
@micropost = micropost.new(content: "lorem ipsum", user_id: @user.id)
Comments
Post a Comment