Path: | example.rb |
Last Update: | Thu Oct 22 18:04:19 +0000 2009 |
Define a fixtures helper method to load up our test data.
# File example.rb, line 7 7: def fixtures(name) 8: entry = YAML::load_file(File.dirname(__FILE__) + "/spec/fixtures/#{name}.yaml") 9: klass = begin 10: Kernel::const_get(Inflector.classify(Inflector.singularize(name))) 11: rescue 12: nil 13: end 14: 15: unless klass.nil? 16: database.logger.debug { "AUTOMIGRATE: #{klass}" } 17: klass.auto_migrate! 18: 19: (entry.kind_of?(Array) ? entry : [entry]).each do |hash| 20: if hash['type'] 21: Object::const_get(hash['type'])::create(hash) 22: else 23: klass::create(hash) 24: end 25: end 26: else 27: table = database.table(name.to_s) 28: table.create! true 29: table.activate_associations! 30: 31: #pp database.schema 32: 33: (entry.kind_of?(Array) ? entry : [entry]).each do |hash| 34: table.insert(hash) 35: end 36: end 37: end