Make sure that there is a sender and a recipient of a message. New test to make sure that there a message also has a sender and a recipient, as the validates_associated doesn't do anything if they are nil.

This commit is contained in:
Shaun McDonald 2008-07-18 16:44:14 +00:00
parent a14419f04f
commit 1bcc2242c0
2 changed files with 9 additions and 3 deletions

View file

@ -2,7 +2,7 @@ class Message < ActiveRecord::Base
belongs_to :sender, :class_name => "User", :foreign_key => :from_user_id
belongs_to :recipient, :class_name => "User", :foreign_key => :to_user_id
validates_presence_of :title, :body, :sent_on
validates_presence_of :title, :body, :sent_on, :sender, :recipient
validates_inclusion_of :message_read, :in => [ true, false ]
validates_associated :sender, :recipient
end

View file

@ -20,9 +20,15 @@ class MessageTest < Test::Unit::TestCase
def test_validating_msgs
message = messages(:one)
assert_equal true, message.valid?
assert message.valid?
massage = messages(:two)
assert_equal true, message.valid?
assert message.valid?
end
def test_invalid_send_recipient
message = messages(:one)
message.sender = nil
message.recipient = nil
assert !message.valid?
end
end