fixes #778
This commit is contained in:
@@ -3,6 +3,7 @@ class Dmail < ActiveRecord::Base
|
||||
validates_presence_of :from_id
|
||||
validates_format_of :title, :with => /\S/
|
||||
validates_format_of :body, :with => /\S/
|
||||
validate :validate_sender_is_not_banned
|
||||
before_validation :initialize_from_id, :on => :create
|
||||
belongs_to :owner, :class_name => "User"
|
||||
belongs_to :to, :class_name => "User"
|
||||
@@ -153,6 +154,15 @@ class Dmail < ActiveRecord::Base
|
||||
include FactoryMethods
|
||||
extend SearchMethods
|
||||
|
||||
def validate_sender_is_not_banned
|
||||
if from.is_banned?
|
||||
errors[:base] = "Sender is banned and cannot send messages"
|
||||
return false
|
||||
else
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
def quoted_body
|
||||
"[quote]#{body}[/quote]"
|
||||
end
|
||||
|
||||
@@ -16,6 +16,19 @@ class DmailTest < ActiveSupport::TestCase
|
||||
CurrentUser.user = nil
|
||||
end
|
||||
|
||||
context "from a banned user" do
|
||||
setup do
|
||||
@user.update_attribute(:is_banned, true)
|
||||
end
|
||||
|
||||
should "not validate" do
|
||||
dmail = FactoryGirl.build(:dmail, :title => "xxx", :owner => @user)
|
||||
dmail.save
|
||||
assert_equal(1, dmail.errors.size)
|
||||
assert_equal(["Sender is banned and cannot send messages"], dmail.errors.full_messages)
|
||||
end
|
||||
end
|
||||
|
||||
context "search" do
|
||||
should "return results based on title contents" do
|
||||
dmail = FactoryGirl.create(:dmail, :title => "xxx", :owner => @user)
|
||||
|
||||
Reference in New Issue
Block a user