Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
31 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |