Skip to content

Commit 1c696f4

Browse files
committed
Since rails 6.1.1 changed default behaviour of CRUD response for invalid
attributes - to respond with 422 status, we have to update our scaffold for generating specs for Create and Update with invalid attributes. I updated both generators to check if controller responds with status 422 instead of 200. Applied that change only for rails 6.1.1 and higher
1 parent a785198 commit 1c696f4

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,17 @@
8282
}.to change(<%= class_name %>, :count).by(0)
8383
end
8484
85+
<% if Rails.version.to_f < 6.1 || Rails.version == '6.1.0' %>
8586
it "renders a successful response (i.e. to display the 'new' template)" do
8687
post <%= index_helper %>_url, params: { <%= ns_file_name %>: invalid_attributes }
8788
expect(response).to be_successful
8889
end
90+
<% else %>
91+
it "renders a response with 422 status - unporcessable entity" do
92+
post <%= index_helper %>_url, params: { <%= ns_file_name %>: invalid_attributes }
93+
expect(response.status).to eq(422)
94+
end
95+
<% end %>
8996
end
9097
end
9198

0 commit comments

Comments
 (0)