Skip to content

Commit

Permalink
add article_decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
hstoebel committed Sep 12, 2019
1 parent 008f624 commit d180230
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions decorator/app/decorators/article_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
class ArticleDecorator < BaseDecorator
# returns a humanized string describing how long ago the article was published
delegate_methods :title
delegate_methods :published_at
include ActionView::Helpers::DateHelper
def age
"Published #{time_ago_in_words(object.published_at)} ago"
"Published #{time_ago_in_words(published_at)} ago"
end
end
6 changes: 5 additions & 1 deletion decorator/spec/decorators/article_decorator_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
require 'rails_helper'

RSpec.describe ArticleDecorator, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
it 'exposes the age of the article in human readable format' do
decorated = article.decorate

expect(decorated.age).to eq('Published 1 day ago')
end
end

0 comments on commit d180230

Please sign in to comment.