diff --git a/app/models/profile.rb b/app/models/profile.rb index 884101c..91d87a3 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -106,7 +106,12 @@ class Profile < ActiveRecord::Base belongs_to :region def location - self.region.name + myregion = self.region + if myregion + myregion.name + else + '' + end end def pending_categorizations diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index 528e6b0..bfb512a 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -646,6 +646,19 @@ class ProfileTest < Test::Unit::TestCase assert !Profile.new.accept_category?(Region.new) 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) + assert_equal 'Some ackwrad region name', p.location + end + + should 'fallback graciously when no region' do + p = Profile.new + p.expects(:region).returns(nil) + assert_equal '', p.location + end + private def assert_invalid_identifier(id) -- libgit2 0.21.2