|
62 | 62 | # For unit tests in Hanami projects, developers may want to define
|
63 | 63 | # params with symbolized keys.
|
64 | 64 | response = action.call(a: "1", b: "2", c: "3")
|
65 |
| - expect(response.body).to eq([%({:a=>"1", :b=>"2", :c=>"3"})]) |
| 65 | + |
| 66 | + if RUBY_VERSION < "3.4" |
| 67 | + expect(response.body).to eq([%({:a=>"1", :b=>"2", :c=>"3"})]) |
| 68 | + else |
| 69 | + expect(response.body).to eq([%({a: "1", b: "2", c: "3"})]) |
| 70 | + end |
66 | 71 | end
|
67 | 72 | end
|
68 | 73 |
|
69 | 74 | context "in a Rack context" do
|
70 | 75 | it "returns all the params as they are" do
|
71 | 76 | # Rack params are always stringified
|
72 | 77 | response = Rack::MockRequest.new(action).request("PATCH", "?id=23", params: {"x" => {"foo" => "bar"}})
|
73 |
| - expect(response.body).to match(%({:id=>"23", :x=>{:foo=>"bar"}})) |
| 78 | + |
| 79 | + if RUBY_VERSION < "3.4" |
| 80 | + expect(response.body).to eq(%({:id=>"23", :x=>{:foo=>"bar"}})) |
| 81 | + else |
| 82 | + expect(response.body).to eq(%({id: "23", x: {foo: "bar"}})) |
| 83 | + end |
74 | 84 | end
|
75 | 85 | end
|
76 | 86 |
|
77 | 87 | context "with Hanami::Router" do
|
78 | 88 | it "returns all the params as they are" do
|
79 | 89 | # Hanami::Router params are always symbolized
|
80 | 90 | response = action.call("router.params" => {id: "23"})
|
81 |
| - expect(response.body).to eq([%({:id=>"23"})]) |
| 91 | + |
| 92 | + if RUBY_VERSION < "3.4" |
| 93 | + expect(response.body).to eq([%({:id=>"23"})]) |
| 94 | + else |
| 95 | + expect(response.body).to eq([%({id: "23"})]) |
| 96 | + end |
82 | 97 | end
|
83 | 98 | end
|
84 | 99 | end
|
|
92 | 107 | context "in testing mode" do
|
93 | 108 | it "returns only the listed params" do
|
94 | 109 | response = action.call(id: 23, unknown: 4, article: {foo: "bar", tags: [:cool]})
|
95 |
| - expect(response.body).to eq([%({:id=>23, :article=>{:tags=>[:cool]}})]) |
| 110 | + |
| 111 | + if RUBY_VERSION < "3.4" |
| 112 | + expect(response.body).to eq([%({:id=>23, :article=>{:tags=>[:cool]}})]) |
| 113 | + else |
| 114 | + expect(response.body).to eq([%({id: 23, article: {tags: [:cool]}})]) |
| 115 | + end |
96 | 116 | end
|
97 | 117 |
|
98 | 118 | it "removes _csrf_token" do
|
|
104 | 124 | context "in a Rack context" do
|
105 | 125 | it "returns only the listed params" do
|
106 | 126 | response = Rack::MockRequest.new(action).request("PATCH", "?id=23", params: {x: {foo: "bar"}})
|
107 |
| - expect(response.body).to match(%({:id=>23})) |
| 127 | + |
| 128 | + if RUBY_VERSION < "3.4" |
| 129 | + expect(response.body).to match(%({:id=>23})) |
| 130 | + else |
| 131 | + expect(response.body).to match(%({id: 23})) |
| 132 | + end |
108 | 133 | end
|
109 | 134 |
|
110 | 135 | it "removes _csrf_token" do
|
111 | 136 | response = Rack::MockRequest.new(action).request("PATCH", "?id=1", params: {_csrf_token: "def", x: {foo: "bar"}})
|
112 | 137 | expect(response.body).not_to match("_csrf_token")
|
113 |
| - expect(response.body).to match(%(:id=>1)) |
| 138 | + |
| 139 | + if RUBY_VERSION < "3.4" |
| 140 | + expect(response.body).to match(%({:id=>1})) |
| 141 | + else |
| 142 | + expect(response.body).to match(%({id: 1})) |
| 143 | + end |
114 | 144 | end
|
115 | 145 | end
|
116 | 146 |
|
117 | 147 | context "with Hanami::Router" do
|
118 | 148 | it "returns only the listed params" do
|
119 | 149 | response = action.call("router.params" => {id: 23, another: "x"})
|
120 |
| - expect(response.body).to eq([%({:id=>23})]) |
| 150 | + |
| 151 | + if RUBY_VERSION < "3.4" |
| 152 | + expect(response.body).to eq([%({:id=>23})]) |
| 153 | + else |
| 154 | + expect(response.body).to eq([%({id: 23})]) |
| 155 | + end |
121 | 156 | end
|
122 | 157 | end
|
123 | 158 | end
|
|
133 | 168 | context "in testing mode" do
|
134 | 169 | it "returns only the listed params" do
|
135 | 170 | response = action.call(username: "jodosha", unknown: "field")
|
136 |
| - expect(response.body).to eq([%({:username=>"jodosha"})]) |
| 171 | + |
| 172 | + if RUBY_VERSION < "3.4" |
| 173 | + expect(response.body).to eq([%({:username=>"jodosha"})]) |
| 174 | + else |
| 175 | + expect(response.body).to eq([%({username: "jodosha"})]) |
| 176 | + end |
137 | 177 | end
|
138 | 178 | end
|
139 | 179 |
|
140 | 180 | context "in a Rack context" do
|
141 | 181 | it "returns only the listed params" do
|
142 | 182 | response = Rack::MockRequest.new(action).request("PATCH", "?username=jodosha", params: {x: {foo: "bar"}})
|
143 |
| - expect(response.body).to match(%({:username=>"jodosha"})) |
| 183 | + |
| 184 | + if RUBY_VERSION < "3.4" |
| 185 | + expect(response.body).to match(%({:username=>"jodosha"})) |
| 186 | + else |
| 187 | + expect(response.body).to match(%({username: "jodosha"})) |
| 188 | + end |
144 | 189 | end
|
145 | 190 | end
|
146 | 191 |
|
147 | 192 | context "with Hanami::Router" do
|
148 | 193 | it "returns only the listed params" do
|
149 | 194 | response = action.call("router.params" => {username: "jodosha", y: "x"})
|
150 |
| - expect(response.body).to eq([%({:username=>"jodosha"})]) |
| 195 | + |
| 196 | + if RUBY_VERSION < "3.4" |
| 197 | + expect(response.body).to eq([%({:username=>"jodosha"})]) |
| 198 | + else |
| 199 | + expect(response.body).to eq([%({username: "jodosha"})]) |
| 200 | + end |
151 | 201 | end
|
152 | 202 | end
|
153 | 203 | end
|
|
507 | 557 | it "raises error when try to add an error " do
|
508 | 558 | params = klass.new(env: {})
|
509 | 559 |
|
510 |
| - expect { params.errors.add(:book, :code, "is invalid") }.to raise_error(ArgumentError, %(Can't add :book, :code, "is invalid" to {:book=>["is missing"]})) |
| 560 | + if RUBY_VERSION < "3.4" |
| 561 | + expect { params.errors.add(:book, :code, "is invalid") }.to raise_error( |
| 562 | + ArgumentError, |
| 563 | + %(Can't add :book, :code, "is invalid" to {:book=>["is missing"]}) |
| 564 | + ) |
| 565 | + else |
| 566 | + expect { params.errors.add(:book, :code, "is invalid") }.to raise_error( |
| 567 | + ArgumentError, |
| 568 | + %(Can't add :book, :code, "is invalid" to {book: ["is missing"]}) |
| 569 | + ) |
| 570 | + end |
511 | 571 | end
|
512 | 572 | end
|
513 | 573 |
|
|
516 | 576 |
|
517 | 577 | it "uses the params defined in the parent class" do
|
518 | 578 | response = action.call(id: 23, unknown: 4, article: {foo: "bar", tags: [:cool]})
|
519 |
| - expect(response.body).to eq([%({:id=>23, :article=>{:tags=>[:cool]}})]) |
| 579 | + |
| 580 | + if RUBY_VERSION < "3.4" |
| 581 | + expect(response.body).to eq([%({:id=>23, :article=>{:tags=>[:cool]}})]) |
| 582 | + else |
| 583 | + expect(response.body).to eq([%({id: 23, article: {tags: [:cool]}})]) |
| 584 | + end |
520 | 585 | end
|
521 | 586 | end
|
522 | 587 | end
|
0 commit comments