Commit c091bfbf35937bdd629423e06c9515e806362c8e

Authored by Joenio Costa
Committed by Antonio Terceiro
1 parent f3f04a53

ActionItem791: send copy of message to requester

app/models/contact.rb
... ... @@ -5,7 +5,8 @@ class Contact < ActiveRecord::Base #WithoutTable
5 5 [:message, :string],
6 6 [:email, :string],
7 7 [:state, :string],
8   - [:city, :string]
  8 + [:city, :string],
  9 + [:receive_a_copy, :boolean]
9 10 ]
10 11 attr_accessor :dest
11 12  
... ... @@ -23,6 +24,9 @@ class Contact < ActiveRecord::Base #WithoutTable
23 24 emails = [contact.dest.contact_email] + contact.dest.admins.map{|i| i.email}
24 25 recipients emails
25 26 from "#{contact.name} <#{contact.email}>"
  27 + if contact.receive_a_copy
  28 + cc "#{contact.name} <#{contact.email}>"
  29 + end
26 30 subject contact.subject
27 31 body :name => contact.name,
28 32 :email => contact.email,
... ...
app/views/contact/new.rhtml
... ... @@ -9,6 +9,7 @@
9 9 <%= labelled_form_field _('City and state'), select_city(true) %>
10 10 <%= f.text_field :subject %>
11 11 <%= f.text_area :message, :rows => 10, :cols => 60 %>
  12 + <%= labelled_form_field check_box(:contact, :receive_a_copy) + _('Want to receive a copy of your message in your mailbox?'), '' %>
12 13  
13 14 <%= submit_button(:send, _('Send')) %>
14 15  
... ...
test/functional/contact_controller_test.rb
... ... @@ -69,4 +69,9 @@ class ContactControllerTest &lt; Test::Unit::TestCase
69 69 assert_equal 'Bahia', assigns(:contact).state
70 70 end
71 71  
  72 + should 'display checkbox for receive copy of email' do
  73 + get :new, :profile => enterprise.identifier
  74 + assert_tag :tag => 'input', :attributes => {:name => 'contact[receive_a_copy]'}
  75 + end
  76 +
72 77 end
... ...
test/unit/contact_sender_test.rb
... ... @@ -41,6 +41,20 @@ class ContactSenderTest &lt; Test::Unit::TestCase
41 41 assert_includes response.to, admin.email
42 42 end
43 43  
  44 + should 'deliver a copy of email if requester wants' do
  45 + ent = Enterprise.new(:name => 'my enterprise', :identifier => 'myent', :environment => Environment.default)
  46 + c = Contact.new(:dest => ent, :email => 'requester@invalid.com', :receive_a_copy => true)
  47 + response = Contact::Sender.deliver_mail(c)
  48 + assert_includes response.cc, c.email
  49 + end
  50 +
  51 + should 'not deliver a copy of email if requester dont wants' do
  52 + ent = Enterprise.new(:name => 'my enterprise', :identifier => 'myent', :environment => Environment.default)
  53 + c = Contact.new(:dest => ent, :email => 'requester@invalid.com', :receive_a_copy => false)
  54 + response = Contact::Sender.deliver_mail(c)
  55 + assert_nil response.cc
  56 + end
  57 +
44 58 private
45 59  
46 60 def read_fixture(action)
... ...