https://github.com/dfischer/fischyfriends
A fischy(sic) version of a friend system
https://github.com/dfischer/fischyfriends
Last synced: about 1 year ago
JSON representation
A fischy(sic) version of a friend system
- Host: GitHub
- URL: https://github.com/dfischer/fischyfriends
- Owner: dfischer
- License: mit
- Created: 2008-03-14T10:33:48.000Z (over 18 years ago)
- Default Branch: master
- Last Pushed: 2008-08-03T09:25:42.000Z (almost 18 years ago)
- Last Synced: 2025-03-26T13:12:26.262Z (over 1 year ago)
- Language: Ruby
- Homepage: http://www.danielfischer.com
- Size: 87.9 KB
- Stars: 42
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.textile
- License: MIT-LICENSE
Awesome Lists containing this project
README
h1. 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:
class CreateFriendships < ActiveRecord::Migration
def self.up
create_table :friendships do |t|
t.integer "user_id", :null => false
t.integer "friend_id", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.timestamps
end
add_index :friendships, :user_id
add_index :friendships, :friend_id
end
def self.down
drop_table :friendships
end
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
h1. 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
it "should be able to tell you if two people are mutual friends" do
@bob.add_friend @quentin
@bob.add_friend @wtf
@quentin.add_friend @bob
@bob.is_mutual_friends_with?(@quentin).should eql(true)
@bob.is_mutual_friends_with?(@wtf).should eql(false)
end
end
h1. Changelog
=======
*August 3, 2008*
* Accepted changeset "868bc":http://github.com/pogopuffin/fischyfriends/commit/868bc89db99fb52385028b9679eb917548a447b6 by pogopuffin
* Added in specs against above changeset
* Tested against Rails 2.1.0 w/ passes
* Updated migration example with indexes, is this wise? I'm not a database wiz here.
*March 14, 2008*
* First Release
Copyright (c) 2008 [Daniel Fischer] / http://www.danielfischer.com, released under the MIT license