Ruby on rails 嵌套模型测试:找不到表'*';错误。
我试图针对一个Ruby on rails 嵌套模型测试:找不到表'*';错误。,ruby-on-rails,ruby,ruby-on-rails-3,rspec,factory-bot,Ruby On Rails,Ruby,Ruby On Rails 3,Rspec,Factory Bot,我试图针对一个工作的大型代码库运行RSpec(我对Rails比较陌生),但在这一点上失败了;我打赌这和FactoryGirl的定义有关 模型概述: 工厂女孩工厂: 规范: 错误: ActiveRecord::StatementInvalid: Could not find table 'friends' 非常欢迎任何反馈,谢谢。您可能需要运行rake db:migrate RAILS\u ENV=test 您可能需要运行rake db:migrate RAILS\u ENV=test 您是否运
工作的
大型代码库运行RSpec(我对Rails比较陌生),但在这一点上失败了;我打赌这和FactoryGirl的定义有关
模型概述:
工厂女孩工厂:
规范:
错误:
ActiveRecord::StatementInvalid: Could not find table 'friends'
非常欢迎任何反馈,谢谢。您可能需要运行
rake db:migrate RAILS\u ENV=test
您可能需要运行rake db:migrate RAILS\u ENV=test
您是否运行过rake db:migrate RAILS\u ENV=test?可能性有多大。。。现在一切都通过了(除了一次测试,但那很好)!我想我从很久以前就没有迁移测试数据库了:)(你能添加你的答案,这样我就可以把帖子标记为已解决了吗?)这总是一些小事,嗯?我刚刚添加了答案。:-)您是否运行过rake db:migrate RAILS\u ENV=test?可能性有多大。。。现在一切都通过了(除了一次测试,但那很好)!我想我从很久以前就没有迁移测试数据库了:)(你能添加你的答案,这样我就可以把帖子标记为已解决了吗?)这总是一些小事,嗯?我刚刚添加了答案。:-)
# models/user.rb
def add_friend(user_id, friend_id)
@friendship = self.friends.new({:user_id => user_id, :friend_id => friend_id})
return false unless @friendship.save
end
FactoryGirl.define do
factory :user, :class => User do |f|
# ...
end
factory :friend, :class => Friend do |f|
f.user_id { Faker::Base.regexify(/\d{1,3}/)}
f.friend_id { Faker::Base.regexify(/\d{1,3}/)}
# ...
end
end
# specs/models/user_spec.rb
it "Adds friends" do
@current_user.add_friend(@current_user.id, @friend_1.id).should be_valid
end
ActiveRecord::StatementInvalid: Could not find table 'friends'