Commit 557f1f5f3041e172c61b8e90c40b082d681c4280
1 parent
675e8782
Exists in
master
and in
22 other branches
invite-members: updates tests to work on rails3
Showing
3 changed files
with
23 additions
and
20 deletions
Show diff stats
test/functional/invite_controller_test.rb
@@ -246,15 +246,15 @@ class InviteControllerTest < ActionController::TestCase | @@ -246,15 +246,15 @@ class InviteControllerTest < ActionController::TestCase | ||
246 | get :search_friend, :profile => profile.identifier, :q => 'me@' | 246 | get :search_friend, :profile => profile.identifier, :q => 'me@' |
247 | 247 | ||
248 | assert_equal 'text/html', @response.content_type | 248 | assert_equal 'text/html', @response.content_type |
249 | - assert_equal [{"name" => friend2.name, "id" => friend2.id}].to_json, @response.body | 249 | + assert_equal [{"id" => friend2.id, "name" => friend2.name}].to_json, @response.body |
250 | 250 | ||
251 | get :search_friend, :profile => profile.identifier, :q => 'cri' | 251 | get :search_friend, :profile => profile.identifier, :q => 'cri' |
252 | 252 | ||
253 | - assert_equal [{"name" => friend1.name, "id" => friend1.id}].to_json, @response.body | 253 | + assert_equal [{"id" => friend1.id, "name" => friend1.name}].to_json, @response.body |
254 | 254 | ||
255 | get :search_friend, :profile => profile.identifier, :q => 'will' | 255 | get :search_friend, :profile => profile.identifier, :q => 'will' |
256 | 256 | ||
257 | - assert_equal [{"name" => friend1.name, "id" => friend1.id}, {"name" => friend2.name, "id" => friend2.id}].to_json, @response.body | 257 | + assert_equal [{"id" => friend1.id, "name" => friend1.name}, {"id" => friend2.id, "name" => friend2.name}].to_json, @response.body |
258 | end | 258 | end |
259 | 259 | ||
260 | should 'not include members in search friends profiles' do | 260 | should 'not include members in search friends profiles' do |
@@ -268,7 +268,7 @@ class InviteControllerTest < ActionController::TestCase | @@ -268,7 +268,7 @@ class InviteControllerTest < ActionController::TestCase | ||
268 | 268 | ||
269 | get :search_friend, :profile => community.identifier, :q => 'will' | 269 | get :search_friend, :profile => community.identifier, :q => 'will' |
270 | 270 | ||
271 | - assert_equal [{"name" => friend1.name, "id" => friend1.id}].to_json, @response.body | 271 | + assert_equal [{"id" => friend1.id, "name" => friend1.name}].to_json, @response.body |
272 | end | 272 | end |
273 | 273 | ||
274 | should 'search friends profiles by fields provided by plugins' do | 274 | should 'search friends profiles by fields provided by plugins' do |
@@ -277,9 +277,10 @@ class InviteControllerTest < ActionController::TestCase | @@ -277,9 +277,10 @@ class InviteControllerTest < ActionController::TestCase | ||
277 | [{:field => 'nickname'}, {:field => 'contact_phone'}] | 277 | [{:field => 'nickname'}, {:field => 'contact_phone'}] |
278 | end | 278 | end |
279 | end | 279 | end |
280 | + Noosfero::Plugin.stubs(:all).returns([Plugin1.name]) | ||
280 | 281 | ||
281 | environment = Environment.default | 282 | environment = Environment.default |
282 | - environment.enable_plugin(Plugin1) | 283 | + environment.enable_plugin(Plugin1.name) |
283 | 284 | ||
284 | friend1 = create_user('harry').person | 285 | friend1 = create_user('harry').person |
285 | friend2 = create_user('william').person | 286 | friend2 = create_user('william').person |
@@ -289,21 +290,21 @@ class InviteControllerTest < ActionController::TestCase | @@ -289,21 +290,21 @@ class InviteControllerTest < ActionController::TestCase | ||
289 | friend2.save | 290 | friend2.save |
290 | 291 | ||
291 | get :search_friend, :profile => profile.identifier, :q => 'prince' | 292 | get :search_friend, :profile => profile.identifier, :q => 'prince' |
292 | - assert_equal [{"name" => friend1.name, "id" => friend1.id}].to_json, @response.body | 293 | + assert_equal [{"id" => friend1.id, "name" => friend1.name}].to_json, @response.body |
293 | 294 | ||
294 | get :search_friend, :profile => profile.identifier, :q => '222' | 295 | get :search_friend, :profile => profile.identifier, :q => '222' |
295 | - assert_equal [{"name" => friend2.name, "id" => friend2.id}].to_json, @response.body | 296 | + assert_equal [{"id" => friend2.id, "name" => friend2.name}].to_json, @response.body |
296 | end | 297 | end |
297 | 298 | ||
298 | should 'invite registered users through profile id' do | 299 | should 'invite registered users through profile id' do |
299 | friend1 = create_user('testuser1').person | 300 | friend1 = create_user('testuser1').person |
300 | friend2 = create_user('testuser2').person | 301 | friend2 = create_user('testuser2').person |
301 | - assert_difference Delayed::Job, :count, 1 do | 302 | + assert_difference 'Delayed::Job.count', 1 do |
302 | post :invite_registered_friend, :profile => profile.identifier, :q => "#{friend1.id},#{friend2.id}", :mail_template => "click: <url>" | 303 | post :invite_registered_friend, :profile => profile.identifier, :q => "#{friend1.id},#{friend2.id}", :mail_template => "click: <url>" |
303 | assert_redirected_to :controller => 'profile', :action => 'friends' | 304 | assert_redirected_to :controller => 'profile', :action => 'friends' |
304 | end | 305 | end |
305 | 306 | ||
306 | - assert_difference InviteFriend, :count, 2 do | 307 | + assert_difference 'InviteFriend.count', 2 do |
307 | process_delayed_job_queue | 308 | process_delayed_job_queue |
308 | end | 309 | end |
309 | end | 310 | end |
test/unit/invitation_test.rb
@@ -78,7 +78,7 @@ class InvitationTest < ActiveSupport::TestCase | @@ -78,7 +78,7 @@ class InvitationTest < ActiveSupport::TestCase | ||
78 | 78 | ||
79 | invited_friend.add_friend(person) | 79 | invited_friend.add_friend(person) |
80 | 80 | ||
81 | - assert_no_difference InviteFriend, :count do | 81 | + assert_no_difference 'InviteFriend.count' do |
82 | Invitation.invite( person, [invited_friend.user.email], "", person ) | 82 | Invitation.invite( person, [invited_friend.user.email], "", person ) |
83 | end | 83 | end |
84 | end | 84 | end |
@@ -90,7 +90,7 @@ class InvitationTest < ActiveSupport::TestCase | @@ -90,7 +90,7 @@ class InvitationTest < ActiveSupport::TestCase | ||
90 | invited_friend.add_friend(person) | 90 | invited_friend.add_friend(person) |
91 | community = fast_create(Community) | 91 | community = fast_create(Community) |
92 | 92 | ||
93 | - assert_difference InviteMember, :count do | 93 | + assert_difference 'InviteMember.count' do |
94 | Invitation.invite( person, [invited_friend.user.email], "", community ) | 94 | Invitation.invite( person, [invited_friend.user.email], "", community ) |
95 | end | 95 | end |
96 | end | 96 | end |
@@ -126,10 +126,10 @@ class InvitationTest < ActiveSupport::TestCase | @@ -126,10 +126,10 @@ class InvitationTest < ActiveSupport::TestCase | ||
126 | friend = create_user('testuser2').person | 126 | friend = create_user('testuser2').person |
127 | community = fast_create(Community) | 127 | community = fast_create(Community) |
128 | 128 | ||
129 | - assert_difference InviteMember, :count do | 129 | + assert_difference 'InviteMember.count' do |
130 | Invitation.invite(person, [friend.id.to_s], 'hello friend <url>', community) | 130 | Invitation.invite(person, [friend.id.to_s], 'hello friend <url>', community) |
131 | end | 131 | end |
132 | - assert_difference InviteFriend, :count do | 132 | + assert_difference 'InviteFriend.count' do |
133 | Invitation.invite(person, [friend.id.to_s], 'hello friend <url>', person) | 133 | Invitation.invite(person, [friend.id.to_s], 'hello friend <url>', person) |
134 | end | 134 | end |
135 | end | 135 | end |
@@ -139,17 +139,17 @@ class InvitationTest < ActiveSupport::TestCase | @@ -139,17 +139,17 @@ class InvitationTest < ActiveSupport::TestCase | ||
139 | friend = create_user('testuser2').person | 139 | friend = create_user('testuser2').person |
140 | community = fast_create(Community) | 140 | community = fast_create(Community) |
141 | 141 | ||
142 | - assert_difference InviteMember, :count do | 142 | + assert_difference 'InviteMember.count' do |
143 | Invitation.invite(person, [friend.id.to_s], 'hello friend <url>', community) | 143 | Invitation.invite(person, [friend.id.to_s], 'hello friend <url>', community) |
144 | end | 144 | end |
145 | - assert_difference InviteFriend, :count do | 145 | + assert_difference 'InviteFriend.count' do |
146 | Invitation.invite(person, [friend.id.to_s], 'hello friend <url>', person) | 146 | Invitation.invite(person, [friend.id.to_s], 'hello friend <url>', person) |
147 | end | 147 | end |
148 | 148 | ||
149 | - assert_no_difference InviteMember, :count do | 149 | + assert_no_difference 'InviteMember.count' do |
150 | Invitation.invite(person, [friend.id.to_s], 'hello friend <url>', community) | 150 | Invitation.invite(person, [friend.id.to_s], 'hello friend <url>', community) |
151 | end | 151 | end |
152 | - assert_no_difference InviteFriend, :count do | 152 | + assert_no_difference 'InviteFriend.count' do |
153 | Invitation.invite(person, [friend.id.to_s], 'hello friend <url>', person) | 153 | Invitation.invite(person, [friend.id.to_s], 'hello friend <url>', person) |
154 | end | 154 | end |
155 | end | 155 | end |
test/unit/invite_member_test.rb
@@ -31,7 +31,7 @@ class InviteMemberTest < ActiveSupport::TestCase | @@ -31,7 +31,7 @@ class InviteMemberTest < ActiveSupport::TestCase | ||
31 | task = InviteMember.create!(:person => p1, :friend => friend, :community_id => community.id) | 31 | task = InviteMember.create!(:person => p1, :friend => friend, :community_id => community.id) |
32 | InviteMember.create!(:person => p2, :friend => friend, :community_id => community.id) | 32 | InviteMember.create!(:person => p2, :friend => friend, :community_id => community.id) |
33 | 33 | ||
34 | - assert_difference friend.tasks.pending, :count, -2 do | 34 | + assert_difference 'friend.tasks.pending.count', -2 do |
35 | task.finish | 35 | task.finish |
36 | end | 36 | end |
37 | end | 37 | end |
@@ -96,7 +96,9 @@ class InviteMemberTest < ActiveSupport::TestCase | @@ -96,7 +96,9 @@ class InviteMemberTest < ActiveSupport::TestCase | ||
96 | p1 = create_user('testuser1').person | 96 | p1 = create_user('testuser1').person |
97 | p2 = create_user('testuser2').person | 97 | p2 = create_user('testuser2').person |
98 | 98 | ||
99 | - TaskMailer.expects(:deliver_target_notification).once | 99 | + mailer = mock |
100 | + mailer.expects(:deliver).at_least_once | ||
101 | + TaskMailer.expects(:target_notification).returns(mailer).once | ||
100 | 102 | ||
101 | task = InviteMember.create!(:person => p1, :friend => p2, :community_id => fast_create(Community).id) | 103 | task = InviteMember.create!(:person => p1, :friend => p2, :community_id => fast_create(Community).id) |
102 | end | 104 | end |
@@ -166,7 +168,7 @@ class InviteMemberTest < ActiveSupport::TestCase | @@ -166,7 +168,7 @@ class InviteMemberTest < ActiveSupport::TestCase | ||
166 | 168 | ||
167 | task = InviteMember.create!(:person => p1, :friend => p2, :community_id => fast_create(Community).id) | 169 | task = InviteMember.create!(:person => p1, :friend => p2, :community_id => fast_create(Community).id) |
168 | 170 | ||
169 | - email = TaskMailer.deliver_target_notification(task, task.target_notification_message) | 171 | + email = TaskMailer.target_notification(task, task.target_notification_message).deliver |
170 | assert_match(/#{task.requestor.name} invited you to join #{task.community.name}/, email.subject) | 172 | assert_match(/#{task.requestor.name} invited you to join #{task.community.name}/, email.subject) |
171 | end | 173 | end |
172 | end | 174 | end |