Commit 5413c05611950cc63e390fb314fb5d6a637f0810

Authored by AntonioTerceiro
1 parent df8735d7

ActionItem514: there are other types of regions



git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2207 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/models/profile_categorization.rb
... ... @@ -13,7 +13,7 @@ class ProfileCategorization < ActiveRecord::Base
13 13 end
14 14  
15 15 def self.remove_region(profile)
16   - region = profile.categories.find(:first, :conditions => "type = 'Region'")
  16 + region = profile.categories.find(:first, :conditions => { :type => [Region, State, City].map(&:name) })
17 17 if region
18 18 ids = region.hierarchy.map(&:id)
19 19 self.delete_all(:profile_id => profile.id, :category_id => ids)
... ...
test/unit/profile_categorization_test.rb
... ... @@ -53,4 +53,17 @@ class ProfileCategorizationTest < ActiveSupport::TestCase
53 53 end
54 54 end
55 55  
  56 + [ Region, State, City ].each do |klass|
  57 + should "be able to remove #{klass.name} from profile" do
  58 + region = klass.create!(:name => 'my region', :environment => Environment.default)
  59 + p = create_user('testuser').person
  60 + p.region = region
  61 + p.save!
  62 +
  63 + ProfileCategorization.remove_region(p)
  64 +
  65 + assert_equal [], p.categories(true)
  66 + end
  67 + end
  68 +
56 69 end
... ...