Skip to content

Commit 8f3a295

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

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,17 @@
8383
}.to change(<%= class_name %>, :count).by(0)
8484
end
8585
86+
<% if Rails.version.to_f < 7.0 %>
8687
it "renders a successful response (i.e. to display the 'new' template)" do
8788
post <%= index_helper %>_url, params: { <%= singular_table_name %>: invalid_attributes }
8889
expect(response).to be_successful
8990
end
91+
<% else %>
92+
it "renders a response with 422 status (i.e. to display the 'new' template)" do
93+
post <%= index_helper %>_url, params: { <%= singular_table_name %>: invalid_attributes }
94+
expect(response).to have_http_status(:unprocessable_entity)
95+
end
96+
<% end %>
9097
end
9198
end
9299
@@ -112,11 +119,19 @@
112119
end
113120
114121
context "with invalid parameters" do
122+
<% if Rails.version.to_f < 7.0 %>
115123
it "renders a successful response (i.e. to display the 'edit' template)" do
116124
<%= file_name %> = <%= class_name %>.create! valid_attributes
117125
patch <%= show_helper %>, params: { <%= singular_table_name %>: invalid_attributes }
118126
expect(response).to be_successful
119127
end
128+
<% else %>
129+
it "renders a response with 422 status (i.e. to display the 'edit' template)" do
130+
<%= file_name %> = <%= class_name %>.create! valid_attributes
131+
patch <%= show_helper %>, params: { <%= singular_table_name %>: invalid_attributes }
132+
expect(response).to have_http_status(:unprocessable_entity)
133+
end
134+
<% end %>
120135
end
121136
end
122137

0 commit comments

Comments
 (0)