From 9d5ea852c79ee89c3848139b48cf8a9920633024 Mon Sep 17 00:00:00 2001 From: Antonio Terceiro Date: Tue, 6 Jan 2009 14:47:35 -0300 Subject: [PATCH] ActionItem862: workaround for location issue --- app/models/profile.rb | 4 ++-- script/release-v0.13.0-ecosol | 2 +- test/unit/profile_test.rb | 29 +++++++++++++++++++++++++---- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/app/models/profile.rb b/app/models/profile.rb index 1aab0e0..d865fc8 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -113,9 +113,9 @@ class Profile < ActiveRecord::Base def location myregion = self.region if myregion - myregion.name + myregion.hierarchy.reverse.map(&:name).join(' - ') else - '' + [ :city, :state, :country ].map {|item| self.respond_to?(item) ? self.send(item) : nil }.compact.join(' - ') end end diff --git a/script/release-v0.13.0-ecosol b/script/release-v0.13.0-ecosol index 117559a..7d85430 100755 --- a/script/release-v0.13.0-ecosol +++ b/script/release-v0.13.0-ecosol @@ -21,7 +21,7 @@ script/runner 'env = Environment.default; echo 'Configurating template for active enterprises..' script/runner 'env = Environment.default template = env.enterprise_template - template.custom_footer = "
{address} {- zip_code}
{city} {- state} {- country}
{Tel: contact_phone} {e-Mail: contact_email}
" + template.custom_footer = "
{address} {- zip_code}
{location}
{Tel: contact_phone} {e-Mail: contact_email}
" template.custom_header = "

{name}


" template.articles.destroy_all homepage = TinyMceArticle.create!(:name => "Início", :body => "Esta é a página inicial do seu empreendimento", :profile => template, :accept_comments => false) diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index 97e3f31..6cf5d82 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -697,18 +697,39 @@ class ProfileTest < Test::Unit::TestCase end should 'query region for location' do - p = Profile.new - region = mock; region.expects(:name).returns('Some ackwrad region name') - p.expects(:region).returns(region) + region = Region.new(:name => 'Some ackwrad region name') + p = Profile.new(:region => region) assert_equal 'Some ackwrad region name', p.location end - should 'fallback graciously when no region' do + should 'query region hierarchy for location' do + state = Region.new(:name => "Bahia") + city = Region.new(:name => "Salvador", :parent => state) + p = Profile.new(:region => city) + assert_equal 'Salvador - Bahia', p.location + end + + should 'use city/state/country fields for location when no region object is set' do + p = Profile.new + p.expects(:region).returns(nil) + p.expects(:city).returns("Salvador") + p.expects(:state).returns("Bahia") + p.expects(:country).returns("Brasil") + assert_equal 'Salvador - Bahia - Brasil', p.location + end + + should 'give empty location if nothing is available' do p = Profile.new p.expects(:region).returns(nil) assert_equal '', p.location end + should 'support (or at least not crash) location for existing profile types' do + assert_nothing_raised do + [Profile,Enterprise,Person,Community,Organization].each { |p| p.new.location } + end + end + should 'default home page is a TinyMceArticle' do profile = Profile.create!(:identifier => 'newprofile', :name => 'New Profile') assert_kind_of TinyMceArticle, profile.home_page -- libgit2 0.21.2