[英]Rails 4 undefined method `followed_users' - Michael Hartl's Tutorial
[英]Michael Hartl's Rails tutorial chapter 12 — undefined method `users'
我正在研究Michal Hartl的教程,第一次測試后出現錯誤。
E
Error:
RelationshipTest#test_should_be_valid:
NoMethodError: undefined method `users' for #<RelationshipTest:0x00007feb7da11100>
test/models/relationship_test.rb:6:in `setup'
bin/rails test test/models/relationship_test.rb:10
E
Error:
RelationshipTest#test_should_require_a_followed_id:
NoMethodError: undefined method `users' for #<RelationshipTest:0x00007feb7dadf2a8>
test/models/relationship_test.rb:6:in `setup'
bin/rails test test/models/relationship_test.rb:19
E
Error:
RelationshipTest#test_should_require_a_follower_id:
NoMethodError: undefined method `users' for #<RelationshipTest:0x00007feb7e8d04e8>
test/models/relationship_test.rb:6:in `setup'
bin/rails test test/models/relationship_test.rb:14
這是我的Relationship_test.rb:
require 'test_helper'
class RelationshipTest < ActiveSupport::TestCase
def setup
@relationship = Relationship.new(follower_id: users(:michael).id,
followed_id: users(:archer).id)
end
test "should be valid" do
assert @relationship.valid?
end
test "should require a follower_id" do
@relationship.follower_id = nil
assert_not @relationship.valid?
end
test "should require a followed_id" do
@relationship.followed_id = nil
assert_not @relationship.valid?
end
end
我真的被錯誤弄糊塗了,所以任何幫助將不勝感激。 我嘗試搜索其他答案,但找不到任何答案。
您需要創建一些燈具並將其放置在test/fixtures/users.yml
。
示例(您可能需要使其適應自己的數據庫設計):
michael:
email: "user_1@example.com"
uid: "user_1@example.com"
encrypted_password: <%= Devise::Encryptor.digest(User, 'password') %>
現在,您可以以users(:michael)
身份users(:michael)
此固定裝置。 查看Rails文檔以獲取更多信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.