user3579987 user3579987 - 3 months ago 18
Ruby Question

factory_girl causing RSpec spec to fail after Rails 4 upgrade

I just upgraded my app to Rails 4 and several of my RSpec specs now fail, all in the same way.

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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)


It looks like the SQL call is somehow malformed now in the for of
INSERT INTO "profiles" ("fields", etc) VALUES (?,?,?)
Any insight as to why the VALUES part is all ?s would be appreciated. I checked my define for :profile and it doesn't seem to be a Faker issue as I had read elsewhere. (I have
Faker::Lorem.words(4).join('-')
which doesn't give an array or anything. Is this an Active Record problem? Is there anywhere else I should be looking for errors or things that need reconfiguring?

Answer

The question marks aren't a problem; they're placeholders for the values.

This part of your array of values

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

indicates that career_goal is set to an array. Change it to a single string (with join or by rewriting it, whatever).

Comments