diff --git a/app/models/profile.rb b/app/models/profile.rb index 1a84841..530911d 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -113,7 +113,7 @@ class Profile < ActiveRecord::Base def location myregion = self.region if myregion - myregion.hierarchy.reverse.map(&:name).join(' - ') + myregion.hierarchy.reverse.first(2).map(&:name).join(' - ') else [ :city, :state, :country ].map {|item| self.respond_to?(item) ? self.send(item) : nil }.compact.join(' - ') end diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index 657ec73..8f513b1 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -702,8 +702,9 @@ class ProfileTest < Test::Unit::TestCase assert_equal 'Some ackwrad region name', p.location end - should 'query region hierarchy for location' do - state = Region.new(:name => "Bahia") + should 'query region hierarchy for location up to 2 levels' do + country = Region.new(:name => "Brazil") + state = Region.new(:name => "Bahia", :parent => country) city = Region.new(:name => "Salvador", :parent => state) p = Profile.new(:region => city) assert_equal 'Salvador - Bahia', p.location -- libgit2 0.21.2