Skip to content

Instantly share code, notes, and snippets.

@khalsah
Created March 20, 2009 04:59
Show Gist options
  • Save khalsah/82222 to your computer and use it in GitHub Desktop.
Save khalsah/82222 to your computer and use it in GitHub Desktop.
Given /^the following (.+) exist(?:s|):$/ do |model_name, table|
model_name = model_name.split(' ')
variation_name = []
begin
model = model_name.join('_').classify.constantize
rescue
variation_name << model_name.shift
if model_name.length > 0 then retry else raise end
end
args = []
args << variation_name.join('_').to_sym if variation_name.length > 0
table.hashes.each do |hash|
attributes = {}
hash.each { |k,v| attributes[k.gsub(' ','').underscore] = v }
args << attributes
model.make(*args)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment