Commit 1ee26ba69d21f3897d277a6fb96d6d31bb3147c3

Authored by Daniela Feitosa
1 parent e46180a8

ActionItem833: fixing: not display variables on footer when it is blank

app/models/profile.rb
... ... @@ -469,9 +469,9 @@ class Profile < ActiveRecord::Base
469 469 def custom_footer
470 470 footer = self[:custom_footer] || environment.custom_footer
471 471 if footer
472   - %w[contact_person contact_email contact_phone location address economic_activity].each do |att|
  472 + %w[contact_person contact_email contact_phone location address economic_activity city state country zip_code].each do |att|
473 473 if self.respond_to?(att) && footer.match(/\{[^{]*#{att}\}/)
474   - if !self.send(att).nil?
  474 + if !self.send(att).nil? && !self.send(att).blank?
475 475 footer = footer.gsub(/\{([^{]*)#{att}\}/, '\1' + self.send(att))
476 476 else
477 477 footer = footer.gsub(/\{[^}]*#{att}\}/, '')
... ...
test/unit/profile_test.rb
... ... @@ -791,6 +791,10 @@ class ProfileTest < Test::Unit::TestCase
791 791 assert_equal '', Profile.new(:custom_footer => '{address}').custom_footer
792 792 end
793 793  
  794 + should 'replace variables on custom_footer when it is blank' do
  795 + assert_equal '', Enterprise.new(:custom_footer => '{ZIP Code: zip_code}', :zip_code => '').custom_footer
  796 + end
  797 +
794 798 should 'replace variables in custom_footer when more than one' do
795 799 assert_equal 'Phone: 9999999', Profile.new(:custom_footer => '{Address: address}{Phone: contact_phone}', :contact_phone => '9999999').custom_footer
796 800 end
... ...