这是我得到的错误。
UserFriendshipTest#test_that_creating_a_friendship_works_without_raising_an_exception:
NoMethodError: undefined method `friend' for #<UserFriendshipTest:0x2947dd0>
test/models/user_friendship_test.rb:9:in `block (2 levels) in <class:UserFriendshipTest>'
test/models/user_friendship_test.rb:8:in `block in <class:UserFriendshipTest>'
这是我的 user_friendship_test.rb 代码。
require 'test_helper'
class UserFriendshipTest < ActiveSupport::TestCase
should belong_to(:user)
should belong_to(:friend)
test "that creating a friendship works without raising an exception" do
assert_nothing_raised do
UserFriendship.create user: users(:brijesh), friend: friend(:neha)
end
end
end
这是我的 user_friendship.rb
class UserFriendship < ActiveRecord::Base
belongs_to :user
belongs_to :friend, class_name: "User", foreign_key: "friend_id"
end