Merge branch 'master' of github.com:diaspora/diaspora_rails

This commit is contained in:
ilya 2010-06-26 02:08:34 -04:00
commit cda2d9eeab
10 changed files with 104 additions and 1 deletions

View file

@ -0,0 +1,14 @@
class CommentsController < ApplicationController
before_filter :authenticate_user!
def create
target = Post.first(:id => params[:comment][:post_id])
text = params[:comment][:text]
if current_user.comment text, :on => target
render :text => "Woo!"
else
render :text => "Boo!"
end
end
end

View file

@ -0,0 +1,9 @@
module CommentsHelper
def target
end
def text
params[:comment][:text]
end
end

24
app/models/comment.rb Normal file
View file

@ -0,0 +1,24 @@
class Comment
include MongoMapper::Document
include ROXML
xml_accessor :text
key :text, String
key :target, String
timestamps!
key :post_id, ObjectId
belongs_to :post, :class_name => "Post"
key :person_id, ObjectId
belongs_to :person, :class_name => "Person"
def ==(other)
(self.message == other.message) && (self.person.email == other.person.email)
end
end

View file

@ -8,6 +8,10 @@ class Post
key :person_id, ObjectId
belongs_to :person, :class_name => 'Person'
many :comments, :class_name => 'Comment', :foreign_key => :post_id
timestamps!

View file

@ -8,8 +8,14 @@ class User < Person
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
before_validation :do_bad_things
def comment(text, options = {})
raise "Comment on what, motherfucker?" unless options[:on]
Comment.new(:person_id => self.id, :text => text, :post => options[:on]).save
end
before_validation :do_bad_things
def do_bad_things
self.password_confirmation = self.password
end

View file

@ -0,0 +1,4 @@
%li.comment
= comment.text
\---
= comment.person.real_name

View file

@ -0,0 +1,7 @@
= form_for Comment.new, :remote => true do |f|
= f.error_messages
%p
/= f.label :message
= f.text_field :text, :value => "dislike!"
= f.hidden_field :post_id, :value => post.id
= f.submit 'comment', :class => 'button'

View file

@ -4,6 +4,12 @@
= post.message
%div.time
= link_to "#{time_ago_in_words(post.updated_at)} ago", status_message_path(post)
%div.comments
= render "comments/new_comment", :post => post
%ul.comment_set
- for comment in post.comments
= render "comments/comment", :comment => comment
- if mine?(post)
= link_to 'Destroy', status_message_path(post), :confirm => 'Are you sure?', :method => :delete

View file

@ -3,6 +3,9 @@ Diaspora::Application.routes.draw do |map|
resources :bookmarks
resources :friends
resources :status_messages
resources :comments
#routes for devise, not really sure you will need to mess with this in the future, lets put default,
#non mutable stuff in anohter file

View file

@ -0,0 +1,26 @@
require 'spec_helper'
describe Comment do
describe "user" do
before do
@user = Factory.create :user
end
it "should be able to comment on his own status" do
status = Factory.create(:status_message, :person => @user)
status.comments.should == []
@user.comment "Yeah, it was great", :on => status
StatusMessage.first.comments.first.text.should == "Yeah, it was great"
end
it "should be able to comment on a friend's status" do
friend = Factory.create :friend
status = Factory.create(:status_message, :person => @friend)
@user.comment "sup dog", :on => status
StatusMessage.first.comments.first.text.should == "sup dog"
StatusMessage.first.comments.first.person.should == @user
end
end
end