2015-11-02 61 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