Commit c091bfbf35937bdd629423e06c9515e806362c8e
Committed by
Antonio Terceiro
1 parent
f3f04a53
Exists in
master
and in
29 other branches
ActionItem791: send copy of message to requester
Showing
4 changed files
with
25 additions
and
1 deletions
Show diff stats
app/models/contact.rb
@@ -5,7 +5,8 @@ class Contact < ActiveRecord::Base #WithoutTable | @@ -5,7 +5,8 @@ class Contact < ActiveRecord::Base #WithoutTable | ||
5 | [:message, :string], | 5 | [:message, :string], |
6 | [:email, :string], | 6 | [:email, :string], |
7 | [:state, :string], | 7 | [:state, :string], |
8 | - [:city, :string] | 8 | + [:city, :string], |
9 | + [:receive_a_copy, :boolean] | ||
9 | ] | 10 | ] |
10 | attr_accessor :dest | 11 | attr_accessor :dest |
11 | 12 | ||
@@ -23,6 +24,9 @@ class Contact < ActiveRecord::Base #WithoutTable | @@ -23,6 +24,9 @@ class Contact < ActiveRecord::Base #WithoutTable | ||
23 | emails = [contact.dest.contact_email] + contact.dest.admins.map{|i| i.email} | 24 | emails = [contact.dest.contact_email] + contact.dest.admins.map{|i| i.email} |
24 | recipients emails | 25 | recipients emails |
25 | from "#{contact.name} <#{contact.email}>" | 26 | from "#{contact.name} <#{contact.email}>" |
27 | + if contact.receive_a_copy | ||
28 | + cc "#{contact.name} <#{contact.email}>" | ||
29 | + end | ||
26 | subject contact.subject | 30 | subject contact.subject |
27 | body :name => contact.name, | 31 | body :name => contact.name, |
28 | :email => contact.email, | 32 | :email => contact.email, |
app/views/contact/new.rhtml
@@ -9,6 +9,7 @@ | @@ -9,6 +9,7 @@ | ||
9 | <%= labelled_form_field _('City and state'), select_city(true) %> | 9 | <%= labelled_form_field _('City and state'), select_city(true) %> |
10 | <%= f.text_field :subject %> | 10 | <%= f.text_field :subject %> |
11 | <%= f.text_area :message, :rows => 10, :cols => 60 %> | 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 | <%= submit_button(:send, _('Send')) %> | 14 | <%= submit_button(:send, _('Send')) %> |
14 | 15 |
test/functional/contact_controller_test.rb
@@ -69,4 +69,9 @@ class ContactControllerTest < Test::Unit::TestCase | @@ -69,4 +69,9 @@ class ContactControllerTest < Test::Unit::TestCase | ||
69 | assert_equal 'Bahia', assigns(:contact).state | 69 | assert_equal 'Bahia', assigns(:contact).state |
70 | end | 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 | end | 77 | end |
test/unit/contact_sender_test.rb
@@ -41,6 +41,20 @@ class ContactSenderTest < Test::Unit::TestCase | @@ -41,6 +41,20 @@ class ContactSenderTest < Test::Unit::TestCase | ||
41 | assert_includes response.to, admin.email | 41 | assert_includes response.to, admin.email |
42 | end | 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 | private | 58 | private |
45 | 59 | ||
46 | def read_fixture(action) | 60 | def read_fixture(action) |