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:
parent
a14419f04f
commit
1bcc2242c0
2 changed files with 9 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue