在 Rails3 中测试 Cancan 授权时 SQLite3 错误:没有这样的表:能力:从“能力”中删除其中 1=1
我在使用 Cancan (http://github.com/ryanb/康康舞)。这些测试是简单的自动生成的测试,看起来像
测试“真相”所做的那样 断言为真 每个单独的测试(单元测试和功能测试)都会
产生以下错误:
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table: opportunity: DELETE FROM "powered" WHERE 1=1
即使定义了用途和能力,也会发生这种情况在 test_helpers.rb 中,
我认为这是由于 Cancan 用于授权的能力模型,因为它没有持久化(只是一个普通的 Ruby 类),因此在数据库中没有表。也许有什么东西试图在测试后拆除能力并错误地尝试从数据库中删除能力?我怎样才能检查这个(更重要的是,修复)?
再次强调,测试中没有自定义逻辑:它们是由 Rails3 beta4 生成的。
(仅供参考,Ability 类不是从 ActiveRecord::Base 继承的,而是包含 CanCan::Ability。此外,应用程序(授权和所有)都工作正常。)
环境: - 红宝石 1.8.7-p249 - Rails 3.0.0.beta4 - 康康舞 1.2.0 - devise 1.1.rc2
还有其他人遇到这个问题吗?
感谢您的帮助 !
更新:尝试切换到 PostgreSQL。显然,错误与数据库无关:运行“rake test”时出现以下错误
ActiveRecord::StatementInvalid: PGError: ERROR: 关系“能力”不存在 第 1 行:从“能力”中删除 ^ :从“能力”中删除
I'm having issues when running the default tests in Rails3 beta4 with Cancan (http://github.com/ryanb/cancan). The tests are the plain vanilla auto-generated ones that look like
test "the truth" do
assert true
end
Every single test (both unit and functional) yields the following error :
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table: abilities: DELETE FROM "abilities" WHERE 1=1
This happens even if a use and ability are defined in test_helpers.rb
I assume this is due to the Ability model Cancan uses for authorization as it isn't persisted (just a plain Ruby class) and therefore has no table in the DB. Perhaps something is trying to tear down abilities after tests and mistakenly trying to delete abilities from the database? How can I check this (and more importantly, fix)?
Once again, there is no custom logic in the tests: they are as generated by Rails3 beta4.
(FYI the Ability class does not inherit from ActiveRecord::Base and includes CanCan::Ability. Also, the app--authorization and all--works fine.)
Environment:
- ruby 1.8.7-p249
- rails 3.0.0.beta4
- cancan 1.2.0
- devise 1.1.rc2
Anybody else run into this issue ?
Thanks for your help !
UPDATE: tried switching to PostgreSQL. Evidently, error is DB-independent: got the following error when running "rake test"
ActiveRecord::StatementInvalid: PGError: ERROR: relation "abilities" does not exist
LINE 1: DELETE FROM "abilities"
^
: DELETE FROM "abilities"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题已解决:我有一个 Skills.yml 固定文件。删除后,错误就消失了。
http://github.com/ryanb/cancan/issues/angled#issue/ 109
Problem solved: I had an abilities.yml fixture file. After deleting it, the error is gone.
http://github.com/ryanb/cancan/issues/closed#issue/109