2015-11-02 65 views
1

在我的应用程序,一个组织的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 
+0

可以粘贴在日志中的SQL当您从开发控制台执行该查询? – tompave

回答

0

如果它的工作原理在开发中而不是在测试中,很可能您的测试数据库不包含该表。

与尝试:

bundle exec rake db:migrate 
bundle exec rake db:test:prepare 
+0

谢谢,但这没有帮助。 – user1883793

+0

它缺少rspec测试中的命名空间,任何想法? – user1883793

+0

我不得不把它放在我的模型中,使其工作' self.table_name =“ihub_invoices”' – user1883793