vendredi 19 juillet 2019

Ruby on Rails Testing - ActiveRecord::StatementInvalid: PG::InvalidTextRepresentation: ERROR: malformed array literal:

I have a project that is running ok on production and development and mostly on many tests, but with on model there's no way to run the tests.

Model:

create_table "cities", force: :cascade do |t|
  t.string "city"
  t.string "cp", array: true
  t.datetime "created_at", null: false
  t.datetime "updated_at", null: false
  t.string "name"
  t.string "primary_cp"
end

(Note that "cp" attribute is an Array and I'm using Postgres on the project) (I'm NOT setting "serialize :cp, Array" on the model)

But when I run rails test test/models/city_test.rb what I get is

Error:
CityTest#test_the_truth:
ActiveRecord::StatementInvalid: PG::InvalidTextRepresentation: ERROR:  
malformed array literal: "MyString"
LINE 28: ...d_at") VALUES (980190962, 'MyString', 'MyString', 
'MyString'...
                                                          ^
DETAIL:  Array value must start with "{" or dimension information.
: DELETE FROM "homes";
DELETE FROM "categories";
DELETE FROM "volunteers";
DELETE FROM "donations";

I've already search other solution here but it doesn't fix the problem. What I'm guessing is that is something related to the yaml serialization that test environment do, but I'm not quite sure.

I have no problem with development and production environments at all, it only happens on test env.

Aucun commentaire:

Enregistrer un commentaire