region_test.rb
1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
require File.dirname(__FILE__) + '/../test_helper'
class RegionTest < Test::Unit::TestCase
should 'be a subclass of category' do
assert_equal Category, Region.superclass
end
should 'have an array of validators' do
region = Region.new
assert_raise ActiveRecord::AssociationTypeMismatch do
region.validators = [ 1 ]
end
assert_nothing_raised do
region.validators = [ Organization.new ]
end
end
should 'be able to search for possible validators by name' do
env = Environment.create!(:name => "my test environment")
region = Region.create!(:environment_id => env.id, :name => 'My Region')
org1 = Organization.create!(:name => 'Organization 1', :identifier => 'org1', :environment_id => env.id)
org2 = Organization.create!(:name => 'Organization 2', :identifier => 'org2', :environment_id => env.id)
possible = region.search_possible_validators('organization')
assert possible.include?(org2)
assert possible.include?(org1)
end
should 'return search results without validators that are already associated to the current region' do
env = Environment.create!(:name => "my test environment")
region = Region.create!(:environment_id => env.id, :name => 'My Region')
org1 = Organization.create!(:name => 'Organization 1', :identifier => 'org1', :environment_id => env.id)
org2 = Organization.create!(:name => 'Organization 2', :identifier => 'org2', :environment_id => env.id)
region.validators << org1
possible = region.search_possible_validators('organization')
assert possible.include?(org2)
assert !possible.include?(org1)
end
end