【问题标题】:Rake Unit Testing : "False" being used for column "no"Rake 单元测试:“否”列使用“假”
【发布时间】:2012-12-11 22:42:21
【问题描述】:

发布 :: 模型

class Post < ActiveRecord::Base
  attr_accessible :body, :name, :no, :num
end

(test/fixtures/)下的Posts.yml

one:
  name: MyString
  body: MyString
  no: 1
  num: 2

在运行时,rake test:units,会生成以下堆栈跟踪

Error:
test_Post_for_correct_attributes(PostTest):
ActiveRecord::StatementInvalid: SQLite3::SQLException: table posts has no column named false: INSERT INTO "posts" ("name", "body", "false", "num", "created_at", "updated_at", "id") VALUES ('MyString', 'MyString', 1, 2, '2012-12-26 10:24:36', '2012-12-26 10:24:36', 980190962)

现在,这里 - 表字段“no”已转换为“false”。 (这似乎是一个问题,因为它被解释为 FALSE 而不是对象变量)

关于如何将变量从 yaml 转换为对象的错误?

Rails 版本 Rails 3.2.9 和 Ruby ruby 1.9.3p194

【问题讨论】:

标签: ruby-on-rails ruby-on-rails-3 unit-testing rake


【解决方案1】:

这对我来说似乎是一个错误,因为 Rails 应该能够接受这一点,尤其是因为这是自动生成的。无论如何,作为临时锻炼,您可以使用:

one:
  name: MyString
  body: MyString
  "no": 1
  num: 2

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-07-10
  • 1970-01-01
  • 1970-01-01
  • 2011-04-10
  • 2021-07-26
  • 2013-12-07
  • 2018-10-17
相关资源
最近更新 更多