paulelliott / fabrication

This project has moved to GitLab! Please check there for the latest updates.
https://gitlab.com/fabrication-gem/fabrication
MIT License
998 stars 97 forks source link

postgres error with complex class_name #294

Closed ghost closed 7 years ago

ghost commented 7 years ago

I have a strange postgres table mapped in this way with rails AR:

class Data::Doctor < ActiveRecord::Base
  self.table_name = 'tb_utenti'
  self.primary_key = "codice_utente"
  # other stuff ...
end

then i defined the fabricator:

Fabricator(:doctor, class_name: "Data::Doctor") do
  codice_utente { SecureRandom.uuid }
  # other attributes ...
end

but i retrieved an error in rspec example:

     Failure/Error: Fabricate.build(model_s, attributes)

     ActiveRecord::StatementInvalid:
       PG::UndefinedTable: ERROR:  relation "tb_utenti" does not exist
       LINE 5:                WHERE a.attrelid = '"tb_utenti"'::regclass
                                                 ^
       :               SELECT a.attname, format_type(a.atttypid, a.atttypmod),
                            pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
                       FROM pg_attribute a LEFT JOIN pg_attrdef d
                         ON a.attrelid = d.adrelid AND a.attnum = d.adnum
                      WHERE a.attrelid = '"tb_utenti"'::regclass
                        AND a.attnum > 0 AND NOT a.attisdropped
                      ORDER BY a.attnum

ruby 2.2.5 rails 4.2.8

paulelliott commented 7 years ago

It looks like you may not have run migrations in your test environment. Try running "rake db:migrate RAILS_ENV=test"