【问题标题】:factory_girl causing RSpec spec to fail after Rails 4 upgrade升级 Rails 4 后 factory_girl 导致 RSpec 规范失败
【发布时间】:2014-08-12 08:20:19
【问题描述】:

我刚刚将我的应用升级到 Rails 4,我的几个 RSpec 规范现在都失败了,所有这些都以同样的方式。

SQL (82.3ms)  INSERT INTO "profiles" ("career_goal", "created_at", "email", "encrypted_password", "first_name", "gpa", "grad_year", "hidden", "keywords", "kind", "last_name", "major_names", "middle_name", "minor_names", "phone", "id", "research_interest", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)  [["career_goal", ["Illum et sunt.", "Illo sapiente nesciunt reiciendis nulla fugit est autem."]], ["created_at", Sat, 21 Jun 2014 15:12:40 PDT -07:00], ["email", "madonna@huels.name"], ["encrypted_password", "$2a$10$y1zijhGouDy1OT4qHGnXR./FvXP9T7DHHvu4BofAt5ZBJrqjFisty"], ["first_name", "Jayde"], ["gpa", #<BigDecimal:e684850,'0.25E1',18(36)>], ["grad_year", 2013], ["hidden", false], ["keywords", "Daisha Ea placeat debitis repellendus autem ad voluptas. Illum et sunt. Illo sapiente nesciunt reiciendis nulla fugit est autem.   "], ["kind", "student"], ["last_name", "Reilly"], ["major_names", "Anthropology"], ["middle_name", "Daisha"], ["minor_names", "Sociology"], ["phone", "724-953-4023 x4372"], ["id", "01234567"], ["research_interest", "Ea placeat debitis repellendus autem ad voluptas."], ["updated_at", Sat, 21 Jun 2014 15:12:40 PDT -07:00]]

TypeError: can't cast Array to text: INSERT INTO "profiles" ("career_goal", "created_at", "email", "encrypted_password", "first_name", "gpa", "grad_year", "hidden", "keywords", "kind", "last_name", "major_names", "middle_name", "minor_names", "phone", "id", "research_interest", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

现在INSERT INTO "profiles" ("fields", etc) VALUES (?,?,?) 的 for 中的 SQL 调用似乎格式不正确,任何关于为什么 VALUES 部分都是 ?s 的见解将不胜感激。我检查了我对 :profile 的定义,这似乎不是我在其他地方读到的 Faker 问题。 (我有Faker::Lorem.words(4).join('-'),它没有提供数组或任何东西。这是一个 Active Record 问题吗?还有其他地方我应该寻找错误或需要重新配置的东西吗?

【问题讨论】:

    标签: ruby-on-rails ruby ruby-on-rails-4 rspec factory-bot


    【解决方案1】:

    问号不是问题;它们是值的占位符。

    这部分值数组

    ["career_goal", ["Illum et sunt.", "Illo sapiente nesciunt reiciendis nulla fugit est autem."]]
    

    表示career_goal 设置为一个数组。将其更改为单个字符串(使用join 或重写它,无论如何)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-09
      • 2013-10-14
      相关资源
      最近更新 更多