2016-08-18 80 views
1

相似名稱的測試加載夾具我有3個班,STI,我想加載夾具每個:Rails的不與STI

Employee

Admin < Employee

OtherEmployee < Employee

我test_helper檔案有fixtures :all

和夾具在:

employees.yml admins.yml other_employees.yml

,但只從other_employees.yml數據被加載到數據庫中。任何想法爲什麼或如何解決這個問題?

燈具:

#employees.yml 
one: 
    id: 1 
    name: Name1 
    full_name: FName1 
    type: Admin 

two: 
    name: Name2 
    full_name: FName2 
    type: Admin 

three: 
    name: Name3 
    full_name: FName3 
    type: OtherEmployee 

#admins.yml 

adminone: 
    name: Admin1 
    full_name: FAdmin1 
    type: Admin 

admintwo: 
    name: Admin2 
    full_name: FAdmin2 
    type: Admin 

#other_employees.yml 

oeone: 
    name: Oemp1 
    full_name: FOemp1 
    type: OtherEmployee 

oetwo: 
    name: Oemp2 
    full_name: FOemp2 
    type: OtherEmployee 

回答

0

您使用Rails的哪個版本?看來,這是一個錯誤,並固定在導軌5和4.2

https://github.com/rails/rails/issues/18492

還有在最後的評論,可能是有幫助的一些信息。

https://github.com/rails/rails/issues/18492#issuecomment-218479248

對於任何人仍在運行到這個問題,你需要一個 類型的屬性添加到您的燈具,其代表着你的 模型STI屬性。對於提供的示例,這將是:

#teachers.yml 
presto: 
    name: Test Teacher 
    type: Teacher 
#students.yml 
testo: 
    name: Test Person 
    teacher: presto 
    type: Student 
+0

我正在使用rails 4.2.6。如果我像上面那樣嘗試,數據庫似乎只需要1個文件。具體而言,以後按字母順序排列,這可能是一條線索。 – akoller

+0

你可以發佈你的夾具文件的樣子嗎? – kcdragon

+0

完成。讓我知道這是否有幫助。 – akoller