Commit 9d5ea852c79ee89c3848139b48cf8a9920633024
1 parent
d7698aae
Exists in
master
and in
28 other branches
ActionItem862: workaround for location issue
Showing
3 changed files
with
28 additions
and
7 deletions
Show diff stats
app/models/profile.rb
| ... | ... | @@ -113,9 +113,9 @@ class Profile < ActiveRecord::Base |
| 113 | 113 | def location |
| 114 | 114 | myregion = self.region |
| 115 | 115 | if myregion |
| 116 | - myregion.name | |
| 116 | + myregion.hierarchy.reverse.map(&:name).join(' - ') | |
| 117 | 117 | else |
| 118 | - '' | |
| 118 | + [ :city, :state, :country ].map {|item| self.respond_to?(item) ? self.send(item) : nil }.compact.join(' - ') | |
| 119 | 119 | end |
| 120 | 120 | end |
| 121 | 121 | ... | ... |
script/release-v0.13.0-ecosol
| ... | ... | @@ -21,7 +21,7 @@ script/runner 'env = Environment.default; |
| 21 | 21 | echo 'Configurating template for active enterprises..' |
| 22 | 22 | script/runner 'env = Environment.default |
| 23 | 23 | template = env.enterprise_template |
| 24 | - template.custom_footer = "<div align=center>{address} {- zip_code}<br/>{city} {- state} {- country}<br/>{<strong>Tel:</strong> contact_phone} {<strong>e-Mail:</strong> contact_email}<br/></div>" | |
| 24 | + template.custom_footer = "<div align=center>{address} {- zip_code}<br/>{location}<br/>{<strong>Tel:</strong> contact_phone} {<strong>e-Mail:</strong> contact_email}<br/></div>" | |
| 25 | 25 | template.custom_header = "<div align=center><h1>{name}</h1><br/></div>" |
| 26 | 26 | template.articles.destroy_all |
| 27 | 27 | homepage = TinyMceArticle.create!(:name => "Início", :body => "Esta é a página inicial do seu empreendimento", :profile => template, :accept_comments => false) | ... | ... |
test/unit/profile_test.rb
| ... | ... | @@ -697,18 +697,39 @@ class ProfileTest < Test::Unit::TestCase |
| 697 | 697 | end |
| 698 | 698 | |
| 699 | 699 | should 'query region for location' do |
| 700 | - p = Profile.new | |
| 701 | - region = mock; region.expects(:name).returns('Some ackwrad region name') | |
| 702 | - p.expects(:region).returns(region) | |
| 700 | + region = Region.new(:name => 'Some ackwrad region name') | |
| 701 | + p = Profile.new(:region => region) | |
| 703 | 702 | assert_equal 'Some ackwrad region name', p.location |
| 704 | 703 | end |
| 705 | 704 | |
| 706 | - should 'fallback graciously when no region' do | |
| 705 | + should 'query region hierarchy for location' do | |
| 706 | + state = Region.new(:name => "Bahia") | |
| 707 | + city = Region.new(:name => "Salvador", :parent => state) | |
| 708 | + p = Profile.new(:region => city) | |
| 709 | + assert_equal 'Salvador - Bahia', p.location | |
| 710 | + end | |
| 711 | + | |
| 712 | + should 'use city/state/country fields for location when no region object is set' do | |
| 713 | + p = Profile.new | |
| 714 | + p.expects(:region).returns(nil) | |
| 715 | + p.expects(:city).returns("Salvador") | |
| 716 | + p.expects(:state).returns("Bahia") | |
| 717 | + p.expects(:country).returns("Brasil") | |
| 718 | + assert_equal 'Salvador - Bahia - Brasil', p.location | |
| 719 | + end | |
| 720 | + | |
| 721 | + should 'give empty location if nothing is available' do | |
| 707 | 722 | p = Profile.new |
| 708 | 723 | p.expects(:region).returns(nil) |
| 709 | 724 | assert_equal '', p.location |
| 710 | 725 | end |
| 711 | 726 | |
| 727 | + should 'support (or at least not crash) location for existing profile types' do | |
| 728 | + assert_nothing_raised do | |
| 729 | + [Profile,Enterprise,Person,Community,Organization].each { |p| p.new.location } | |
| 730 | + end | |
| 731 | + end | |
| 732 | + | |
| 712 | 733 | should 'default home page is a TinyMceArticle' do |
| 713 | 734 | profile = Profile.create!(:identifier => 'newprofile', :name => 'New Profile') |
| 714 | 735 | assert_kind_of TinyMceArticle, profile.home_page | ... | ... |