chat_controller_test.rb
2.93 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
require File.dirname(__FILE__) + '/../test_helper'
class ChatControllerTest < ActionController::TestCase
def setup
env = Environment.default
env.enable('xmpp_chat')
env.save!
@person = create_user('testuser').person
end
# should 'cant view chat when not logged in' do
# get :index
# assert_response 302
# end
# should 'can view chat when logged in' do
# login_as 'testuser'
#
# get :index
# assert_response :success
# end
should 'get default avatar' do
login_as 'testuser'
get :avatar, :id => 'testuser'
assert_response :redirect
end
should 'get avatar from community' do
community = fast_create(Community)
login_as 'testuser'
get :avatar, :id => community.identifier
assert_equal 'image/png', @response.content_type
assert @response.body.index('PNG')
end
# should 'auto connect if last presence status is blank' do
# login_as 'testuser'
#
# get :index
# assert_template 'auto_connect_online'
# end
# should 'auto connect if there last presence status was chat' do
# create_user('testuser_online', :last_chat_status => 'chat')
# login_as 'testuser_online'
#
# get :index
# assert_template 'auto_connect_online'
# end
# should 'auto connect busy if last presence status was dnd' do
# create_user('testuser_busy', :last_chat_status => 'dnd')
# login_as 'testuser_busy'
#
# get :index
# assert_template 'auto_connect_busy'
# end
begin
require 'ruby_bosh'
should 'try to start xmpp session' do
login_as 'testuser'
RubyBOSH.expects(:initialize_session).raises("Error trying to connect...")
get :start_session
assert_response 500
assert_template 'start_session_error'
end
rescue LoadError
puts 'W: could not load RubyBOSH; skipping some chat tests'
should 'skip the above test if the chat dependencies are not installed' do
print '*'
end
end
# should 'render not found if chat feature disabled' do
# login_as 'testuser'
#
# env = Environment.default
# env.disable('xmpp_chat')
# env.save!
#
# get :index
#
# assert_response 404
# assert_template 'not_found'
# end
should 'not update presence status from non-ajax requests' do
@person.user.expects(:update_attributes).never
@controller.stubs(:current_user).returns(@person.user)
get :update_presence_status
assert_template nil
end
should 'update presence status from ajax requests' do
@person.user.expects(:update_attributes).once
@controller.stubs(:current_user).returns(@person.user)
@request.stubs(:xhr?).returns(true)
get :update_presence_status
assert_template nil
end
should 'update presence status time from ajax requests' do
@controller.stubs(:current_user).returns(@person.user)
@request.stubs(:xhr?).returns(true)
chat_status_at = @person.user.chat_status_at
get :update_presence_status
assert_not_equal chat_status_at, @person.user.chat_status_at
end
end