所以我想弄清楚如何測試has_many關係,但我遇到了一些困難。Rails Testing Table not found
這裏的錯誤
table tokens has no column named user_id
以下是我重新錯誤
$ rails new lab
$ cd lab
$ rails g model user name # has_many tokens
$ rails g model token code # belongs_to user
$ rake db:migrate
# tokens.yml
one:
code: 0A
user: user_one
two:
code: 0B
user: user_one
# users.yml
user_one:
name: John
# user_test.rb
require 'test_helper'
class UserTest < ActiveSupport::TestCase
test "has tokens" do
user = users(:user_one)
assert_not_equal [], user.tokens
end
end