features_controller_test.rb
2.38 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
require File.dirname(__FILE__) + '/../test_helper'
require 'features_controller'
# Re-raise errors caught by the controller.
class FeaturesController; def rescue_action(e) raise e end; end
class FeaturesControllerTest < Test::Unit::TestCase
fixtures :environments, :domains
def setup
@controller = FeaturesController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
end
def test_listing_features
uses_host 'anhetegua.net'
get :index
assert_template 'index'
Environment.available_features.each do |feature, text|
assert_tag(:tag => 'input', :attributes => { :type => 'checkbox', :name => "environment[enabled_features][]", :value => feature})
end
end
def test_updates_enabled_features
uses_host 'anhetegua.net'
post :update, :environment => { :enabled_features => [ 'feature1', 'feature2' ] }
assert_redirected_to :action => 'index'
assert_kind_of String, flash[:notice]
v = Environment.find(environments(:anhetegua_net).id)
assert v.enabled?('feature2')
assert v.enabled?('feature2')
assert !v.enabled?('feature3')
end
def test_update_disable_all
uses_host 'anhetegua.net'
post :update # no features
assert_redirected_to :action => 'index'
assert_kind_of String, flash[:notice]
v = Environment.find(environments(:anhetegua_net).id)
assert !v.enabled?('feature1')
assert !v.enabled?('feature2')
assert !v.enabled?('feature3')
end
def test_update_no_post
uses_host 'anhetegua.net'
get :update
assert_redirected_to :action => 'index'
end
def test_updates_organization_approval_method
uses_host 'anhetegua.net'
post :update, :environment => { :organization_approval_method => 'region' }
assert_redirected_to :action => 'index'
assert_kind_of String, flash[:notice]
v = Environment.find(environments(:anhetegua_net).id)
assert_equal :region, v.organization_approval_method
end
def test_should_mark_current_organization_approval_method_in_view
uses_host 'anhetegua.net'
Environment.find(environments(:anhetegua_net).id).update_attributes(:organization_approval_method => :region)
post :index
assert_tag :tag => 'select', :attributes => { :name => 'environment[organization_approval_method]' }, :descendant => { :tag => 'option', :attributes => { :value => 'region', :selected => true } }
end
end