Skip to content

Instantly share code, notes, and snippets.

@cbartlett
Created January 27, 2011 22:21
Show Gist options
  • Save cbartlett/799418 to your computer and use it in GitHub Desktop.
Save cbartlett/799418 to your computer and use it in GitHub Desktop.
Given /^that ([^"]*) has (\d+) ([^"]*)$/ do |parent, count, child|
parent = parent.gsub(/\W+/,'_').downcase.sub(/^_/, '')
parent_instance = instance_variable_get("@#{parent}")
child = child.gsub(/\W+/,'_').downcase
child_class = Fabrication::Support.class_for(child.singularize)
if child_class && !child_class.new.respond_to?("#{parent}=")
parent = parent.pluralize
parent_instance = [parent_instance]
end
create_with_default_attributes(child, count.to_i, parent => parent_instance)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment