In the layer.rb model, I have
validates_presence_of :data_source
validates_presence_of :url, :if => :other_dataset?
def other_dataset?
data_source == ‘other’
end
When I tried to do the unit testing,
def test_when_datasource_is_other
layer = Layer.new(:data_source =>‘other’, :url => nil)
assert !layer.valid?
assert layer.errors.invalid?(:url)
end
it keeps throw me an error:
NoMethodError: undefined method `data_source=’ for #Layer:0x311bce8
does your table have a column with the name ‘data_source’ ?
if this is only temporary data, you must define it with
attr_accessor :data_source
Thorsten M. wrote:
does your table have a column with the name ‘data_source’ ?
if this is only temporary data, you must define it with
attr_accessor :data_source
Yes, the layers table has a string type column named ‘data_source’
Ensure your test database is up to date schema-wise.
rake db:test:clone
If you recently did a migrate, that puts your test db out of sync.
I’ve got a plugin I’ll release soon that just makes db:migrate do the
db:test:clone step automatically (cos I always forget to do that when I
run
tests in textmate)