DG MS; clicking on a person's name redirects to that person's post stream

This commit is contained in:
maxwell 2010-06-23 14:32:51 -07:00
parent a673e48317
commit 9fa26f020e
10 changed files with 89 additions and 34 deletions

View file

@ -7,6 +7,7 @@ class FriendsController < ApplicationController
def show
@friend = Friend.first(:conditions=> {:id => params[:id]})
@friend_posts = @friend.posts
end
def destroy

View file

@ -47,7 +47,7 @@ module ApplicationHelper
end
def mine?(post)
post.owner == User.first.email
post.person == User.first
end
def type_partial(post)
@ -58,4 +58,20 @@ module ApplicationHelper
def how_long_ago(obj)
time_ago_in_words(obj.created_at) + " ago."
end
def person_url(person)
case person.class.to_s
when "Friend"
friend_path(person)
when "User"
user_path(person)
else
"#"
end
end
def link_to_person(person)
link_to person.real_name, person_url(person)
end
end

View file

@ -41,7 +41,6 @@ class Post
yield self
end
protected
def send_to_view

View file

@ -1,6 +1,6 @@
%li.message{:class => ("mine" if mine?(post))}
%span.from
= link_to post.owner, "#"
= link_to_person post.person
%b wrote a new blog post
%br
%b= post.title
@ -8,4 +8,4 @@
= raw post.body
%div.time= link_to "#{time_ago_in_words(post.updated_at)} ago", blog_path(post)
- if mine?(post)
= link_to 'Destroy', blog_path(post), :confirm => 'Are you sure?', :method => :delete
= link_to 'Destroy', blog_path(post), :confirm => 'Are you sure?', :method => :delete

View file

@ -1,6 +1,6 @@
%li.message{:class => ("mine" if mine?(post))}
%span.from
= link_to post.owner, "#"
= link_to_person post.person
%b shared a link
%br
= post.title

View file

@ -1,16 +1,8 @@
- title "Friend"
%h1= "#{@friend.real_name}'s network stream"
%p
%strong Real Name:
= @friend.real_name
%p
%strong Email:
= @friend.email
%p
%strong Url:
= @friend.url
%p
= link_to "Destroy", @friend, :confirm => 'Are you sure?', :method => :delete
|
= link_to "View All", friends_path
- if @posts
%ul#stream
- for post in @posts
= render type_partial(post), :post => post
- else
%h3 no posts to display!

View file

@ -1,6 +1,6 @@
%li.message{:class => ("mine" if mine?(post))}
%span.from
= link_to post.person.real_name, "#"
= link_to_person post.person
= post.message
%div.time
= "#{time_ago_in_words(post.updated_at)} ago"

View file

@ -0,0 +1 @@
%h1 user page!

View file

@ -0,0 +1,28 @@
require File.dirname(__FILE__) + '/../spec_helper'
include ApplicationHelper
describe ApplicationHelper do
before do
@user = Factory.create(:user, :email => "robert@grimm.com")
@friend = Factory.create(:friend)
end
it "should specifiy if a post is not owned user" do
p = Factory.create(:post, :person => @friend)
mine?(p).should be false
end
it "should specifiy if a post is owned current user" do
p = Factory.create(:post, :person => @user)
mine?(p).should be true
end
it "should provide a correct show path for a given friend" do
person_url(@friend).should == "/friends/#{@friend.id}"
end
it "should provide a correct show path for a given user" do
person_url(@user).should == "/users/#{@user.id}"
end
end

View file

@ -28,20 +28,38 @@ describe Post do
end
end
it "should list child types in reverse chronological order" do
Factory.create(:status_message, :message => "puppies", :created_at => Time.now+1)
Factory.create(:bookmark, :title => "Reddit", :link => "http://reddit.com", :created_at => Time.now+2)
Factory.create(:status_message, :message => "kittens", :created_at => Time.now+3)
Factory.create(:blog, :title => "Bears", :body => "Bear's body", :created_at => Time.now+4)
Factory.create(:bookmark, :title => "Google", :link => "http://google.com", :created_at => Time.now+5)
stream = Post.stream
stream.count.should == 5
stream[0].class.should == Bookmark
stream[1].class.should == Blog
stream[2].class.should == StatusMessage
stream[3].class.should == Bookmark
stream[4].class.should == StatusMessage
describe "stream" do
before do
@owner = Factory.create(:user, :email => "robert@grimm.com")
@friend_one = Factory.create(:friend, :email => "some@dudes.com")
@friend_two = Factory.create(:friend, :email => "other@dudes.com")
Factory.create(:status_message, :message => "puppies", :created_at => Time.now+1, :person => @owner)
Factory.create(:bookmark, :title => "Reddit", :link => "http://reddit.com", :created_at => Time.now+2, :person => @friend_one)
Factory.create(:status_message, :message => "kittens", :created_at => Time.now+3, :person => @friend_two)
Factory.create(:blog, :title => "Bears", :body => "Bear's body", :created_at => Time.now+4, :person => @owner)
Factory.create(:bookmark, :title => "Google", :link => "http://google.com", :created_at => Time.now+5, :person => @friend_two)
end
it "should list child types in reverse chronological order" do
stream = Post.stream
stream.count.should == 5
stream[0].class.should == Bookmark
stream[1].class.should == Blog
stream[2].class.should == StatusMessage
stream[3].class.should == Bookmark
stream[4].class.should == StatusMessage
end
it "should get all posts for a specified user" do
friend_posts = @friend_one.posts
friend_posts.count.should == 1
friend_posts = @friend_two.posts
friend_posts.count.should == 2
end
end
end