1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionpack/test/controller/required_params_test.rb

28 lines
691 B
Ruby
Raw Normal View History

require 'abstract_unit'
class BooksController < ActionController::Base
def create
params.require(:book).require(:name)
head :ok
end
end
class ActionControllerRequiredParamsTest < ActionController::TestCase
tests BooksController
test "missing required parameters will raise exception" do
assert_raise ActionController::ParameterMissing do
2013-01-15 19:07:13 -05:00
post :create, { magazine: { name: "Mjallo!" } }
end
assert_raise ActionController::ParameterMissing do
2013-01-15 19:07:13 -05:00
post :create, { book: { title: "Mjallo!" } }
end
end
test "required parameters that are present will not raise" do
post :create, { book: { name: "Mjallo!" } }
assert_response :ok
end
end