Created
March 20, 2009 04:59
-
-
Save khalsah/82222 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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