DG; Post belongs to a Person, and a Person has many Posts. Also, added Person for real this time
This commit is contained in:
parent
9a44578c37
commit
523cb6f15f
4 changed files with 25 additions and 3 deletions
15
app/models/person.rb
Normal file
15
app/models/person.rb
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
class Person
|
||||
include Mongoid::Document
|
||||
include ROXML
|
||||
|
||||
xml_accessor :email
|
||||
xml_accessor :real_name
|
||||
|
||||
field :email
|
||||
field :real_name
|
||||
|
||||
has_many_related :posts
|
||||
|
||||
validates_presence_of :email, :real_name
|
||||
|
||||
end
|
||||
|
|
@ -17,6 +17,10 @@ class Post
|
|||
field :source
|
||||
field :snippet
|
||||
|
||||
|
||||
belongs_to_related :person
|
||||
|
||||
|
||||
before_create :set_defaults
|
||||
|
||||
after_save :send_to_view
|
||||
|
|
@ -50,6 +54,7 @@ class Post
|
|||
self.owner ||= user_email
|
||||
self.source ||= user_email
|
||||
self.snippet ||= user_email
|
||||
self.person ||= User.first
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
%li.message{:class => ("mine" if mine?(post))}
|
||||
%span.from
|
||||
= link_to post.owner, "#"
|
||||
= link_to post.person.real_name, "#"
|
||||
= post.message
|
||||
%div.time
|
||||
= "#{time_ago_in_words(post.updated_at)} ago"
|
||||
|
|
|
|||
|
|
@ -5,12 +5,14 @@ describe Post do
|
|||
Factory.create(:user, :email => "bob@aol.com")
|
||||
end
|
||||
|
||||
|
||||
describe 'defaults' do
|
||||
before do
|
||||
WebSocket.stub!(:update_clients)
|
||||
@post = Factory.create(:post, :owner => nil, :source => nil, :snippet => nil)
|
||||
@post = Factory.create(:post, :person => nil, :owner => nil, :source => nil, :snippet => nil)
|
||||
end
|
||||
|
||||
it "should associate the owner if none is present" do
|
||||
@post.person.should == User.first
|
||||
end
|
||||
|
||||
it "should add an owner if none is present" do
|
||||
|
|
|
|||
Loading…
Reference in a new issue