在我的应用程序,一个组织的has_many发票和组织没有任何名称空间,但发票上有IHUB ::发票,并在我的组织模式我有Rspec的失败命名空间的has_many关系
has_many :invoices, class_name: 'Ihub::Invoice'
在我控制器我这一行,工作正常发展:
@invoices = Ihub::Invoice.where(organisation_id: current_organisation.id).page(params[:page])
我的RSpec的失败与此错误:
Failure/Error: Unable to find matching line from backtrace
ActiveRecord::StatementInvalid:
PG::UndefinedTable: ERROR: relation "invoices" does not exist
LINE 5: WHERE a.attrelid = '"invoices"'::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 = '"invoices"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
更新
已经尝试过,这并没有帮助。在发展
RAILS_ENV=test rake db:drop db:create db:schema:load
SQL查询
Ihub::Invoice Load (0.2ms) SELECT "ihub_invoices".* FROM "ihub_invoices" WHERE "ihub_invoices"."organisation_id" = $1 [["organisation_id", 89]]
在rspec的
SQL错误(不同的查询IHUB :: Invoice.first),但你可以看到命名空间缺失
Failure/Error: Unable to find matching line from backtrace
ActiveRecord::StatementInvalid:
PG::UndefinedTable: ERROR: relation "invoices" does not exist
LINE 1: SELECT "invoices".* FROM "invoices" ORDER BY "invoices"."i...
^
: SELECT "invoices".* FROM "invoices" ORDER BY "invoices"."id" ASC LIMIT 1
可以粘贴在日志中的SQL当您从开发控制台执行该查询? – tompave