region_validators_controller_test.rb
3.12 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
require_relative "../test_helper"
require 'region_validators_controller'
class RegionValidatorsControllerTest < ActionController::TestCase
  all_fixtures
  def setup
    @controller = RegionValidatorsController.new
    @request    = ActionController::TestRequest.new
    @response   = ActionController::TestResponse.new
    login_as('ze')
  end
  # Replace this with your real tests.
  should 'list regions at index' do
    get :index
    assert_response :success
    assert_template 'index'
    assert assigns(:regions)
  end
  should 'view validators for a  specific region' do
    environment = fast_create(Environment, :name => "my environment")
    give_permission('ze', 'manage_environment_validators', environment)
    region = Region.new(:name => 'my region')
    environment.regions << region
    refute region.new_record?
    @controller.expects(:environment).returns(environment).at_least_once
    get :region, :id => region.id
    assert_response :success
    assert_template 'region'
    assert_equal region, assigns(:region)
  end
  should 'search possible validators by name' do
    environment = fast_create(Environment, :name => "my environment")
    give_permission('ze', 'manage_environment_validators', environment)
    region = Region.new(:name => 'my region')
    environment.regions << region
    refute region.new_record?
    org = create(Organization, :name => "My frufru organization", :identifier => 'frufru', :environment_id => environment.id)
    @controller.expects(:environment).returns(environment).at_least_once
    get :search, :id => region.id, :search => 'frufru'
    assert_response :success
    assert_equal [org], assigns(:search)
  end
  should 'be able to add validators to the current region' do
    environment = fast_create(Environment, :name => "my environment")
    give_permission('ze', 'manage_environment_validators', environment)
    region = Region.new(:name => 'my region')
    environment.regions << region
    refute region.new_record?
    org = create(Organization, :name => "My frufru organization", :identifier => 'frufru', :environment_id => environment.id)
    @controller.expects(:environment).returns(environment).at_least_once
    post :add, :id => region.id, :validator_id => org.id
    assert_response :redirect
    assert_redirected_to :action => 'region', :id => region.id
    assert Region.find(region.id).validators.include?(org)
  end
  should 'be able to remove validators from the current region' do
    environment = fast_create(Environment, :name => "my environment")
    give_permission('ze', 'manage_environment_validators', environment)
    region = Region.new(:name => 'my region')
    environment.regions << region
    refute region.new_record?
    org = create(Organization, :name => "My frufru organization", :identifier => 'frufru', :environment_id => environment.id)
    region.validators << org
    @controller.expects(:environment).returns(environment).at_least_once
    post :remove, :id => region.id, :validator_id => org.id
    assert_response :redirect
    assert_redirected_to :action => 'region', :id => region.id
    refute Region.find(region.id).validators.include?(org)
  end
end