Commit ba9deb07a614068c4c75d0c01c70eb5f9bb89e40

Authored by Antonio Terceiro
1 parent c692f7b2

ActionItem833: going up only 2 levels when using region

app/models/profile.rb
@@ -113,7 +113,7 @@ class Profile < ActiveRecord::Base @@ -113,7 +113,7 @@ class Profile < ActiveRecord::Base
113 def location 113 def location
114 myregion = self.region 114 myregion = self.region
115 if myregion 115 if myregion
116 - myregion.hierarchy.reverse.map(&:name).join(' - ') 116 + myregion.hierarchy.reverse.first(2).map(&:name).join(' - ')
117 else 117 else
118 [ :city, :state, :country ].map {|item| self.respond_to?(item) ? self.send(item) : nil }.compact.join(' - ') 118 [ :city, :state, :country ].map {|item| self.respond_to?(item) ? self.send(item) : nil }.compact.join(' - ')
119 end 119 end
test/unit/profile_test.rb
@@ -702,8 +702,9 @@ class ProfileTest < Test::Unit::TestCase @@ -702,8 +702,9 @@ class ProfileTest < Test::Unit::TestCase
702 assert_equal 'Some ackwrad region name', p.location 702 assert_equal 'Some ackwrad region name', p.location
703 end 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 city = Region.new(:name => "Salvador", :parent => state) 708 city = Region.new(:name => "Salvador", :parent => state)
708 p = Profile.new(:region => city) 709 p = Profile.new(:region => city)
709 assert_equal 'Salvador - Bahia', p.location 710 assert_equal 'Salvador - Bahia', p.location