diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 438c3f9c6..5989654ac 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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 diff --git a/app/views/blogs/_blog.html.haml b/app/views/blogs/_blog.html.haml index 2c8ba7b67..366f5ad85 100644 --- a/app/views/blogs/_blog.html.haml +++ b/app/views/blogs/_blog.html.haml @@ -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 diff --git a/app/views/bookmarks/_bookmark.html.haml b/app/views/bookmarks/_bookmark.html.haml index 2a457866a..03fd47c0f 100644 --- a/app/views/bookmarks/_bookmark.html.haml +++ b/app/views/bookmarks/_bookmark.html.haml @@ -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 diff --git a/app/views/friends/show.html.haml b/app/views/friends/show.html.haml index fedc3e2a3..8ca7c8c57 100644 --- a/app/views/friends/show.html.haml +++ b/app/views/friends/show.html.haml @@ -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! diff --git a/app/views/status_messages/_status_message.html.haml b/app/views/status_messages/_status_message.html.haml index 1484b2d9e..0c1e6786f 100644 --- a/app/views/status_messages/_status_message.html.haml +++ b/app/views/status_messages/_status_message.html.haml @@ -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" diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml new file mode 100644 index 000000000..01cfb9999 --- /dev/null +++ b/app/views/users/show.html.haml @@ -0,0 +1 @@ +%h1 user page! diff --git a/spec/controllers/friends_controller_spec.rb b/spec/controllers/friends_controller_spec.rb index 4abbbede7..57d6e87df 100644 --- a/spec/controllers/friends_controller_spec.rb +++ b/spec/controllers/friends_controller_spec.rb @@ -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 diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb new file mode 100644 index 000000000..b4c82c919 --- /dev/null +++ b/spec/helpers/application_helper_spec.rb @@ -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 diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index a7a0919b7..6e5327753 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -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