public
Description: The open source social networking platform in Ruby on Rails from the author of RailsSpace
Homepage: http://insoshi.com
Clone URL: git://github.com/insoshi/insoshi.git
Basic message associations and validations
Michael Hartl (author)
Fri Feb 22 18:45:18 -0800 2008
commit  368f57dd27358247488e03888d42bf32c45568c5
tree    5c26d35850808a9661b58f6eeb0af011b270fb07
parent  9e0f578cd9f50e250d65f1eccf7211c674eea5c5
...
1
 
2
3
4
...
14
15
16
 
 
 
 
 
 
 
 
 
 
 
17
18
19
...
32
33
34
 
 
 
 
 
 
 
 
 
 
35
36
37
...
1
2
3
4
5
...
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
...
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
0
@@ -1,4 +1,5 @@
0
 require 'digest/sha1'
0
+# TODO: move ^ this ^ to a global include place.
0
 class Person < ActiveRecord::Base
0
   
0
   MAX_EMAIL = MAX_PASSWORD = 40
0
@@ -14,6 +15,17 @@ class Person < ActiveRecord::Base
0
   NUM_RECENTLY_VIEWED = 4
0
   
0
   has_many :photos, :dependent => :destroy, :order => 'created_at'
0
+ # TODO: use with_options here
0
+ has_many :_sent_messages, :foreign_key => "sender_id",
0
+ :class_name => "Message",
0
+ :dependent => :destroy,
0
+ :conditions => "sender_deleted_at IS NULL",
0
+ :order => 'created_at DESC'
0
+ has_many :_received_messages, :foreign_key => "recipient_id",
0
+ :class_name => "Message",
0
+ :dependent => :destroy,
0
+ :conditions => "recipient_deleted_at IS NULL",
0
+ :order => 'created_at DESC'
0
   attr_accessor :password, :sorted_photos
0
   attr_accessible :email, :password, :password_confirmation, :name,
0
                   :description
0
@@ -32,6 +44,16 @@ class Person < ActiveRecord::Base
0
   
0
   before_save :downcase_email, :encrypt_password
0
   
0
+ ## Message methods
0
+
0
+ def received_messages(page = 1)
0
+ _received_messages.paginate(:page => page, :per_page => MESSAGES_PER_PAGE)
0
+ end
0
+
0
+ def sent_messages(page = 1)
0
+ _sent_messages.paginate(:page => page, :per_page => MESSAGES_PER_PAGE)
0
+ end
0
+
0
   ## Photo helpers
0
   
0
   def photo
...
1
 
 
2
3
4
...
1
2
3
4
5
6
0
@@ -1,4 +1,6 @@
0
 ActionController::Routing::Routes.draw do |map|
0
+ map.resources :communications
0
+
0
   map.resources :photos
0
   map.resources :people
0
   map.resource :session
...
5
6
7
8
9
10
11
12
...
14
15
16
17
 
 
 
 
 
 
18
...
5
6
7
 
 
8
9
10
...
12
13
14
 
15
16
17
18
19
20
21
0
@@ -5,8 +5,6 @@ quentin:
0
   crypted_password: JdoXqX9FKe9zeGEArrs796+NtoqYBT3DYSRe/1CyHMyNorHPvUImHPJfx1mM\nsz7hEFypKH7p/jRAnwQLVbcJTdjL8+Wet4/bJOT55NN2eWMRb/wZKGdljOy9\nbTEAenLKKEQNQtpE7QQiiSQ7a1DACJxhPYqWAn1lOQ9K8Rv77MA=\n
0
   created_at: <%= 5.days.ago.to_s :db %>
0
 
0
-
0
-
0
 aaron:
0
   email: aaron@example.com
0
   name: Aaron
0
@@ -14,4 +12,9 @@ aaron:
0
   crypted_password: JdoXqX9FKe9zeGEArrs796+NtoqYBT3DYSRe/1CyHMyNorHPvUImHPJfx1mM\nsz7hEFypKH7p/jRAnwQLVbcJTdjL8+Wet4/bJOT55NN2eWMRb/wZKGdljOy9\nbTEAenLKKEQNQtpE7QQiiSQ7a1DACJxhPYqWAn1lOQ9K8Rv77MA=\n
0
   created_at: <%= 1.day.ago.to_s :db %>
0
 
0
-
0
+kelly:
0
+ email: kelly@example.com
0
+ name: Kelly
0
+ description: I'm Kelly
0
+ crypted_password: JdoXqX9FKe9zeGEArrs796+NtoqYBT3DYSRe/1CyHMyNorHPvUImHPJfx1mM\nsz7hEFypKH7p/jRAnwQLVbcJTdjL8+Wet4/bJOT55NN2eWMRb/wZKGdljOy9\nbTEAenLKKEQNQtpE7QQiiSQ7a1DACJxhPYqWAn1lOQ9K8Rv77MA=\n
0
+ created_at: <%= 1.day.ago.to_s :db %>
0
\ No newline at end of file
...
78
79
80
 
 
 
 
 
 
 
 
 
 
81
82
83
...
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
0
@@ -78,6 +78,16 @@ describe Person do
0
     end
0
   end
0
   
0
+ describe "message associations" do
0
+ it "should have sent messages" do
0
+ @person.sent_messages.should_not be_nil
0
+ end
0
+
0
+ it "should have received messages" do
0
+ @person.received_messages.should_not be_nil
0
+ end
0
+ end
0
+
0
   describe "authentication" do
0
     it 'resets password' do
0
       @person.update_attributes(:password => 'newp',

Comments

    No one has commented yet.