Skip to content

Commit 01488d8

Browse files
committed
Updated controller template to check http status unprocessable_entity(422) with invalid params in rails 7.0.
1 parent 8f3a295 commit 01488d8

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

lib/generators/rspec/scaffold/templates/controller_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,17 @@
9090
end
9191
9292
context "with invalid params" do
93+
<% if Rails.version.to_f < 7.0 %>
9394
it "returns a success response (i.e. to display the 'new' template)" do
9495
post :create, params: {<%= singular_table_name %>: invalid_attributes}, session: valid_session
9596
expect(response).to be_successful
9697
end
98+
<% else %>
99+
it "renders a response with 422 status (i.e. to display the 'new' template)" do
100+
post :create, params: {<%= singular_table_name %>: invalid_attributes}, session: valid_session
101+
expect(response).to have_http_status(:unprocessable_entity)
102+
end
103+
<% end %>
97104
end
98105
end
99106
@@ -118,11 +125,19 @@
118125
end
119126
120127
context "with invalid params" do
128+
<% if Rails.version.to_f < 7.0 %>
121129
it "returns a success response (i.e. to display the 'edit' template)" do
122130
<%= file_name %> = <%= class_name %>.create! valid_attributes
123131
put :update, params: {id: <%= file_name %>.to_param, <%= singular_table_name %>: invalid_attributes}, session: valid_session
124132
expect(response).to be_successful
125133
end
134+
<% else %>
135+
it "renders a response with 422 status (i.e. to display the 'edit' template)" do
136+
<%= file_name %> = <%= class_name %>.create! valid_attributes
137+
put :update, params: {id: <%= file_name %>.to_param, <%= singular_table_name %>: invalid_attributes}, session: valid_session
138+
expect(response).to have_http_status(:unprocessable_entity)
139+
end
140+
<% end %>
126141
end
127142
end
128143

0 commit comments

Comments
 (0)