diff --git a/app/models/friendship.rb b/app/models/friendship.rb index ab4fcd8..6afc8a7 100644 --- a/app/models/friendship.rb +++ b/app/models/friendship.rb @@ -1,2 +1,5 @@ class Friendship < ActiveRecord::Base + belongs_to :person, :foreign_key => :person_id + belongs_to :friend, :class_name => 'Person', :foreign_key => 'friend_id' + end diff --git a/test/fixtures/friendships.yml b/test/fixtures/friendships.yml deleted file mode 100644 index b49c4eb..0000000 --- a/test/fixtures/friendships.yml +++ /dev/null @@ -1,5 +0,0 @@ -# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html -one: - id: 1 -two: - id: 2 diff --git a/test/unit/friendship_test.rb b/test/unit/friendship_test.rb index bfc3041..ac0605f 100644 --- a/test/unit/friendship_test.rb +++ b/test/unit/friendship_test.rb @@ -1,10 +1,25 @@ require File.dirname(__FILE__) + '/../test_helper' class FriendshipTest < Test::Unit::TestCase - fixtures :friendships - # Replace this with your real tests. - def test_truth - assert true + should 'connect a person to another' do + p1 = Person.new + p2 = Person.new + + f = Friendship.new + assert_raise ActiveRecord::AssociationTypeMismatch do + f.person = Organization.new + end + assert_raise ActiveRecord::AssociationTypeMismatch do + f.friend = Organization.new + end + assert_nothing_raised do + f.person = p1 + f.friend = p2 + end + + f.save! + end + end -- libgit2 0.21.2