blob: b27069140b0aa1ec51e93a63bc61b27fb567a88d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
require 'abstract_unit'
class BooksController < ActionController::Base
def create
params.require(:book).require(:name)
head :ok
end
def update
params.require(:book)
head :ok
end
end
class ActionControllerRequiredParamsTest < ActionController::TestCase
tests BooksController
test "missing required parameters will raise exception" do
assert_raise ActionController::ParameterMissing do
post :create, { magazine: { name: "Mjallo!" } }
end
assert_raise ActionController::ParameterMissing do
post :create, { book: { title: "Mjallo!" } }
end
end
test "empty required parameters will raise an exception" do
assert_raise ActionController::EmptyParameter do
put :update, {book: {}}
end
assert_raise ActionController::EmptyParameter do
put :update, {book: ''}
end
assert_raise ActionController::EmptyParameter do
put :update, {book: nil}
end
end
test "required parameters that are present will not raise" do
post :create, { book: { name: "Mjallo!" } }
assert_response :ok
end
end
|