Commit 1d34206ad32eb153b8ac5a153fb50c4be78907e7

Authored by AntonioTerceiro
1 parent f37d4b1e

ActionItem507: making location method more robust in profile

git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2163 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/models/profile.rb
... ... @@ -106,7 +106,12 @@ class Profile < ActiveRecord::Base
106 106 belongs_to :region
107 107  
108 108 def location
109   - self.region.name
  109 + myregion = self.region
  110 + if myregion
  111 + myregion.name
  112 + else
  113 + ''
  114 + end
110 115 end
111 116  
112 117 def pending_categorizations
... ...
test/unit/profile_test.rb
... ... @@ -646,6 +646,19 @@ class ProfileTest < Test::Unit::TestCase
646 646 assert !Profile.new.accept_category?(Region.new)
647 647 end
648 648  
  649 + should 'query region for location' do
  650 + p = Profile.new
  651 + region = mock; region.expects(:name).returns('Some ackwrad region name')
  652 + p.expects(:region).returns(region)
  653 + assert_equal 'Some ackwrad region name', p.location
  654 + end
  655 +
  656 + should 'fallback graciously when no region' do
  657 + p = Profile.new
  658 + p.expects(:region).returns(nil)
  659 + assert_equal '', p.location
  660 + end
  661 +
649 662 private
650 663  
651 664 def assert_invalid_identifier(id)
... ...