Commit e4b31d74a5832de06e020a5ef220ae9a0252ded8
1 parent
5955193e
Exists in
master
and in
27 other branches
friendship: make it possible to be friend again
Showing
4 changed files
with
7 additions
and
5 deletions
Show diff stats
app/models/add_friend.rb
... | ... | @@ -4,7 +4,7 @@ class AddFriend < Task |
4 | 4 | |
5 | 5 | validates_presence_of :requestor_id, :target_id |
6 | 6 | |
7 | - validates_uniqueness_of :target_id, :scope => [ :requestor_id ] | |
7 | + validates_uniqueness_of :target_id, scope: [ :requestor_id, :status ], if: proc{ |t| t.status == Task::Status::ACTIVE } | |
8 | 8 | |
9 | 9 | validates_length_of :group_for_person, :group_for_friend, :maximum => 150, :allow_nil => true |
10 | 10 | ... | ... |
app/models/person.rb
... | ... | @@ -150,7 +150,7 @@ roles] } |
150 | 150 | end |
151 | 151 | |
152 | 152 | def already_request_friendship?(person) |
153 | - person.tasks.find_by_requestor_id(self.id, :conditions => { :type => 'AddFriend' }) | |
153 | + person.tasks.where(requestor_id: self.id, type: 'AddFriend', status: Task::Status::ACTIVE).first | |
154 | 154 | end |
155 | 155 | |
156 | 156 | def remove_friend(friend) | ... | ... |
test/unit/add_friend_test.rb
... | ... | @@ -77,9 +77,9 @@ class AddFriendTest < ActiveSupport::TestCase |
77 | 77 | end |
78 | 78 | |
79 | 79 | should 'not add friend twice' do |
80 | - fast_create(AddFriend, :requestor_id => person1.id, :target_id => person2.id) | |
80 | + create AddFriend, person: person1, friend: person2, status: 1 | |
81 | 81 | assert_raise ActiveRecord::RecordInvalid do |
82 | - AddFriend.create!(:person => person1, :friend => person2) | |
82 | + create AddFriend, person: person1, friend: person2, status: 1 | |
83 | 83 | end |
84 | 84 | end |
85 | 85 | ... | ... |
test/unit/person_test.rb
... | ... | @@ -324,7 +324,9 @@ class PersonTest < ActiveSupport::TestCase |
324 | 324 | should 'already request friendship' do |
325 | 325 | p1 = create_user('testuser1').person |
326 | 326 | p2 = create_user('testuser2').person |
327 | - create(AddFriend, :person => p1, :friend => p2) | |
327 | + create(AddFriend, person: p1, friend: p2).finish | |
328 | + assert !p1.already_request_friendship?(p2) | |
329 | + create(AddFriend, person: p1, friend: p2) | |
328 | 330 | assert p1.already_request_friendship?(p2) |
329 | 331 | end |
330 | 332 | ... | ... |