Commit f03d356367a613c33feeeba7ce1e5f63d097a923
1 parent
95b5546d
Exists in
master
and in
28 other branches
ActionItem36: "scheduling" addition of friends
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1467 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
83 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,24 @@ |
1 | +class AddFriend < Task | |
2 | + | |
3 | + acts_as_having_settings :group_for_person, :group_for_friend, :field => :data | |
4 | + | |
5 | + validates_presence_of :requestor_id, :target_id | |
6 | + | |
7 | + alias :person :requestor | |
8 | + alias :person= :requestor= | |
9 | + | |
10 | + alias :friend :target | |
11 | + alias :friend= :target= | |
12 | + | |
13 | + def perform | |
14 | + Friendship.create!(:person => requestor, :friend => target) | |
15 | + Friendship.create!(:person => target, :friend => requestor) | |
16 | + end | |
17 | + | |
18 | + # Returns <tt>false</tt>. Adding friends by itself does not trigger e-mail | |
19 | + # sending. | |
20 | + def sends_email? | |
21 | + false | |
22 | + end | |
23 | + | |
24 | +end | ... | ... |
... | ... | @@ -0,0 +1,59 @@ |
1 | +require File.dirname(__FILE__) + '/../test_helper' | |
2 | + | |
3 | +class AddFriendTest < ActiveSupport::TestCase | |
4 | + | |
5 | + should 'be a task' do | |
6 | + ok { AddFriend.new.kind_of?(Task) } | |
7 | + end | |
8 | + | |
9 | + should 'actually create friendships (two way) when confirmed' do | |
10 | + p1 = create_user('testuser1').person | |
11 | + p2 = create_user('testuser2').person | |
12 | + | |
13 | + task = AddFriend.create!(:person => p1, :friend => p2) | |
14 | + | |
15 | + assert_difference Friendship, :count, 2 do | |
16 | + task.finish | |
17 | + end | |
18 | + | |
19 | + ok('p1 should have p2 as friend') { p1.friends.include?(p2) } | |
20 | + ok('p2 should have p1 as friend') { p2.friends.include?(p1) } | |
21 | + end | |
22 | + | |
23 | + should 'require requestor (person adding other as friend)' do | |
24 | + task = AddFriend.new | |
25 | + task.valid? | |
26 | + | |
27 | + ok('must not validate with empty requestor') { task.errors.invalid?(:requestor_id) } | |
28 | + | |
29 | + task.requestor = Person.new | |
30 | + task.valid? | |
31 | + ok('must validate when requestor is given') { task.errors.invalid?(:requestor_id)} | |
32 | + | |
33 | + end | |
34 | + | |
35 | + should 'require target (person being added)' do | |
36 | + task = AddFriend.new | |
37 | + task.valid? | |
38 | + | |
39 | + ok('must not validate with empty target') { task.errors.invalid?(:target_id) } | |
40 | + | |
41 | + task.target = Person.new | |
42 | + task.valid? | |
43 | + ok('must validate when target is given') { task.errors.invalid?(:target_id)} | |
44 | + end | |
45 | + | |
46 | + should 'not send e-mails' do | |
47 | + | |
48 | + p1 = create_user('testuser1').person | |
49 | + p2 = create_user('testuser2').person | |
50 | + | |
51 | + TaskMailer.expects(:deliver_task_finished).never | |
52 | + TaskMailer.expects(:deliver_task_created).never | |
53 | + | |
54 | + task = AddFriend.create!(:person => p1, :friend => p2) | |
55 | + task.finish | |
56 | + | |
57 | + end | |
58 | + | |
59 | +end | ... | ... |