I'm ROR newbie, I followed ch12, this is my user_test.rb
test "should follow and unfollow a user" do
user_test = users(:test)
ancher = users(:ancher)
assert_not user_test.following?(ancher)
user_test.follow(ancher)
assert user_test.following?(ancher) ------> error line 82
user_test.unfollow(ancher)
assert_not user_test.following?(ancher)
end
This is my user.rb
class User < ActiveRecord::Base
has_many :microposts, dependent: :destroy
has_many :active_relationships, class_name: "Relationship",
foreign_key: "followed_id",
dependent: :destroy
has_many :following, through: :active_relationships, source: :followed
...
def follow(other_user)
active_relationships.create(followed_id: other_user.id)
end
def unfollow(other_user)
active_relationships.find_by(followed_id: other_user.id).destroy
end
def following?(other_user)
following.include?(other_user)
end
...
This is my relationship.rb
class Relationship < ActiveRecord::Base
belongs_to :follower, class_name: "User"
belongs_to :followed, class_name: "User"
validates :follower_id, presence: true
validates :followed_id, presence: true
end
When I run bundle exec rake test
. I always get
FAIL["test_should_follow_and_unfollow_a_user", UserTest, 2015-12-09 17:32:33 +0000]
test_should_follow_and_unfollow_a_user#UserTest (1449682353.62s)
Failed assertion, no message given.
test/models/user_test.rb:82:in `block in <class:UserTest>'
I have no idea, thanks your help.
Aucun commentaire:
Enregistrer un commentaire