mailconf_controller_test.rb
3.8 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
require_relative "../test_helper"
class MailconfControllerTest < ActionController::TestCase
def setup
@controller = MailconfController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
User.destroy_all
@user = create_user('ze')
MailConf.stubs(:enabled?).returns(true)
MailConf.stubs(:webmail_url).returns('http://web.mail.net/')
end
attr_accessor :user
should 'check if mail is enabled' do
MailConf.expects(:enabled?).returns(false)
login_as('ze')
get :index, :profile => 'ze'
assert_response 500
end
should 'not be used by organizations' do
org = Organization.create!(:name => 'testorg', :identifier => 'testorg')
login_as('ze')
get :index, :profile => 'testorg'
assert_response 403
end
should 'not be edited by others' do
another = create_user('johndoe')
login_as(another.login)
get :index, :profile => 'ze'
assert_response 403
end
should 'be edited by owner' do
login_as('ze')
get :index, :profile => 'ze'
assert_response :success
end
should 'expose user to templates' do
login_as('ze')
get :index, :profile => 'ze'
assert_equal user, assigns(:user)
end
should 'present enable/disable for e-mail use' do
login_as('ze')
get :index, :profile => 'ze'
assert_tag(
:tag => 'a',
:content => 'Enable e-Mail',
:attributes => {:href => '/myprofile/ze/mailconf/enable'}
)
end
should 'display correctly the state false of e-mail enable/disable' do
login_as('ze')
user.update_attributes!(:enable_email => false)
get :index, :profile => 'ze'
assert_tag :tag => 'a', :content => 'Enable e-Mail'
assert_no_tag :tag => 'a', :content => 'Disable e-Mail', :attributes => { :href => '/myprofile/ze/mailconf/disable' }
end
should 'not display www in email address when force_www=true' do
login_as('ze')
env = Environment.default
env.force_www = true
env.save!
get :index, :profile => 'ze'
assert_tag :tag => 'li', :content => /ze@colivre.net/
end
should 'not display www in email address when force_www=false' do
login_as('ze')
env = Environment.default
env.force_www = false
env.save!
get :index, :profile => 'ze'
assert_tag :tag => 'li', :content => /ze@colivre.net/
end
should 'create task to environment admin when enable email' do
login_as('ze')
assert_difference 'EmailActivation.count' do
post :enable, :profile => 'ze'
end
end
should 'save mail enable/disable as false' do
login_as('ze')
assert user.enable_email!
post :disable, :profile => 'ze'
assert !Profile['ze'].user.enable_email
end
should 'go back on save' do
login_as('ze')
post :enable, :profile => 'ze'
assert_redirected_to :controller => 'profile_editor', :action => 'edit'
end
should 'go to profile editor after enable email' do
login_as('ze')
post :enable, :profile => 'ze'
assert_redirected_to :controller => 'profile_editor', :action => 'edit'
end
should 'display notice after saving' do
login_as('ze')
post :enable, :profile => 'ze'
assert_kind_of String, session[:notice]
end
should 'link back to control panel' do
login_as('ze')
get :index, :profile => 'ze'
assert_tag :tag => 'div', :attributes => { :id => 'content'}, :descendant => { :tag => 'a', :attributes => { :href => '/myprofile/ze' } }
end
should 'not display input for enable/disable e-mail when has pending_enable_email' do
login_as('ze')
user.update_attribute(:environment_id, Environment.default.id)
EmailActivation.create!(:requestor => user.person, :target => Environment.default)
get :index, :profile => 'ze'
assert_no_tag :tag => 'input', :attributes => {:name => 'user[enable_email]', :type => 'checkbox'}
end
end