Commit ba9deb07a614068c4c75d0c01c70eb5f9bb89e40
1 parent
c692f7b2
Exists in
master
and in
29 other branches
ActionItem833: going up only 2 levels when using region
Showing
2 changed files
with
4 additions
and
3 deletions
Show diff stats
app/models/profile.rb
... | ... | @@ -113,7 +113,7 @@ class Profile < ActiveRecord::Base |
113 | 113 | def location |
114 | 114 | myregion = self.region |
115 | 115 | if myregion |
116 | - myregion.hierarchy.reverse.map(&:name).join(' - ') | |
116 | + myregion.hierarchy.reverse.first(2).map(&:name).join(' - ') | |
117 | 117 | else |
118 | 118 | [ :city, :state, :country ].map {|item| self.respond_to?(item) ? self.send(item) : nil }.compact.join(' - ') |
119 | 119 | end | ... | ... |
test/unit/profile_test.rb
... | ... | @@ -702,8 +702,9 @@ class ProfileTest < Test::Unit::TestCase |
702 | 702 | assert_equal 'Some ackwrad region name', p.location |
703 | 703 | end |
704 | 704 | |
705 | - should 'query region hierarchy for location' do | |
706 | - state = Region.new(:name => "Bahia") | |
705 | + should 'query region hierarchy for location up to 2 levels' do | |
706 | + country = Region.new(:name => "Brazil") | |
707 | + state = Region.new(:name => "Bahia", :parent => country) | |
707 | 708 | city = Region.new(:name => "Salvador", :parent => state) |
708 | 709 | p = Profile.new(:region => city) |
709 | 710 | assert_equal 'Salvador - Bahia', p.location | ... | ... |