2011-05-29 132 views
3

如何解决数据库锁定问题?因为我的测试没有通过 - 它使同一类别中的一堆测试失败。谢谢!数据库被锁定?

1) UsersController GET 'edit' should have a link to change the Gravatar 
    Failure/Error: @user = Factory(:user) 
    SQLite3::BusyException: database is locked: INSERT INTO "users" ("created_at", "email", "encrypted_password", "name", "salt", "updated_at") VALUES ('2011-05-29 03:47:07.510067', '[email protected]', 'fc70fcb4b094b388d87c5054ed9b0bfa06f53431d44c527e852c5bdffd3a0fa8', 'Matthew Berman', NULL, '2011-05-29 03:47:07.510067') 
    # ./spec/controllers/users_controller_spec.rb:128:in `block (3 levels) in <top (required)>' 

回答

16

这是由于Rails控制台会话正在打开。为了在将来避免这种情况,一定要bin/rails console -s,并且在访问SQLite 3 DB时确保退出任何控制台会话。

+6

如果其他人对轨道选项有点困惑/无知,他意味着脚本/轨道控制台-s。 -s用于“沙箱”,意味着退出时所有更改都会回滚。我想这意味着控制台不需要在数据库上写入锁定;尽管为什么它会永远保持写入锁之间的命令对我来说是神秘的。 – 2012-06-10 00:18:55