From 1ee26ba69d21f3897d277a6fb96d6d31bb3147c3 Mon Sep 17 00:00:00 2001 From: Daniela Soares Feitosa Date: Mon, 15 Dec 2008 18:23:43 -0300 Subject: [PATCH] ActionItem833: fixing: not display variables on footer when it is blank --- app/models/profile.rb | 4 ++-- test/unit/profile_test.rb | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/profile.rb b/app/models/profile.rb index ef636e4..6fa6301 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -469,9 +469,9 @@ class Profile < ActiveRecord::Base def custom_footer footer = self[:custom_footer] || environment.custom_footer if footer - %w[contact_person contact_email contact_phone location address economic_activity].each do |att| + %w[contact_person contact_email contact_phone location address economic_activity city state country zip_code].each do |att| if self.respond_to?(att) && footer.match(/\{[^{]*#{att}\}/) - if !self.send(att).nil? + if !self.send(att).nil? && !self.send(att).blank? footer = footer.gsub(/\{([^{]*)#{att}\}/, '\1' + self.send(att)) else footer = footer.gsub(/\{[^}]*#{att}\}/, '') diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index 7e6df8a..e4b50d7 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -791,6 +791,10 @@ class ProfileTest < Test::Unit::TestCase assert_equal '', Profile.new(:custom_footer => '{address}').custom_footer end + should 'replace variables on custom_footer when it is blank' do + assert_equal '', Enterprise.new(:custom_footer => '{ZIP Code: zip_code}', :zip_code => '').custom_footer + end + should 'replace variables in custom_footer when more than one' do assert_equal 'Phone: 9999999', Profile.new(:custom_footer => '{Address: address}{Phone: contact_phone}', :contact_phone => '9999999').custom_footer end -- libgit2 0.21.2