2 years ago
#32294
Jerome
Testing unprocessable_entity in standard rails framework
With the goal of getting coverage for a line that,
if the object cannot be saved
render :new, status: :unprocessable_entity
writing a test, for a class where Post belongs_to :user
, such as
assert_no_difference "Post.count" do
post posts_path, params: { post: { user_id: nil } }
end
assert_response :unprocessable_entity
will in practice never reach the response stage as ActiveRecord::RecordInvalid:
will be invoked beforehand.
A block test assert_response :unprocessable_entity do
generates
NoMethodError: undefined method 'response_code' for nil:NilClass
This test appears somewhat moot because it would be covered upstream by a validity test. Still, the curiosity of possibly bypassing the validation test interrupt is strong...
Can unprocessable_entity be tested under standard rails framework?
ruby-on-rails
minitest
0 Answers
Your Answer