DG MS; clicking on a person's name redirects to that person's post stream
This commit is contained in:
parent
a673e48317
commit
9fa26f020e
10 changed files with 89 additions and 34 deletions
|
|
@ -7,6 +7,7 @@ class FriendsController < ApplicationController
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@friend = Friend.first(:conditions=> {:id => params[:id]})
|
@friend = Friend.first(:conditions=> {:id => params[:id]})
|
||||||
|
@friend_posts = @friend.posts
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ module ApplicationHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def mine?(post)
|
def mine?(post)
|
||||||
post.owner == User.first.email
|
post.person == User.first
|
||||||
end
|
end
|
||||||
|
|
||||||
def type_partial(post)
|
def type_partial(post)
|
||||||
|
|
@ -58,4 +58,20 @@ module ApplicationHelper
|
||||||
def how_long_ago(obj)
|
def how_long_ago(obj)
|
||||||
time_ago_in_words(obj.created_at) + " ago."
|
time_ago_in_words(obj.created_at) + " ago."
|
||||||
end
|
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
|
end
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,6 @@ class Post
|
||||||
yield self
|
yield self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def send_to_view
|
def send_to_view
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
%li.message{:class => ("mine" if mine?(post))}
|
%li.message{:class => ("mine" if mine?(post))}
|
||||||
%span.from
|
%span.from
|
||||||
= link_to post.owner, "#"
|
= link_to_person post.person
|
||||||
%b wrote a new blog post
|
%b wrote a new blog post
|
||||||
%br
|
%br
|
||||||
%b= post.title
|
%b= post.title
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
%li.message{:class => ("mine" if mine?(post))}
|
%li.message{:class => ("mine" if mine?(post))}
|
||||||
%span.from
|
%span.from
|
||||||
= link_to post.owner, "#"
|
= link_to_person post.person
|
||||||
%b shared a link
|
%b shared a link
|
||||||
%br
|
%br
|
||||||
= post.title
|
= post.title
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,8 @@
|
||||||
- title "Friend"
|
%h1= "#{@friend.real_name}'s network stream"
|
||||||
|
|
||||||
%p
|
- if @posts
|
||||||
%strong Real Name:
|
%ul#stream
|
||||||
= @friend.real_name
|
- for post in @posts
|
||||||
%p
|
= render type_partial(post), :post => post
|
||||||
%strong Email:
|
- else
|
||||||
= @friend.email
|
%h3 no posts to display!
|
||||||
%p
|
|
||||||
%strong Url:
|
|
||||||
= @friend.url
|
|
||||||
|
|
||||||
%p
|
|
||||||
= link_to "Destroy", @friend, :confirm => 'Are you sure?', :method => :delete
|
|
||||||
|
|
|
||||||
= link_to "View All", friends_path
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
%li.message{:class => ("mine" if mine?(post))}
|
%li.message{:class => ("mine" if mine?(post))}
|
||||||
%span.from
|
%span.from
|
||||||
= link_to post.person.real_name, "#"
|
= link_to_person post.person
|
||||||
= post.message
|
= post.message
|
||||||
%div.time
|
%div.time
|
||||||
= "#{time_ago_in_words(post.updated_at)} ago"
|
= "#{time_ago_in_words(post.updated_at)} ago"
|
||||||
|
|
|
||||||
1
app/views/users/show.html.haml
Normal file
1
app/views/users/show.html.haml
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
%h1 user page!
|
||||||
28
spec/helpers/application_helper_spec.rb
Normal file
28
spec/helpers/application_helper_spec.rb
Normal 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
|
||||||
|
|
@ -28,13 +28,21 @@ describe Post do
|
||||||
end
|
end
|
||||||
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)
|
|
||||||
|
|
||||||
|
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 = Post.stream
|
||||||
stream.count.should == 5
|
stream.count.should == 5
|
||||||
stream[0].class.should == Bookmark
|
stream[0].class.should == Bookmark
|
||||||
|
|
@ -43,5 +51,15 @@ describe Post do
|
||||||
stream[3].class.should == Bookmark
|
stream[3].class.should == Bookmark
|
||||||
stream[4].class.should == StatusMessage
|
stream[4].class.should == StatusMessage
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue