Sha256: ce664febf83c5f3422ca3208efcf86c0c43fd6165c4d1611e37a5eed4372bbd0

Contents?: true

Size: 1.69 KB

Versions: 10

Compression:

Stored size: 1.69 KB

Contents

require 'test_helper'

class FriendshipTest < ActiveSupport::TestCase
  fixtures :friendships, :users, :roles, :friendship_statuses 

  def test_user_and_friend_can_not_be_same
    fr = Friendship.new(:user_id => 1, :friend_id => 1)
    assert(!fr.valid?, "Friendship should not be valid")
    assert fr.errors[:user_id]
  end
  
  def test_should_prevent_overzealous_frienders
    Friendship.daily_request_limit = 2    
    
    assert Friendship.create!(:user_id => 1, :friend_id => 3, :friendship_status => FriendshipStatus[:pending], :initiator => true)
    assert Friendship.create!(:user_id => 1, :friend_id => 4, :friendship_status => FriendshipStatus[:pending], :initiator => true)
    
    f3 = Friendship.create(:user_id => 1, :friend_id => 5, :friendship_status => FriendshipStatus[:pending], :initiator => true)
    assert(!f3.valid?, "Friendship should not be valid")
    assert_equal f3.errors[:base], ["Sorry, you'll have to wait a little while before requesting any more friendships."]
  end
  
  def test_should_notify_requester_when_accepted
    f = friendships(:aaron_receive_quentin_pending)    
    assert_difference ActionMailer::Base.deliveries, :length, 1 do
      f.update_attributes(:friendship_status => FriendshipStatus[:accepted]) && f.reverse.update_attributes(:friendship_status => FriendshipStatus[:accepted])    
    end        
  end

  def test_should_not_notify_requester_when_pending
    f = friendships(:aaron_receive_quentin_pending)    
    assert_difference ActionMailer::Base.deliveries, :length, 0 do
      f.update_attributes(:friendship_status => FriendshipStatus[:pending]) && f.reverse.update_attributes(:friendship_status => FriendshipStatus[:pending])    
    end        
  end


end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
community_engine-3.2.0 test/unit/friendship_test.rb
community_engine-3.0.0 test/unit/friendship_test.rb
community_engine-2.3.2 test/unit/friendship_test.rb
community_engine-2.3.1 test/unit/friendship_test.rb
community_engine-2.3.0 test/unit/friendship_test.rb
community_engine-2.1.0 test/unit/friendship_test.rb
community_engine-2.0.0 test/unit/friendship_test.rb
community_engine-2.0.0.beta3 test/unit/friendship_test.rb
community_engine-2.0.0.beta2 test/unit/friendship_test.rb
community_engine-2.0.0.beta1 test/unit/friendship_test.rb