Skip to content
This repository has been archived by the owner on Feb 8, 2020. It is now read-only.

Commit

Permalink
Validate comment params
Browse files Browse the repository at this point in the history
  • Loading branch information
avdgaag committed Mar 24, 2015
1 parent e1bce61 commit 455fc58
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
10 changes: 9 additions & 1 deletion apps/web/controllers/comments/create.rb
Expand Up @@ -2,12 +2,20 @@ module Web::Controllers::Comments
class Create
include Web::Action

params do
param :article_id, presence: true
param :author, presence: true
param :body, presence: true
end

def initialize(comment_repository: Demo::CommentRepository)
@comment_repository = comment_repository
end

def call(params)
@comment_repository.create(Demo::Comment.new(params))
if params.valid?
@comment_repository.create(Demo::Comment.new(params))
end
redirect_to "/articles/#{params[:article_id]}"
end
end
Expand Down
7 changes: 7 additions & 0 deletions spec/web/controllers/comments/create_spec.rb
Expand Up @@ -21,5 +21,12 @@ module Web::Controllers::Comments
action.call(params)
comment_repository.verify
end

it 'does not create a comment when a parameter is missing' do
action.call({})
assert_raises(MockExpectationError, 'create should not have been called') do
comment_repository.verify
end
end
end
end

0 comments on commit 455fc58

Please sign in to comment.