Commit 1d34206ad32eb153b8ac5a153fb50c4be78907e7
1 parent
f37d4b1e
Exists in
master
and in
23 other branches
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
Showing
2 changed files
with
19 additions
and
1 deletions
Show diff stats
app/models/profile.rb
| @@ -106,7 +106,12 @@ class Profile < ActiveRecord::Base | @@ -106,7 +106,12 @@ class Profile < ActiveRecord::Base | ||
| 106 | belongs_to :region | 106 | belongs_to :region |
| 107 | 107 | ||
| 108 | def location | 108 | def location |
| 109 | - self.region.name | 109 | + myregion = self.region |
| 110 | + if myregion | ||
| 111 | + myregion.name | ||
| 112 | + else | ||
| 113 | + '' | ||
| 114 | + end | ||
| 110 | end | 115 | end |
| 111 | 116 | ||
| 112 | def pending_categorizations | 117 | def pending_categorizations |
test/unit/profile_test.rb
| @@ -646,6 +646,19 @@ class ProfileTest < Test::Unit::TestCase | @@ -646,6 +646,19 @@ class ProfileTest < Test::Unit::TestCase | ||
| 646 | assert !Profile.new.accept_category?(Region.new) | 646 | assert !Profile.new.accept_category?(Region.new) |
| 647 | end | 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 | private | 662 | private |
| 650 | 663 | ||
| 651 | def assert_invalid_identifier(id) | 664 | def assert_invalid_identifier(id) |