Skip to content

Commit 4ccc002

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.
1 parent a785198 commit 4ccc002

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@
8282
}.to change(<%= class_name %>, :count).by(0)
8383
end
8484
85-
it "renders a successful response (i.e. to display the 'new' template)" do
85+
it "renders a response with 422 status - unprocessable entity" do
8686
post <%= index_helper %>_url, params: { <%= ns_file_name %>: invalid_attributes }
87-
expect(response).to be_successful
87+
expect(response.status).to eq(422)
8888
end
8989
end
9090
end
@@ -111,10 +111,10 @@
111111
end
112112
113113
context "with invalid parameters" do
114-
it "renders a successful response (i.e. to display the 'edit' template)" do
114+
it "renders a response with 422 status - unprocessable entity" do
115115
<%= file_name %> = <%= class_name %>.create! valid_attributes
116116
patch <%= show_helper.tr('@', '') %>, params: { <%= singular_table_name %>: invalid_attributes }
117-
expect(response).to be_successful
117+
expect(response.status).to eq(422)
118118
end
119119
end
120120
end

0 commit comments

Comments
 (0)