Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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