Merge branch 'master' of github.com:diaspora/diaspora_rails
This commit is contained in:
commit
cda2d9eeab
10 changed files with 104 additions and 1 deletions
14
app/controllers/comments_controller.rb
Normal file
14
app/controllers/comments_controller.rb
Normal 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
|
||||||
9
app/helpers/comments_helper.rb
Normal file
9
app/helpers/comments_helper.rb
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
module CommentsHelper
|
||||||
|
def target
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def text
|
||||||
|
params[:comment][:text]
|
||||||
|
end
|
||||||
|
end
|
||||||
24
app/models/comment.rb
Normal file
24
app/models/comment.rb
Normal 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
|
||||||
|
|
||||||
|
|
@ -8,6 +8,10 @@ class Post
|
||||||
|
|
||||||
key :person_id, ObjectId
|
key :person_id, ObjectId
|
||||||
belongs_to :person, :class_name => 'Person'
|
belongs_to :person, :class_name => 'Person'
|
||||||
|
|
||||||
|
|
||||||
|
many :comments, :class_name => 'Comment', :foreign_key => :post_id
|
||||||
|
|
||||||
timestamps!
|
timestamps!
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,14 @@ class User < Person
|
||||||
devise :database_authenticatable, :registerable,
|
devise :database_authenticatable, :registerable,
|
||||||
:recoverable, :rememberable, :trackable, :validatable
|
: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
|
def do_bad_things
|
||||||
self.password_confirmation = self.password
|
self.password_confirmation = self.password
|
||||||
end
|
end
|
||||||
|
|
|
||||||
4
app/views/comments/_comment.html.haml
Normal file
4
app/views/comments/_comment.html.haml
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
%li.comment
|
||||||
|
= comment.text
|
||||||
|
\---
|
||||||
|
= comment.person.real_name
|
||||||
7
app/views/comments/_new_comment.html.haml
Normal file
7
app/views/comments/_new_comment.html.haml
Normal 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'
|
||||||
|
|
@ -4,6 +4,12 @@
|
||||||
= post.message
|
= post.message
|
||||||
%div.time
|
%div.time
|
||||||
= link_to "#{time_ago_in_words(post.updated_at)} ago", status_message_path(post)
|
= 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)
|
- if mine?(post)
|
||||||
= link_to 'Destroy', status_message_path(post), :confirm => 'Are you sure?', :method => :delete
|
= link_to 'Destroy', status_message_path(post), :confirm => 'Are you sure?', :method => :delete
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,9 @@ Diaspora::Application.routes.draw do |map|
|
||||||
resources :bookmarks
|
resources :bookmarks
|
||||||
resources :friends
|
resources :friends
|
||||||
resources :status_messages
|
resources :status_messages
|
||||||
|
resources :comments
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#routes for devise, not really sure you will need to mess with this in the future, lets put default,
|
#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
|
#non mutable stuff in anohter file
|
||||||
|
|
|
||||||
26
spec/models/comments_spec.rb
Normal file
26
spec/models/comments_spec.rb
Normal 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
|
||||||
Loading…
Reference in a new issue