Skip to content

Commit

Permalink
Add a helper for comments title
Browse files Browse the repository at this point in the history
  • Loading branch information
GCorbel committed Jun 17, 2012
1 parent 1087e11 commit 9fe4fd6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
7 changes: 7 additions & 0 deletions app/helpers/comment_helper.rb
@@ -0,0 +1,7 @@
module CommentHelper
def comment_title_for(comment)
(comment.user ? comment.user.username : comment.username) +
' - ' +
comment.created_at.strftime('%d/%m/%Y %H:%M')
end
end
4 changes: 1 addition & 3 deletions app/views/comments/_comment.html.erb
@@ -1,8 +1,6 @@
<div id="comment_<%= comment.id %>" class="graybox">
<h2>
<%= comment.user ? comment.user : comment.username %>
-
<%= comment.created_at.strftime('%d/%m/%Y %H:%M') %>
<%= comment_title_for comment %>
</h2>
<div>
<%= markdown comment.message %>
Expand Down
23 changes: 23 additions & 0 deletions spec/helpers/comment_helpers_spec.rb
@@ -0,0 +1,23 @@
describe CommentHelper do
let(:user) { build_stubbed(:user) }
let(:comment) { build_stubbed(:comment, created_at: now) }
let(:now) { DateTime.now }
let(:formatted_now) { now.strftime('%d/%m/%Y %H:%M') }

describe :comment_title do
subject { comment_title_for(comment) }

context 'when there is a user' do
it 'show the title' do
comment.user = user
should == "#{user.username} - #{formatted_now}"
end
end

context 'when there is a username' do
it 'show the title with the username' do
should == "#{comment.username} - #{formatted_now}"
end
end
end
end

0 comments on commit 9fe4fd6

Please sign in to comment.