From c091bfbf35937bdd629423e06c9515e806362c8e Mon Sep 17 00:00:00 2001 From: Joenio Costa Date: Wed, 10 Dec 2008 12:06:49 -0300 Subject: [PATCH] ActionItem791: send copy of message to requester --- app/models/contact.rb | 6 +++++- app/views/contact/new.rhtml | 1 + test/functional/contact_controller_test.rb | 5 +++++ test/unit/contact_sender_test.rb | 14 ++++++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/models/contact.rb b/app/models/contact.rb index 9a994d2..437ab67 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -5,7 +5,8 @@ class Contact < ActiveRecord::Base #WithoutTable [:message, :string], [:email, :string], [:state, :string], - [:city, :string] + [:city, :string], + [:receive_a_copy, :boolean] ] attr_accessor :dest @@ -23,6 +24,9 @@ class Contact < ActiveRecord::Base #WithoutTable emails = [contact.dest.contact_email] + contact.dest.admins.map{|i| i.email} recipients emails from "#{contact.name} <#{contact.email}>" + if contact.receive_a_copy + cc "#{contact.name} <#{contact.email}>" + end subject contact.subject body :name => contact.name, :email => contact.email, diff --git a/app/views/contact/new.rhtml b/app/views/contact/new.rhtml index 1db7cbd..79dc4c9 100644 --- a/app/views/contact/new.rhtml +++ b/app/views/contact/new.rhtml @@ -9,6 +9,7 @@ <%= labelled_form_field _('City and state'), select_city(true) %> <%= f.text_field :subject %> <%= f.text_area :message, :rows => 10, :cols => 60 %> + <%= labelled_form_field check_box(:contact, :receive_a_copy) + _('Want to receive a copy of your message in your mailbox?'), '' %> <%= submit_button(:send, _('Send')) %> diff --git a/test/functional/contact_controller_test.rb b/test/functional/contact_controller_test.rb index be51105..c7e2f91 100644 --- a/test/functional/contact_controller_test.rb +++ b/test/functional/contact_controller_test.rb @@ -69,4 +69,9 @@ class ContactControllerTest < Test::Unit::TestCase assert_equal 'Bahia', assigns(:contact).state end + should 'display checkbox for receive copy of email' do + get :new, :profile => enterprise.identifier + assert_tag :tag => 'input', :attributes => {:name => 'contact[receive_a_copy]'} + end + end diff --git a/test/unit/contact_sender_test.rb b/test/unit/contact_sender_test.rb index 7f48fab..0e313f1 100644 --- a/test/unit/contact_sender_test.rb +++ b/test/unit/contact_sender_test.rb @@ -41,6 +41,20 @@ class ContactSenderTest < Test::Unit::TestCase assert_includes response.to, admin.email end + should 'deliver a copy of email if requester wants' do + ent = Enterprise.new(:name => 'my enterprise', :identifier => 'myent', :environment => Environment.default) + c = Contact.new(:dest => ent, :email => 'requester@invalid.com', :receive_a_copy => true) + response = Contact::Sender.deliver_mail(c) + assert_includes response.cc, c.email + end + + should 'not deliver a copy of email if requester dont wants' do + ent = Enterprise.new(:name => 'my enterprise', :identifier => 'myent', :environment => Environment.default) + c = Contact.new(:dest => ent, :email => 'requester@invalid.com', :receive_a_copy => false) + response = Contact::Sender.deliver_mail(c) + assert_nil response.cc + end + private def read_fixture(action) -- libgit2 0.21.2