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> -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thorsten Muller
2007-Nov-14 17:49 UTC
Re: validate_presence_of unit testing with if condition
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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thorsten Muller 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_sourceYes, the layers table has a string type column named ''data_source'' -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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) On Nov 14, 2007 12:01 PM, Joan Gu <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Thorsten Muller 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'' > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---