danielharan (owner)

Revisions

gist: 175864 Download_button fork
public
Public Clone URL: git://gist.github.com/175864.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
  has_many :connections, :foreign_key => "from_id"
  has_many :favorites, :through => :connections, :source => :to
  
  has_many :connections_as_target, :class_name => "Connection", :foreign_key => "to_id"
  has_many :fans, :through => :connections_as_target, :source => :from
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  context "A person having connections" do
    setup do
      @john = Factory(:person)
      
      # John pays attention to Jane
      @jane = Factory(:person)
      @connection = @john.connections.create :to => @jane
    end
    
    should "create a connection" do
      assert_equal @john, @connection.from
      assert_equal @jane, @connection.to
    end
    
    should "mark @jane as one of John's favorites" do
      assert_equal [@jane], @john.favorites
    end
    
    should "mark @john as one of Jane's fans" do
      assert_equal [@john], @jane.fans
    end
  end