Permalink
Browse files

Validate comment params

  • Loading branch information...
avdgaag committed Mar 24, 2015
1 parent e1bce61 commit 455fc583184c15a234eb3f1daa0f9f5be9ec5190
Showing with 16 additions and 1 deletion.
  1. +9 −1 apps/web/controllers/comments/create.rb
  2. +7 −0 spec/web/controllers/comments/create_spec.rb
@@ -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
@@ -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.