Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Animal < ActiveRecord::Base
- end
- class Bird < Animal
- end
- class Monkey < Animal
- end
- FactoryGirl.define do
- factory :animal do
- initialize_with do
- if [true, false].sample
- Monkey.new
- else
- Bird.new
- end
- end
- end
- end
- FactoryGirl.define do
- factory(:animal) do
- type { %w[Monkey Bird].sample }
- initialize_with do
- record = new(attributes)
- record.becomes(record.type.constantize)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement