Skip to content

osfho/fischyfriends

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fischyfriends
=====

Pre-productioon plugin released to the public.

The basic idea is that there are two classes of users.

Fans, and mutual fans. If two people are fans, they are mutual fans, and thereby in my definition, friends.

Make sure you create a friendship model and this migration:

  
    create_table "friendships", :force => true do |t|
      t.integer  "user_id",    :null => false
      t.integer  "friend_id",  :null => false
      t.datetime "created_at"
      t.datetime "updated_at"
    end
  
  
    #friendship.rb
    
    class Friendship < ActiveRecord::Base
      belongs_to :friendshipped_by_me,   :foreign_key => :user_id,   :class_name => "User"
      belongs_to :friendshipped_for_me,  :foreign_key => :friend_id, :class_name => "User"
    end
  

Also add this in your user model:

  
    #user.rb
    
    acts_as_fischyfriend
  

RSpec Example
===

  
    require File.dirname(__FILE__) + '/../spec_helper'

    describe Friendship do
      before(:each) do
        @friendship = Friendship.new
      end

      it "should be valid" do
        @friendship.should be_valid
      end
    end

    describe Friendship, "between two users" do
      fixtures :users
  
      before(:each) do
        @quentin = users(:quentin)
        @bob = users(:aaron)
        @wtf = User.create!(:login => 'a_user', :password => 'password', :password_confirmation => 'password', :email => 'poop@poop.com')
      end
  
      it "should acknowledge there is a friendship between them" do
        @bob.add_friend @quentin
        @bob.add_friend @wtf
        @quentin.add_friend @bob
    
        @bob.reload

        @bob.is_a_fan_of.should include(@wtf)
        @bob.is_a_fan_of.should_not include(@quentin)
   
        @bob.pending_mutual_friends.should include(@wtf)
        @bob.pending_mutual_friends.should_not include(@quentin)

        @wtf.mutual_friends.should be_empty
        @wtf.fans_of_me.should include(@bob)
    
        @quentin.reload
        @quentin.mutual_friends.should include(@bob)
        @quentin.mutual_friends.should_not include(@wtf)
    
        @quentin.destroy_friendship_with @bob
        @quentin.reload
        @quentin.friends_by_me.should_not include(@bob)
    
      end
    end
  

Copyright © 2008 [Daniel Fischer] / http://www.danielfischer.com, released under the MIT license

About

A fischy(sic) version of a friend system

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%