2016-08-18 83 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