On May 10, 10:47 am, venkata reddy
<venkatareddy...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Hi all, i am very new when it comes to writing tests, can anyone give
> me an idea how to write RSpec test for the following custom
> validation.
>
> def validate_campaign_and_ad
> unless self.ad.nil? || self.ad.campaign_id == self.campaign_id
> errors.add(:campaign_id, "ad.campaign (#{self.ad.campaign_id})
> does not match campaign (#{self.campaign_id})")
> end
> end
I''d start by constructing an object that should pass the validation
and checking that some_object.should be_valid? and then by
constructing an object that isn''t valid and checking that the object
isn''t valid and that the right error message is present.
Fred
>
> Thanks in Advance
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.