Commit ca3abf86681aa65801856a5e073ea2a65fb99acb

Authored by AntonioTerceiro
1 parent bdfc4145

ActionItem36: adding a minimal Friendship class


git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1459 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/models/friendship.rb
1 class Friendship < ActiveRecord::Base 1 class Friendship < ActiveRecord::Base
  2 + belongs_to :person, :foreign_key => :person_id
  3 + belongs_to :friend, :class_name => 'Person', :foreign_key => 'friend_id'
  4 +
2 end 5 end
test/fixtures/friendships.yml
@@ -1,5 +0,0 @@ @@ -1,5 +0,0 @@
1 -# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html  
2 -one:  
3 - id: 1  
4 -two:  
5 - id: 2  
test/unit/friendship_test.rb
1 require File.dirname(__FILE__) + '/../test_helper' 1 require File.dirname(__FILE__) + '/../test_helper'
2 2
3 class FriendshipTest < Test::Unit::TestCase 3 class FriendshipTest < Test::Unit::TestCase
4 - fixtures :friendships  
5 4
6 - # Replace this with your real tests.  
7 - def test_truth  
8 - assert true 5 + should 'connect a person to another' do
  6 + p1 = Person.new
  7 + p2 = Person.new
  8 +
  9 + f = Friendship.new
  10 + assert_raise ActiveRecord::AssociationTypeMismatch do
  11 + f.person = Organization.new
  12 + end
  13 + assert_raise ActiveRecord::AssociationTypeMismatch do
  14 + f.friend = Organization.new
  15 + end
  16 + assert_nothing_raised do
  17 + f.person = p1
  18 + f.friend = p2
  19 + end
  20 +
  21 + f.save!
  22 +
9 end 23 end
  24 +
10 end 25 end