RS, IZ, Merged from master

This commit is contained in:
ilya 2010-06-23 20:19:25 -04:00
commit 81157190ac
9 changed files with 96 additions and 30 deletions

View file

@ -59,4 +59,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

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

View file

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

View file

@ -1,16 +1,11 @@
- 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 @friend.posts
%ul#stream
- for post in @friend.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

@ -5,6 +5,7 @@ describe FriendsController do
before do
#TODO(dan) Mocking Warden; this is a temp fix
request.env['warden'] = mock_model(Warden, :authenticate? => @user, :authenticate! => @user)
Factory.create(:user)
@friend = Factory.build(:friend)
end
@ -48,5 +49,12 @@ describe FriendsController do
it 'should have test that a delete removes a friend from the database' do
end
it 'should display a list of a friends posts on their page' do
friend = Factory.create(:friend)
@status_message = Factory.create(:status_message, :person => friend)
get :show, :id => friend.id
response.body.should include @status_message.message
end
end

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

@ -17,20 +17,38 @@ describe Post do
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