This file contains 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
#!/usr/bin/env ruby | |
# | |
# Originally written by http://redartisan.com/tags/csv | |
# Added and minor changes by Gavin Laking | |
# Rewritten by Andrew Bennett for Ruby 1.9 | |
# | |
# Usage: ruby csv_to_fixture.rb file.csv [--json] | |
# | |
# "id","name","mime_type","extensions","icon_url" | |
# "1","unknown","unknown/unknown","||","/images/icon/file_unknown.gif" |
This file contains 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
step 'the following category records' do |table| | |
table.hashes.each do |hash| | |
a = AttributeSet.find_or_create_by(slug: 'myattritubetest', label: 'myattributetest', description: 'myattributeset') | |
if hash['parents'].present? | |
path = hash['parents'].split(', ') | |
ancestor = Category.find_or_create_by(title: path.shift, attribute_set_id: a.id) | |
path.each_with_index do |ancestor_title, index| | |
category = Category.find_or_create_by(title: ancestor_title, parent_id: ancestor.id, attribute_set_id: a.id) | |
ancestor = category | |
end |