FactoryGirl.define do factory :<%= singular_table_name %><%= explicit_class_option %> do <% i = 0 -%> <% for attribute in attributes -%> <% if attribute.reference? -%> association :<%= attribute.name %>, factory: :<%= attribute.name %> <% elsif attribute.name == 'email' -%> sequence(:<%= attribute.name %>) {|n| "email#{format "%02d", n}@gmail.com" } <% elsif attribute.name =~ /(.*)_url$/ -%> sequence(:<%= attribute.name %>) {|n| "http://<%= $1 %>#{format "%02d", n}.com" } <% elsif attribute.name == 'password' -%> password 'password' <% elsif attribute.name == 'position' -%> sequence(:<%= attribute.name %>) {|n| n } <% elsif [:string, :text].include? attribute.type -%> sequence(:<%= attribute.name %>) {|n| "<%= attribute.name.capitalize.gsub('_', ' ') %>#{format "%02d", n}" } <% elsif attribute.type == :integer -%> <% i += 1 -%> sequence(:<%= attribute.name %>) {|n| "<%= i %>#{format "%02d", n}" } <% else -%> <%= attribute.name %> <%= attribute.default.inspect %> <% end -%> <% end -%> end end