Commit d22c261e52998c42af3feb91cf9028eb9cb7685e
Committed by
Antonio Terceiro
1 parent
7fac6d07
Exists in
master
and in
29 other branches
ActionItem791: validate contact before deliver mail
Showing
3 changed files
with
14 additions
and
0 deletions
Show diff stats
app/models/contact.rb
... | ... | @@ -16,6 +16,7 @@ class Contact < ActiveRecord::Base #WithoutTable |
16 | 16 | validates_format_of :email, :with => Noosfero::Constants::EMAIL_FORMAT, :if => (lambda {|o| !o.email.blank?}) |
17 | 17 | |
18 | 18 | def deliver |
19 | + return false unless self.valid? | |
19 | 20 | Contact::Sender.deliver_mail(self) |
20 | 21 | end |
21 | 22 | ... | ... |
test/functional/contact_controller_test.rb
... | ... | @@ -74,4 +74,10 @@ class ContactControllerTest < Test::Unit::TestCase |
74 | 74 | assert_tag :tag => 'input', :attributes => {:name => 'contact[receive_a_copy]'} |
75 | 75 | end |
76 | 76 | |
77 | + should 'not deliver contact if mandatory field is blank' do | |
78 | + post :new, :profile => enterprise.identifier, :contact => {:subject => 'Hi', :message => 'Hi, all'} | |
79 | + assert_response :success | |
80 | + assert_template 'new' | |
81 | + end | |
82 | + | |
77 | 83 | end | ... | ... |
test/unit/contact_test.rb
... | ... | @@ -37,4 +37,11 @@ class ContactTest < ActiveSupport::TestCase |
37 | 37 | assert c.deliver |
38 | 38 | end |
39 | 39 | |
40 | + should 'not deliver message if contact is invalid' do | |
41 | + ent = Enterprise.create!(:name => 'my enterprise', :identifier => 'myent', :environment => Environment.default) | |
42 | + c = Contact.new(:name => 'john', :subject => 'hi', :message => 'hi, all', :dest => ent) | |
43 | + assert !c.valid? | |
44 | + assert !c.deliver | |
45 | + end | |
46 | + | |
40 | 47 | end | ... | ... |