Commit 35fba7896b88651d2d7ff85ca1f8e3546ea819b9
Committed by
Antonio Terceiro
1 parent
275fdc75
Exists in
master
and in
29 other branches
ActionItem866: fix: don't expand variables when editing header/footer
Showing
4 changed files
with
30 additions
and
13 deletions
Show diff stats
app/helpers/boxes_helper.rb
... | ... | @@ -23,9 +23,9 @@ module BoxesHelper |
23 | 23 | content = boxes.reverse.map { |item| display_box(item, main_content) }.join("\n") |
24 | 24 | content = main_content if (content.blank?) |
25 | 25 | |
26 | - maybe_display_custom_element(holder, :custom_header, :id => 'profile-header') + | |
26 | + maybe_display_custom_element(holder, :custom_header_expanded, :id => 'profile-header') + | |
27 | 27 | content_tag('div', content, :class => 'boxes', :id => 'boxes' ) + |
28 | - maybe_display_custom_element(holder, :custom_footer, :id => 'profile-footer') | |
28 | + maybe_display_custom_element(holder, :custom_footer_expanded, :id => 'profile-footer') | |
29 | 29 | end |
30 | 30 | |
31 | 31 | def maybe_display_custom_element(holder, element, options = {}) | ... | ... |
app/models/profile.rb
... | ... | @@ -461,6 +461,10 @@ class Profile < ActiveRecord::Base |
461 | 461 | end |
462 | 462 | |
463 | 463 | def custom_header |
464 | + self[:custom_header] || environment.custom_header | |
465 | + end | |
466 | + | |
467 | + def custom_header_expanded | |
464 | 468 | header = self[:custom_header] || environment.custom_header |
465 | 469 | if header |
466 | 470 | if self.respond_to?(:name) && header.include?('{name}') |
... | ... | @@ -472,6 +476,10 @@ class Profile < ActiveRecord::Base |
472 | 476 | end |
473 | 477 | |
474 | 478 | def custom_footer |
479 | + self[:custom_footer] || environment.custom_footer | |
480 | + end | |
481 | + | |
482 | + def custom_footer_expanded | |
475 | 483 | footer = self[:custom_footer] || environment.custom_footer |
476 | 484 | if footer |
477 | 485 | %w[contact_person contact_email contact_phone location address economic_activity city state country zip_code].each do |att| | ... | ... |
test/unit/boxes_helper_test.rb
... | ... | @@ -9,7 +9,7 @@ class BoxesHelperTest < Test::Unit::TestCase |
9 | 9 | holder = mock |
10 | 10 | holder.stubs(:boxes).returns([]) |
11 | 11 | holder.stubs(:boxes_limit).returns(0) |
12 | - holder.stubs(:custom_header).returns('my custom header') | |
12 | + holder.stubs(:custom_header_expanded).returns('my custom header') | |
13 | 13 | |
14 | 14 | assert_tag_in_string display_boxes(holder, 'main content'), :tag => "div", :attributes => { :id => 'profile-header' }, :content => 'my custom header' |
15 | 15 | end |
... | ... | @@ -18,7 +18,7 @@ class BoxesHelperTest < Test::Unit::TestCase |
18 | 18 | holder = mock |
19 | 19 | holder.stubs(:boxes).returns([]) |
20 | 20 | holder.stubs(:boxes_limit).returns(0) |
21 | - holder.stubs(:custom_footer).returns('my custom footer') | |
21 | + holder.stubs(:custom_footer_expanded).returns('my custom footer') | |
22 | 22 | |
23 | 23 | assert_tag_in_string display_boxes(holder, 'main content'), :tag => "div", :attributes => { :id => 'profile-footer' }, :content => 'my custom footer' |
24 | 24 | end | ... | ... |
test/unit/profile_test.rb
... | ... | @@ -768,7 +768,8 @@ class ProfileTest < Test::Unit::TestCase |
768 | 768 | end |
769 | 769 | |
770 | 770 | should 'provide custom header with variables' do |
771 | - assert_equal 'Custom header of Test', Profile.new(:custom_header => 'Custom header of {name}', :name => 'Test').custom_header | |
771 | + assert_equal 'Custom header of {name}', Profile.new(:custom_header => 'Custom header of {name}', :name => 'Test').custom_header | |
772 | + assert_equal 'Custom header of Test', Profile.new(:custom_header => 'Custom header of {name}', :name => 'Test').custom_header_expanded | |
772 | 773 | end |
773 | 774 | |
774 | 775 | should 'provide custom footer' do |
... | ... | @@ -780,27 +781,33 @@ class ProfileTest < Test::Unit::TestCase |
780 | 781 | end |
781 | 782 | |
782 | 783 | should 'replace variables on custom_footer' do |
783 | - assert_equal 'Address for test', Profile.new(:custom_footer => '{address}', :address => 'Address for test').custom_footer | |
784 | + assert_equal '{address}', Profile.new(:custom_footer => '{address}', :address => 'Address for test').custom_footer | |
785 | + assert_equal 'Address for test', Profile.new(:custom_footer => '{address}', :address => 'Address for test').custom_footer_expanded | |
784 | 786 | end |
785 | 787 | |
786 | 788 | should 'replace variables on custom_footer with title' do |
787 | - assert_equal 'Address: Address for test', Profile.new(:custom_footer => '{Address: address}', :address => 'Address for test').custom_footer | |
789 | + assert_equal '{Address: address}', Profile.new(:custom_footer => '{Address: address}', :address => 'Address for test').custom_footer | |
790 | + assert_equal 'Address: Address for test', Profile.new(:custom_footer => '{Address: address}', :address => 'Address for test').custom_footer_expanded | |
788 | 791 | end |
789 | 792 | |
790 | 793 | should 'replace variables on custom_footer when it is nil' do |
791 | - assert_equal '', Profile.new(:custom_footer => '{address}').custom_footer | |
794 | + assert_equal '{address}', Profile.new(:custom_footer => '{address}').custom_footer | |
795 | + assert_equal '', Profile.new(:custom_footer => '{address}').custom_footer_expanded | |
792 | 796 | end |
793 | 797 | |
794 | 798 | 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 | |
799 | + assert_equal '{ZIP Code: zip_code}', Enterprise.new(:custom_footer => '{ZIP Code: zip_code}', :zip_code => '').custom_footer | |
800 | + assert_equal '', Enterprise.new(:custom_footer => '{ZIP Code: zip_code}', :zip_code => '').custom_footer_expanded | |
796 | 801 | end |
797 | 802 | |
798 | 803 | should 'replace variables in custom_footer when more than one' do |
799 | - assert_equal 'Phone: 9999999', Profile.new(:custom_footer => '{Address: address}{Phone: contact_phone}', :contact_phone => '9999999').custom_footer | |
804 | + assert_equal '{Address: address}{Phone: contact_phone}', Profile.new(:custom_footer => '{Address: address}{Phone: contact_phone}', :contact_phone => '9999999').custom_footer | |
805 | + assert_equal 'Phone: 9999999', Profile.new(:custom_footer => '{Address: address}{Phone: contact_phone}', :contact_phone => '9999999').custom_footer_expanded | |
800 | 806 | end |
801 | 807 | |
802 | 808 | should 'replace variables on custom_footer with title when it is nil' do |
803 | - assert_equal '', Profile.new(:custom_footer => '{Address: address}').custom_footer | |
809 | + assert_equal '{Address: address}', Profile.new(:custom_footer => '{Address: address}').custom_footer | |
810 | + assert_equal '', Profile.new(:custom_footer => '{Address: address}').custom_footer_expanded | |
804 | 811 | end |
805 | 812 | |
806 | 813 | should 'provide environment header if profile header is blank' do |
... | ... | @@ -991,7 +998,8 @@ class ProfileTest < Test::Unit::TestCase |
991 | 998 | p.apply_template(template) |
992 | 999 | |
993 | 1000 | assert_equal '{name}', p[:custom_header] |
994 | - assert_equal 'test prof', p.custom_header | |
1001 | + assert_equal '{name}', p.custom_header | |
1002 | + assert_equal 'test prof', p.custom_header_expanded | |
995 | 1003 | end |
996 | 1004 | |
997 | 1005 | should 'copy footer when applying template' do |
... | ... | @@ -1003,7 +1011,8 @@ class ProfileTest < Test::Unit::TestCase |
1003 | 1011 | p.apply_template(template) |
1004 | 1012 | |
1005 | 1013 | assert_equal '{address}', p[:custom_footer] |
1006 | - assert_equal 'Profile address', p.custom_footer | |
1014 | + assert_equal '{address}', p.custom_footer | |
1015 | + assert_equal 'Profile address', p.custom_footer_expanded | |
1007 | 1016 | end |
1008 | 1017 | |
1009 | 1018 | should 'copy homepage when applying template' do | ... | ... |