Understanding assert_difference in Ruby on Rails

后端 未结 4 1285
日久生厌
日久生厌 2021-02-13 02:43

Could anyone please explain what this test code does? :

assert_difference(\'Post.count\') do
    post :create, :post => { :title => \'Hi\', :body => \'T         


        
4条回答
  •  天涯浪人
    2021-02-13 03:43

    This is just checking to make sure that the number of objects for whatever type was specified has increased by 1. (It is an easy way to check to see that an object was added to the DB)

提交回复
热议问题