在我的應用程序,一個組織的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