<commit_before>require 'spec_helper'

describe Amistad::FriendModel do
  
  before(:all) do
    %w(<NAME>).each do |name|
      eval "@#{name.downcase} = User.create(:name => '#{name}')"
    end
  end
  
  context "when creating friendships" do
    before(:each) do
      Friendship.delete_all
    end
    
    it "requests friendships with other users" do
      @john.invite(@jane).should == true
      @victoria.invite(@john).should == true
    end

    it "approves friendships requested by other users" do
      @john.invite(@jane).should == true
      @victoria.invite(@john).should == true

      @jane.approve(@john).should == true
      @john.approve(@victoria).should == true
    end
    
    it "could not create a new friendship with a user which is already a friend" do
      @john.invite(@jane).should == true
      @john.invite(@jane).should == false
      @jane.invite(@john).should == false
    end
    
    it "could not create a friendship with himself" do
      @john.invite(@john).should == false
    end
    
    it "could not approuve a non-existent friendship" do
      @peter.approve(@john).should == false
    end
  end
  
  context "when listing friendships" do
    before(:each) do
      Friendship.delete_all
      @john.invite(@jane).should == true
      @john.invite(@james).should == true
      
      @peter.invite(@john).should == true
      @mary.invite(@john).should == true
      
      @james.approve(@john).should == true
      @john.approve(@mary).should == true
    end
    
    it "lists all the friends" do
      @john.friends.count.should == 2
      @john.friends.should include(@james)
      @john.friends.should include(@mary)
    end
    
    it "lists the friends who invited him" do
      @john.invited_by.should include(@mary)
      @john.invited_by.should_not include(@peter)
    end
    
    it "lists the friends who was invited by him" do
      @john.invited.should include(@james)
      @john.invited.should_not include(@jane)
    end
    
    it "lists the pending friends who invited him" do
      @john.pending_invited_by.should_not include(@mary)
      @john.pending_invited_by.should include(@peter)
    end

    it "lists the pending friends who was invited by him" do
      @john.pending_invited.should_not include(@james)
      @john.pending_invited.should include(@jane)
    end

    it "checks if a user is a friend" do
      @john.is_friend_with?(@james).should == true
      @john.is_friend_with?(@mary).should == true
      
      @john.is_friend_with?(@jane).should == false
      @john.is_friend_with?(@peter).should == false
    end
    
    it "checks if a user was invited by another" do
      @jane.was_invited_by?(@john).should == true
      @james.was_invited_by?(@john).should == true
      
      @john.was_invited_by?(@jane).should == false
      @victoria.was_invited_by?(@john).should == false
    end
    
    it "lists the friends he has in common with another user" do
      @james.common_friends_with(@mary).count.should == 1
      @james.common_friends_with(@mary).should include(@john)
    end
  end
  
  context "when removing friendships" do
    before(:each) do
      Friendship.delete_all
      @victoria.invite(@mary).should == true<commit_msg>added specs for new methods<commit_after>require 'spec_helper'

describe Amistad::FriendModel do
  
  before(:all) do
    %w(<NAME> Mary <NAME>abeth).each do |name|
      eval "@#{name.downcase} = User.create(:name => '#{name}')"
    end
  end
  
  context "when creating friendships" do
    before(:each) do
      Friendship.delete_all
    end
    
    it "requests friendships with other users" do
      @john.invite(@jane).should == true
      @victoria.invite(@john).should == true
    end

    it "approves friendships requested by other users" do
      @john.invite(@jane).should == true
      @victoria.invite(@john).should == true

      @jane.approve(@john).should == true
      @john.approve(@victoria).should == true
    end
    
    it "could not create a new friendship with a user which is already a friend" do
      @john.invite(@jane).should == true
      @john.invite(@jane).should == false
      @jane.invite(@john).should == false
    end
    
    it "could not create a friendship with himself" do
      @john.invite(@john).should == false
    end
    
    it "could not approuve a non-existent friendship" do
      @peter.approve(@john).should == false
    end
  end
  
  context "when listing friendships" do
    before(:each) do
      Friendship.delete_all
      @john.invite(@jane).should == true
      @john.invite(@james).should == true
      
      @peter.invite(@john).should == true
      @mary.invite(@john).should == true
      
      @james.approve(@john).should == true
      @john.approve(@mary).should == true
    end
    
    it "lists all the friends" do
      @john.friends.count.should == 2
      @john.friends.should include(@james)
      @john.friends.should include(@mary)
    end
    
    it "lists the friends who invited him" do
      @john.invited_by.should include(@mary)
      @john.invited_by.should_not include(@peter)
    end
    
    it "lists the friends who was invited by him" do
      @john.invited.should include(@james)
      @john.invited.should_not include(@jane)
    end
    
    it "lists the pending friends who invited him" do
      @john.pending_invited_by.should_not include(@mary)
      @john.pending_invited_by.should include(@peter)
    end

    it "lists the pending friends who was invited by him" do
      @john.pending_invited.should_not include(@james)
      @john.pending_invited.should include(@jane)
    end

    it "checks if a user is a friend" do
      @john.is_friend_with?(@james).should == true
      @john.is_friend_with?(@mary).should == true

      @john.is_friend_with?(@jane).should == false
      @john.is_friend_with?(@peter).should == false
    end

    it "checks if a user has any connection with another user" do
      @john.is_connected_with?(@jane).should == true
      @jane.is_connected_with?(@john).should == true

      @john.is_connected_with?(@peter).should == true
      @peter.is_connected_with?(@john).should == true

      @victoria.is_connected_with?(@john).should == false
      @john.is_connected_with?(@victoria).should == false
    end

    it "checks if a user was invited by another" do
      @jane.was_invited_by?(@john).should == true
      @james.was_invited_by?(@john).should == true
      
      @john.was_invited_by?(@jane).should == false
      @victoria.was_invited_by?(@john).should == false
    end

    it "checks if a user has invited another user" do
      @john.has_invited?(@jane).should == true
      @john.has_invited?(@james).should == true

      @jane.has_invited?(@john).should == false
      @james.has_invited?(@john).should == false

      @victoria.has_invited?(@john).should == false
      @john.has_invited?(@victoria).should == false
    end

    it "lists the friends he has in common with another user" do
      @james.common_friends_with(@mary).count.should == 1
      @james.common_friends_with(@mary).should include(@john)
    end
  end
  
  context "when removing friendships" do
    before(:each) do
      Friendship.delete_all
      @victoria.invite(@mary).should == true
{'fraction_non_alphanumeric': 0.12101998621640248, 'fraction_numerical': 0.0005513439007580978, 'mean_word_length': 2.7850808555033906, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4408321', 'n_tokens_mistral': 2440, 'n_tokens_neox': 2298, 'n_words': 569}