Testing simple STI with FactoryGirl

后端 未结 1 533
挽巷
挽巷 2021-02-05 02:22

I have got a class, that is the base of some other classes that specializes the behavior:

class Task < ActiveRecord::Base
  attr_accessible :type, :name, :com         


        
相关标签:
1条回答
  • 2021-02-05 03:00

    You can declare the definitions of factories as follow:

    FactoryGirl.define do
      factory :task, class: 'Task' do
        shop
        currency
        value 10
      end
    
      factory :counter_task, parent: :task, class: 'CounterTask' do
      end
    end
    

    And now you can test base class isolated from its own factory and the same for each inherited class.

    0 讨论(0)
提交回复
热议问题