Hi there,
I got a Problem using comma-seperated-values as fixtures. It simply does
not fixture anything, no error message at all.
Here my code (… => RAILS_ROOT):
the test in …/test/unit/uk/incode_test.rb
require File.dirname(FILE) + ‘/…/…/test_helper’
class UK::IncodeTest < Test::Unit::TestCase
fixtures File.join( ‘uk’, ‘uk_incodes’ )
def test_class_for
# Returns record for provided incode.code and caches set
time_before = Time.now
assert_nil UK::Incode.for(‘0000’)
distance = Time.now - time_before
time_before = Time.now
assert_instance_of UK::Incode, UK::Incode.for('PH50')
# stupid test...
assert distance > Time.now - time_before
end
end
the csv in …/test/fixtures/uk/uk_incodes.csv
code, posttown, county
AB10, ABERDEEN, Aberdeenshire
AB11, ABERDEEN, Aberdeenshire
AB12, ABERDEEN, Aberdeenshire
AB13, MILLTIMBER, Aberdeenshire
AB14, PETERCULTER, Aberdeenshire
AB15, ABERDEEN, Aberdeenshire
snip
the model in …/app/models/uk/incode.rb
module UK
class Incode < ActiveRecord::Base
set_table_name ‘uk_incodes’
validates_presence_of :code
validates_presence_of :county
@@postcodes = Hash.new
# Returns record for provided incode.code and caches set
def self.for code
if @@postcodes.empty?
self.find( :all ).each do |postcode|
@@postcodes[ postcode.code.to_sym ] = postcode
end
end
p @@postcodes
@@postcodes[ code.to_sym ]
end
end
end
Thanks for any advice
Florian