更新4
见下面的解决方案
**更新3**
如果有人真的还在读这个(我很感激!)我今天一直在努力解决我的代码(是的仍然是一个菜鸟和ruby on rails教程的第11章).
我应该重置回上次提交:
$ cd rails_screencast/sample_app/
$ git reset --hard 2396c0d288d132ffc43c82d5cbbc736a5258eed2
HEAD is now at 2396c0d Micropost Validations
Run Code Online (Sandbox Code Playgroud)
当我检查本地主机上的网站,它实际上显示的用户的列表,而不是一个错误页面,但是当我运行测试套件(自动测试与叉勺 - 我重置这些几次也可以肯定的)我仍然得到所有错误如下所示.我非常好奇"无法找到表'用户'"因为它出现在每个错误中#
108) Users signin success should sign a user in and out
Failure/Error: user = Factory(:user)
ActiveRecord::StatementInvalid:
Could not find table 'users'
# ./spec/requests/users_spec.rb:56:in `block (4 levels) in <top (required)>'
Finished in 0.9872 seconds
108 examples, 108 failures
Run Code Online (Sandbox Code Playgroud)
是时候继续堵塞并查看所有这些错误,如果有人可以提供任何见解或提示或想法,我会很感激!或者,如果您需要其他信息,我也可以发布(只是非常具体到哪些文件可以查看,因为我已经没有完全流利的语言,因为许多已经存在)
更新2:
看来,我的复位弄乱的东西了出厂设置为全部,有时我的错误都指向行我micropost_spec.rb文件的5专门@了@user =厂(:用户)线......几乎像我的工厂文件ISN"与任何事物联系在一起.我想知道rake db:migrate是否可以解决我的任何问题...或者只是创建新问题...我只有样本数据填写了faker
有任何想法吗?
是否可以将我的文件系统恢复为先前的提交并重新开始?......当我是绿色的时候
Failures:
1) Micropost should create a new instance with valid attributes
Failure/Error: @user = Factory(:user)
ActiveRecord::StatementInvalid:
Could not find table 'users'
# ./spec/models/micropost_spec.rb:5:in `block (2 levels) in <top (required)>'
2) Micropost user associations should have a user attribute
Failure/Error: @user = Factory(:user)
ActiveRecord::StatementInvalid:
Could not find table 'users'
# ./spec/models/micropost_spec.rb:5:in `block (2 levels) in <top (required)>'
3) Micropost user associations should have the right associated user
Failure/Error: @user = Factory(:user)
ActiveRecord::StatementInvalid:
Could not find table 'users'
# ./spec/models/micropost_spec.rb:5:in `block (2 levels) in <top (required)>'
4) Micropost validations should have a user id
Failure/Error: @user = Factory(:user)
ActiveRecord::StatementInvalid:
Could not find table 'users'
# ./spec/models/micropost_spec.rb:5:in `block (2 levels) in <top (required)>'
5) Micropost validations should require nonblank content
Failure/Error: @user = Factory(:user)
ActiveRecord::StatementInvalid:
Could not find table 'users'
# ./spec/models/micropost_spec.rb:5:in `block (2 levels) in <top (required)>'
6) Micropost validations should reject long content
Failure/Error: @user = Factory(:user)
ActiveRecord::StatementInvalid:
Could not find table 'users'
# ./spec/models/micropost_spec.rb:5:in `block (2 levels) in <top (required)>'
Run Code Online (Sandbox Code Playgroud)
更新1:
我的错误从4到6到111都有一个反复出现的主题
1) Micropost should create a new instance with valid attributes
Failure/Error: @user = Factory(:user)
ActiveRecord::StatementInvalid:
Could not find table 'users'
# ./spec/models/micropost_spec.rb:53:in `block (2 levels) in <top (required)>'
Run Code Online (Sandbox Code Playgroud)
特别是"找不到表'用户’" - 我复制本教程的Git代码为micropost_spec.rb文件,但似乎并没有解决它 - 也许有人可以帮我直接到什么表指的是?
//////////////////////////////////////以下原件////////// //////////////////////
我正在使用Ruby on Rails Tutorial第11课,我正在尝试填充我的数据库来显示微博
当我做rake db:populate命令时,它给了我以下内容:
macbook:sample_app macbook$ rake db:populate
(in /Users/macbook/rails_screencast/sample_app)
db/test.sqlite3 already exists
db/test.sqlite3 already exists
db/development.sqlite3 already exists
-- create_table("microposts", {:force=>true})
-> 0.0090s
-- add_index("microposts", ["user_id"], {:name=>"index_microposts_on_user_id"})
-> 0.0074s
-- create_table("users", {:force=>true})
-> 0.0243s
-- add_index("users", ["email"], {:name=>"index_users_on_email", :unique=>true})
-> 0.0094s
-- initialize_schema_migrations_table()
-> 0.0167s
-- assume_migrated_upto_version(20110614132314, "db/migrate")
-> 0.0432s
rake aborted!
Validation failed: Email is invalid
Run Code Online (Sandbox Code Playgroud)
我运行了几次并且一直遇到同样的错误...当我在浏览器上访问该站点时,我的样本用户都没有...
require 'faker'
namespace :db do
desc "Fill database with sample data"
task :populate => :environment do
Rake::Task['db:reset'].invoke
admin = User.create!(:name => "Foo Bar",
:email => "foo@bar.com",
:password => "foobar",
:password_confirmation => "foobar")
admin.toggle!(:admin)
99.times do |n|
name = Faker::Name.name
email = "example-#{n+1}@railstutorial.org"
password = "password"
User.create!(:name => name,
:email => email,
:password => password,
:password_confirmation => password)
end
User.all(:limit => 6).each do |user|
50.times do
user.microposts.create!(:content => Faker::Lorem.sentence(5))
end
end
end
end
Run Code Online (Sandbox Code Playgroud)
然后我决定哦也许rake db:reset会清除我的示例数据库,我可以用新鲜的东西再次运行填充...错误的假设
我的测试套件现在显示:
Finished in 0.99915 seconds
111 examples, 111 failures
Run Code Online (Sandbox Code Playgroud)
在我搞砸了更多的东西之前,我正在寻找一些建议下一步去哪里...
rzs*_*hau 118
Michael(railstutorial.org的作者)回复了我的电子邮件请求!
如果在运行测试套件时丢失了一个表,则可能表明您需要运行:
rake db:test:prepare
Run Code Online (Sandbox Code Playgroud)
对!!YAYYYY
Finished in 4.82 seconds
108 examples, 0 failures
Run Code Online (Sandbox Code Playgroud)
蛋糕时间!
db:populate您所显示的 本身会执行此db:reset操作,因此手动执行不会导致 . 尚未发生的任何问题db:populate。
您只需删除db/*.sqlite3文件即可从头开始。该代码中没有任何明显的内容db:populate可以解释为什么电子邮件验证失败,您必须显示User模型和其中的验证,以便我们诊断初始问题。
| 归档时间: |
|
| 查看次数: |
22701 次 |
| 最近记录: |