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


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@googlegroups.com.
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.

Search Discussions

  • Frederick Cheung at May 10, 2012 at 12:03 pm

    On May 10, 10:47 am, venkata reddy 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@googlegroups.com.
    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedMay 10, '12 at 9:47a
activeMay 10, '12 at 12:03p
posts2
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Venkata reddy: 1 post Frederick Cheung: 1 post

People

Translate

site design / logo © 2021 Grokbase