mailconf_controller_test.rb
3.73 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
require File.dirname(__FILE__) + '/../test_helper'
class MailconfControllerTest < Test::Unit::TestCase
all_fixtures
def setup
@controller = MailconfController.new
@request = ActionController::TestRequest.new
@request.stubs(:ssl?).returns(true)
@response = ActionController::TestResponse.new
MailConf.stubs(:enabled?).returns(true)
MailConf.stubs(:webmail_url).returns('http://web.mail.net/')
end
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')
get :index, :profile => 'testorg'
assert_response 403
end
should 'not be edited by others' do
login_as('johndoe')
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 users(:ze), assigns(:user)
end
should 'present enable/disable for e-mail use' do
login_as('ze')
get :index, :profile => 'ze'
assert_tag(
:tag => 'form',
:attributes => { :action => '/myprofile/ze/mailconf/save'},
:descendant => {
:tag => 'input',
:attributes => { :name => 'user[enable_email]', :type => 'checkbox' }
}
)
end
should 'display correctly the state true of e-mail enable/disable' do
login_as('ze')
users(:ze).update_attributes!(:enable_email => true)
get :index, :profile => 'ze'
assert_tag :tag => 'input', :attributes => { :name => 'user[enable_email]', :type => 'checkbox', :value => '1', :checked => 'checked' }
end
should 'display correctly the state false of e-mail enable/disable' do
login_as('ze')
users(:ze).update_attributes!(:enable_email => false)
get :index, :profile => 'ze'
assert_no_tag :tag => 'input', :attributes => { :name => 'user[enable_email]', :type => 'checkbox', :value => '1', :checked => 'checked' }
assert_tag :tag => 'input', :attributes => { :name => 'user[enable_email]', :type => 'hidden', :value => '0' }
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 => 'label', :attributes => { :for => 'user_enable_email' }, :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 => 'label', :attributes => { :for => 'user_enable_email' }, :content => /ze@colivre.net/
end
should 'save mail enable/disable as true' do
login_as('ze')
post :save, :profile => 'ze', :user => { :enable_email => '1' }
assert Profile['ze'].user.enable_email
end
should 'save mail enable/disable as false' do
login_as('ze')
post :save, :profile => 'ze', :user => { :enable_email => '0' }
assert !Profile['ze'].user.enable_email
end
should 'go back on save' do
login_as('ze')
post :save, :profile => 'ze'
assert_redirected_to :action => 'index'
end
should 'display notice after saving' do
login_as('ze')
post :save, :profile => 'ze'
assert_kind_of String, flash[: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
end