Как протестировать следующий пример?
class Post < ActiveRecord::Base
belongs_to :discussion, touch: true
end
Вы можете установить ожидаемое сообщение :
it "should touch the discussion" do
post = Factory.build(:post)
post.discussion.should_receive(:touch)
post.save!
end
В этом примере используется Factory Girl , но вы также можете использовать фикстуры или макеты.
Вы можете имитировать вызов #touch или проверить влияние вашего обратного вызова на него.
it "should touch the discussion" do
original_updated_at = @discussion.updated_at
@post.save!
@post.discussion.updated_at.should_not_be == original_updated_at
end