This repository has been archived by the owner on Feb 8, 2020. It is now read-only.
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
11 changed files
with
190 additions
and
7 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
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,14 @@ | ||
module Web::Controllers::Comments | ||
class Create | ||
include Web::Action | ||
|
||
def initialize(comment_repository: Demo::CommentRepository) | ||
@comment_repository = comment_repository | ||
end | ||
|
||
def call(params) | ||
@comment_repository.create(Demo::Comment.new(params)) | ||
redirect_to "/articles/#{params[:article_id]}" | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require 'kramdown' | ||
|
||
module Web::Presenters | ||
class CommentPresenter | ||
include Lotus::Presenter | ||
|
||
def created_at | ||
super.strftime '%e %b %Y %H:%M' | ||
end | ||
|
||
def body | ||
_raw Kramdown::Document.new(super).to_html | ||
end | ||
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
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,25 @@ | ||
require_relative '../../../spec_helper' | ||
|
||
module Web::Controllers::Comments | ||
describe Create do | ||
let(:comment_repository) { Minitest::Mock.new } | ||
let(:comment) { Demo::Comment.new(params) } | ||
let(:action) { Web::Controllers::Comments::Create.new(comment_repository: comment_repository) } | ||
let(:params) { Hash[article_id: 1, author: 'John', body: 'lorem ipsum'] } | ||
|
||
before do | ||
comment_repository.expect :create, true, [comment] | ||
end | ||
|
||
it 'is redirects to the article' do | ||
response = action.call(params) | ||
assert_equal 302, response[0] | ||
assert_equal '/articles/1', response[1]['Location'] | ||
end | ||
|
||
it 'creates a comment in the repository' do | ||
action.call(params) | ||
comment_repository.verify | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require_relative '../../features_helper' | ||
|
||
describe 'Commenting on articles' do | ||
before do | ||
Demo::ArticleRepository.clear | ||
@article = Demo::ArticleRepository.create( | ||
Demo::Article.new(title: 'Hello, world', body: 'Lorem ipsum') | ||
) | ||
end | ||
|
||
describe 'when there are no comments' do | ||
it 'hides the comments heading' do | ||
visit '/' | ||
click_link 'Hello, world' | ||
assert page.has_no_css?('.comments__heading'), 'there should not have been a comments heading' | ||
end | ||
end | ||
|
||
describe 'when there are comments' do | ||
it 'shows the comment and the total number of comments' do | ||
visit '/' | ||
click_link 'Hello, world' | ||
fill_in 'Name', with: 'John' | ||
fill_in 'Comment', with: 'Nice post!' | ||
click_button 'Submit Comment' | ||
assert page.has_css?('.comments__heading', text: '1 comment'), 'there is no comments heading' | ||
assert page.has_css?('.comment__body', text: 'Nice post!'), 'there is no comment' | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require_relative '../../spec_helper' | ||
|
||
module Web::Presenters | ||
describe CommentPresenter do | ||
let(:comment) { Demo::Comment.new(author: 'John', body: 'lorem ipsum', created_at: Time.new(2015, 2, 1, 12, 30)) } | ||
let(:presenter) { CommentPresenter.new(comment) } | ||
|
||
it 'is a Lotus::Presenter' do | ||
assert_kind_of Lotus::Presenter, presenter | ||
end | ||
|
||
it 'formats the created_at timestamp' do | ||
assert_equal ' 1 Feb 2015 12:30', presenter.created_at, 'created_at formatting is incorrect' | ||
end | ||
|
||
it 'formats the body using markdown' do | ||
assert_equal "<p>lorem ipsum</p>\n", presenter.body, "no markdown was applied to the body" | ||
end | ||
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