From abde4c9b0aa96cee0648e0b3dbf2d607ccf49fbb Mon Sep 17 00:00:00 2001 From: Carol Nichols Date: Fri, 23 Nov 2012 21:46:14 -0500 Subject: [PATCH] Fixes Issue #548 and #731. Handles cases where author is nil and that causes errors in the view. I don't know how update authors get to be nil, but here we are. --- app/views/updates/_list.html.haml | 22 +++++++++++++--------- test/acceptance/update_test.rb | 17 +++++++++++++++++ 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/app/views/updates/_list.html.haml b/app/views/updates/_list.html.haml index 9e8709be..3dd5cbd3 100644 --- a/app/views/updates/_list.html.haml +++ b/app/views/updates/_list.html.haml @@ -6,14 +6,15 @@ - unless defined?(no_highlight) and no_highlight - mine = current_user.nil? ? false : (update.author.user == current_user) - mentioned = current_user.nil? ? false : update.mentioned?(current_user.username) - %li.update.hentry.message{:class => (mentioned ? "mention " : "") + (mine ? "mine " : ""), :id => "update-#{update.id}", "data-id" => update.id, "data-name" => update.author.fully_qualified_name} - .author.vcard - %a.url{:href => update.author.url, :rel => "user"} - = AuthorDecorator.decorate(update.author).avatar - %span.fn - %a.url{:href => update.author.url} - = update.author.display_name - (#{update.author.username}) + %li.update.hentry.message{:class => (mentioned ? "mention " : "") + (mine ? "mine " : ""), :id => "update-#{update.id}", "data-id" => update.id, "data-name" => update.author ? update.author.fully_qualified_name : ""} + - if update.author + .author.vcard + %a.url{:href => update.author.url, :rel => "user"} + = AuthorDecorator.decorate(update.author).avatar + %span.fn + %a.url{:href => update.author.url} + = update.author.display_name + (#{update.author.username}) .entry-content %span.message-text != update.to_html @@ -25,7 +26,10 @@ %span.in-reply %a{:href => "/updates/#{update.referral.id}"} in reply to - %span.name= update.referral.author.username + - if update.referral.author + %span.name= update.referral.author.username + - else + an update - elsif !update.referral_url.nil? %span.in-reply %a{:href => update.referral_url} diff --git a/test/acceptance/update_test.rb b/test/acceptance/update_test.rb index 20593ccf..57ae7a5f 100644 --- a/test/acceptance/update_test.rb +++ b/test/acceptance/update_test.rb @@ -106,6 +106,23 @@ end end + it "shows an update in reply to another update that has a nil author" do + # Not sure how this happens, but it does. author_id exists but the + # associated author does not. + update = Fabricate(:update, :author_id => "999999") + + update2 = Fabricate(:update) + update2.referral_id = update.id + update2.save + + visit "/updates" + + within "#page" do + text.must_include update2.text + text.must_include update.text + end + end + describe "update with hashtag" do it "creates a working hashtag link" do log_in_as_some_user