Commit 9f30e9832974979ef70f80503e05833cf363a4f9

Authored by AntonioTerceiro
1 parent 9f909540

ActionItem102: wrote missing functional tests



git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@668 3f533792-8f58-4932-b0fe-aaf55b0a4547
test/functional/region_validators_controller_test.rb
... ... @@ -39,10 +39,9 @@ class RegionValidatorsControllerTest < Test::Unit::TestCase
39 39 region = Region.new(:name => 'my region')
40 40 environment.regions << region
41 41 assert !region.new_record?
42   - org = Organization.create!(:name => "My frufru organization", :identifier => 'frufru')
  42 + org = Organization.create!(:name => "My frufru organization", :identifier => 'frufru', :environment_id => environment.id)
43 43  
44 44 @controller.expects(:environment).returns(environment)
45   - Organization.expects(:find_by_contents).with('frufru').returns([org])
46 45  
47 46 get :search, :id => region.id, :search => 'frufru'
48 47  
... ... @@ -51,11 +50,36 @@ class RegionValidatorsControllerTest &lt; Test::Unit::TestCase
51 50 end
52 51  
53 52 should 'be able to add validators to the current region' do
54   - flunk 'need to write this test'
  53 + environment = Environment.create!(:name => "my environment")
  54 + region = Region.new(:name => 'my region')
  55 + environment.regions << region
  56 + assert !region.new_record?
  57 + org = Organization.create!(:name => "My frufru organization", :identifier => 'frufru', :environment_id => environment.id)
  58 +
  59 + @controller.expects(:environment).returns(environment).at_least_once
  60 +
  61 + post :add, :id => region.id, :validator_id => org.id
  62 + assert_response :redirect
  63 + assert_redirected_to :action => 'region', :id => region.id
  64 +
  65 + assert Region.find(region.id).validators.include?(org)
55 66 end
56 67  
57 68 should 'be able to remove validators from the current region' do
58   - flunk 'need to write this test'
  69 + environment = Environment.create!(:name => "my environment")
  70 + region = Region.new(:name => 'my region')
  71 + environment.regions << region
  72 + assert !region.new_record?
  73 + org = Organization.create!(:name => "My frufru organization", :identifier => 'frufru', :environment_id => environment.id)
  74 + region.validators << org
  75 +
  76 + @controller.expects(:environment).returns(environment).at_least_once
  77 +
  78 + post :remove, :id => region.id, :validator_id => org.id
  79 + assert_response :redirect
  80 + assert_redirected_to :action => 'region', :id => region.id
  81 +
  82 + assert !Region.find(region.id).validators.include?(org)
59 83 end
60 84  
61 85 end
... ...