]> git.openstreetmap.org Git - rails.git/commitdiff
Make sure that there is a sender and a recipient of a message. New test to make sure...
authorShaun McDonald <shaun@shaunmcdonald.me.uk>
Fri, 18 Jul 2008 16:44:14 +0000 (16:44 +0000)
committerShaun McDonald <shaun@shaunmcdonald.me.uk>
Fri, 18 Jul 2008 16:44:14 +0000 (16:44 +0000)
app/models/message.rb
test/unit/message_test.rb

index 97e411192b0df5cedbd89d7255f236ac7fb2cf35..ec712be252a706b9c1e68541dd3e4a816b90f7a1 100644 (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
index 28c7605ffb979326e57589c5969e39908859a607..4de1a7b295557420a114e711a89b1b5a36791698 100644 (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