From 1bcc2242c0a5bc58abb0ab23964d474af04923fa Mon Sep 17 00:00:00 2001 From: Shaun McDonald Date: Fri, 18 Jul 2008 16:44:14 +0000 Subject: [PATCH] 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. --- app/models/message.rb | 2 +- test/unit/message_test.rb | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/models/message.rb b/app/models/message.rb index 97e411192..ec712be25 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -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 diff --git a/test/unit/message_test.rb b/test/unit/message_test.rb index 28c7605ff..4de1a7b29 100644 --- a/test/unit/message_test.rb +++ b/test/unit/message_test.rb @@ -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 -- 2.39.5