Created
August 20, 2013 01:56
-
-
Save iorionda/6276293 to your computer and use it in GitHub Desktop.
rails console で
[email protected](main)> model.first.to_fg
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$/, '')}" | |
else | |
array << " #{key} #{value.inspect}" | |
end | |
end | |
array << " end" | |
array << "end" | |
array.join("\n") | |
end | |
alias_method :to_fg, :to_factory_girl | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment