invite_controller_test.rb
5.4 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
require File.dirname(__FILE__) + '/../test_helper'
class InviteControllerTest < ActionController::TestCase
def setup
@profile = create_user('testuser').person
@friend = create_user('thefriend').person
@community = fast_create(Community)
login_as ('testuser')
end
attr_accessor :profile, :friend, :community
should 'add manually invitation of an added address with friend object on a queue and process it later' do
assert_difference Delayed::Job, :count, 1 do
post :friends, :profile => profile.identifier, :manual_import_addresses => "#{friend.name} <#{friend.email}>", :import_from => "manual", :mail_template => "click: <url>", :step => 2
assert_redirected_to :controller => 'friends'
end
assert_difference InviteFriend, :count, 1 do
Delayed::Worker.new.work_off
end
end
should 'add manually invitation of an added address with only email on a queue and process it later' do
assert_difference Delayed::Job, :count, 1 do
post :friends, :profile => profile.identifier, :manual_import_addresses => "test@test.com", :import_from => "manual", :mail_template => "click: <url>", :step => 2
assert_redirected_to :controller => 'friends'
end
assert_difference InviteFriend, :count, 1 do
Delayed::Worker.new.work_off
end
end
should 'add manually invitation of an added address with email and other format on a queue and process it later' do
assert_difference Delayed::Job, :count, 1 do
post :friends, :profile => profile.identifier, :manual_import_addresses => "test@test.cz.com", :import_from => "manual", :mail_template => "click: <url>", :step => 2
assert_redirected_to :controller => 'friends'
end
assert_difference InviteFriend, :count, 1 do
Delayed::Worker.new.work_off
end
end
should 'add manually invitation of more than one added address on a queue and process it later' do
assert_difference Delayed::Job, :count, 1 do
post :friends, :profile => profile.identifier, :manual_import_addresses => "Some Friend <somefriend@email.com>\r\notherperson@bleble.net\r\n", :import_from => "manual", :mail_template => "click: <url>", :step => 2
assert_redirected_to :controller => 'friends'
end
assert_difference InviteFriend, :count, 2 do
Delayed::Worker.new.work_off
end
end
should 'add manually invitation of an added address with name and e-mail on a queue and process it later' do
assert_difference Delayed::Job, :count, 1 do
post :friends, :profile => profile.identifier, :manual_import_addresses => "Test Name <test@test.com>", :import_from => "manual", :mail_template => "click: <url>", :step => 2
assert_redirected_to :controller => 'friends'
end
assert_difference InviteFriend, :count, 1 do
Delayed::Worker.new.work_off
end
end
should 'add invitation of yourself on a queue and not process it later' do
assert_difference Delayed::Job, :count, 1 do
post :friends, :profile => profile.identifier, :manual_import_addresses => "#{profile.name} <#{profile.user.email}>", :import_from => "manual", :mail_template => "click: <url>", :step => 2
assert_redirected_to :controller => 'friends'
end
assert_no_difference InviteFriend, :count do
Delayed::Worker.new.work_off
end
end
should 'add invitation of an already friend on a queue and not process it later' do
friend = create_user('testfriend', :email => 'friend@noosfero.org')
friend.person.add_friend(profile)
assert_difference Delayed::Job, :count, 1 do
post :friends, :profile => profile.identifier, :manual_import_addresses => "#{friend.name} <#{friend.email}>", :import_from => "manual", :mail_template => "click: <url>", :step => 2
assert_redirected_to :controller => 'friends'
end
assert_no_difference InviteFriend, :count do
Delayed::Worker.new.work_off
end
end
should 'display invitation page' do
get :friends, :profile => profile.identifier
assert_response :success
assert_tag :tag => 'h1', :content => 'Invite your friends'
end
should 'get mail template to invite members' do
community.add_admin(profile)
get :friends, :profile => community.identifier
assert_equal InviteMember.mail_template, assigns(:mail_template)
end
should 'get mail template to invite friends' do
community.add_admin(profile)
get :friends, :profile => profile.identifier
assert_equal InviteFriend.mail_template, assigns(:mail_template)
end
should 'deny if user has no rights to invite members' do
get :friends, :profile => community.identifier
assert_response 403 # forbidden
end
should 'deny access when trying to invite friends to another user' do
get :friends, :profile => friend.identifier
assert_response 403 # forbidden
end
should 'redirect to friends after invitation if profile is a person' do
post :friends, :profile => profile.identifier, :manual_import_addresses => "#{friend.name} <#{friend.email}>", :import_from => "manual", :mail_template => "click: <url>", :step => 2
assert_redirected_to :controller => 'friends'
end
should 'redirect to friends after invitation if profile is not a person' do
community.add_admin(profile)
post :friends, :profile => community.identifier, :manual_import_addresses => "#{friend.name} <#{friend.email}>", :import_from => "manual", :mail_template => "click: <url>", :step => 2
assert_redirected_to :controller => 'profile_members'
end
end