更新: | 2024-05-20 |
---|---|
作者: | @voluntas |
バージョン: | 2024.1 |
URL: | https://voluntas.github.io/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ActiveRecord::Base | |
def to_factory_girl | |
ignores = %w(id created_at updated_at) | |
array = [] | |
array << "FactoryGirl.define do" | |
array << " factory :#{self.class.model_name.underscore} do" | |
attributes.each do |key, value| | |
next if ignores.include?(key) | |
if key =~ /_id$/ | |
array << " association :#{key.gsub(/_id$/, '')}" |