I met a very strange problem when testing a CallBack in model.
I think the codes are very straightforward.
class Download < ActiveRecord::Base
drink = Drink.find(self.drink_id)
drink.download_count += 1
class DownloadTest < ActiveSupport::TestCase
Replace this with your real tests.
@drink = drinks(:one)
@user = users(:quentin)
test “the download count should increase when some one download a
old_download_count = @drink.download_count puts @drink.download_count d = Download.new(:drink_id => @drink.id, :user_id => @user.id,
:stars => 5)
assert_equal old_download_count + 1, @drink.reload.download_count
But the test is always because the last assert.
the @drink’s download_count is not increase…
<6> expected but was
This problem really make me crazy…
Hope you guys can give me some help
thanks a lot…