Commit 5759d40da9be30a391023f9b2b927241180c5944

Authored by AntonioTerceiro
1 parent 1470780d

ActionItem102: searching for possible validators.



git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@665 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing 2 changed files with 21 additions and 2 deletions   Show diff stats
app/models/region.rb
1 1 # Region is a special type of category that is related to geographical issues.
2 2 class Region < Category
3 3 has_and_belongs_to_many :validators, :class_name => Organization.name, :join_table => :region_validators
  4 +
  5 + def search_possible_validators(search)
  6 + Organization.find_by_contents(search).reject {|item| self.validator_ids.include?(item.id) }
  7 + end
4 8 end
... ...
test/unit/region_test.rb
... ... @@ -17,11 +17,26 @@ class RegionTest &lt; Test::Unit::TestCase
17 17 end
18 18  
19 19 should 'be able to search for possible validators by name' do
20   - flunk 'need to write this test'
  20 + env = Environment.create!(:name => "my test environment")
  21 + region = Region.create!(:environment_id => env.id, :name => 'My Region')
  22 + org1 = Organization.create!(:name => 'Organization 1', :identifier => 'org1', :environment_id => env.id)
  23 + org2 = Organization.create!(:name => 'Organization 2', :identifier => 'org2', :environment_id => env.id)
  24 +
  25 + possible = region.search_possible_validators('organization')
  26 + assert possible.include?(org2)
  27 + assert possible.include?(org1)
21 28 end
22 29  
23 30 should 'return search results without validators that are already associated to the current region' do
24   - flunk 'need to write this test'
  31 + env = Environment.create!(:name => "my test environment")
  32 + region = Region.create!(:environment_id => env.id, :name => 'My Region')
  33 + org1 = Organization.create!(:name => 'Organization 1', :identifier => 'org1', :environment_id => env.id)
  34 + org2 = Organization.create!(:name => 'Organization 2', :identifier => 'org2', :environment_id => env.id)
  35 + region.validators << org1
  36 +
  37 + possible = region.search_possible_validators('organization')
  38 + assert possible.include?(org2)
  39 + assert !possible.include?(org1)
25 40 end
26 41  
27 42 end
... ...