class CreateFactory
Public Class Methods
call(objects)
click to toggle source
# File lib/create_factory.rb, line 5 def call(objects) File.open(path, "w+") do |f| objects.each do |object| f.puts(formatte_factory(object)) f.puts("\n") end end end
Private Class Methods
formatte_factory(object)
click to toggle source
# File lib/create_factory.rb, line 20 def formatte_factory(object) atttributes_symbolized = object[:attributes][0].inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo} formatted_attributes = atttributes_symbolized.to_s.delete(':').delete('{').delete('}').gsub("=>", ": ") factory_name = object[:table].singularize.to_sym "let(:#{factory_name}) { create :#{factory_name}, #{formatted_attributes} }" end
path()
click to toggle source
# File lib/create_factory.rb, line 16 def path Rails.env.test? ? "./dummy_app/spec/data.txt" : "spec/data.txt" end