@@ -32,6 +32,12 @@ def params;
32
32
controller . param! :word , String , transform : :upcase
33
33
expect ( controller . params [ "word" ] ) . to eql ( "FOO" )
34
34
end
35
+
36
+ it "transforms default value" do
37
+ allow ( controller ) . to receive ( :params ) . and_return ( { } )
38
+ controller . param! :word , String , default : "foo" , transform : :upcase
39
+ expect ( controller . params [ "word" ] ) . to eql ( "FOO" )
40
+ end
35
41
end
36
42
37
43
context "with a block" do
@@ -41,6 +47,12 @@ def params;
41
47
expect ( controller . params [ "word" ] ) . to eql ( "foo" )
42
48
end
43
49
50
+ it "transforms default value" do
51
+ allow ( controller ) . to receive ( :params ) . and_return ( { } )
52
+ controller . param! :word , String , default : "foo" , transform : lambda { |n | n . upcase }
53
+ expect ( controller . params [ "word" ] ) . to eql ( "FOO" )
54
+ end
55
+
44
56
it "transforms falsey value" do
45
57
allow ( controller ) . to receive ( :params ) . and_return ( { "foo" => "0" } )
46
58
controller . param! :foo , :boolean , transform : lambda { |n | n ? "bar" : "no bar" }
@@ -54,6 +66,13 @@ def params;
54
66
expect { controller . param! :foo , String , required : true , transform : :upcase } . to raise_error ( RailsParam ::InvalidParameterError , "Parameter foo is required" )
55
67
end
56
68
end
69
+
70
+ context "when param is optional & not present" do
71
+ it "doesn't transform the value" do
72
+ allow ( controller ) . to receive ( :params ) . and_return ( { } )
73
+ expect { controller . param! :foo , String , transform : :upcase } . not_to raise_error
74
+ end
75
+ end
57
76
end
58
77
59
78
describe "default" do
0 commit comments