Skip to content

Instantly share code, notes, and snippets.

@danielharan
Created August 26, 2009 21:33
Show Gist options
  • Save danielharan/175864 to your computer and use it in GitHub Desktop.
Save danielharan/175864 to your computer and use it in GitHub Desktop.
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
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment