diff options
-rw-r--r-- | app/models/outgoing_message.rb | 2 | ||||
-rw-r--r-- | spec/models/outgoing_message_spec.rb | 12 |
2 files changed, 12 insertions, 2 deletions
diff --git a/app/models/outgoing_message.rb b/app/models/outgoing_message.rb index e89c11141..e2ee696c5 100644 --- a/app/models/outgoing_message.rb +++ b/app/models/outgoing_message.rb @@ -271,7 +271,7 @@ class OutgoingMessage < ActiveRecord::Base end def format_of_body - if self.body.empty? || self.body =~ /\A#{get_salutation}\s+#{get_signoff}/ || self.body =~ /#{get_internal_review_insert_here_note}/ + if self.body.empty? || self.body =~ /\A#{Regexp.escape(get_salutation)}\s+#{Regexp.escape(get_signoff)}/ || self.body =~ /#{Regexp.escape(get_internal_review_insert_here_note)}/ if self.message_type == 'followup' if self.what_doing == 'internal_review' errors.add(:body, _("Please give details explaining why you want a review")) diff --git a/spec/models/outgoing_message_spec.rb b/spec/models/outgoing_message_spec.rb index 1e05e09f1..8c000665b 100644 --- a/spec/models/outgoing_message_spec.rb +++ b/spec/models/outgoing_message_spec.rb @@ -144,7 +144,7 @@ describe OutgoingMessage, " when making an outgoing message" do end -describe IncomingMessage, " when censoring data" do +describe OutgoingMessage, " when censoring data" do before do @om = outgoing_messages(:useless_outgoing_message) @@ -163,3 +163,13 @@ describe IncomingMessage, " when censoring data" do @om.body.should match(/fancy cat/) end end + +describe OutgoingMessage, "when validating the format of the message body", :focus => true do + + it 'should handle a salutation with a bracket in it' do + outgoing_message = FactoryGirl.build(:initial_request) + outgoing_message.stub!(:get_salutation).and_return("Dear Bob (Robert,") + lambda{ outgoing_message.valid? }.should_not raise_error(RegexpError) + end + +end |