public-activity / public_activity

Easy activity tracking for models - similar to Github's Public Activity

Home Page:https://github.com/pokonski/public_activity

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Random odd failure when PublicActivity.with_tracking used in Rails app with RSpec

vanboom opened this issue · comments

commented

We have a fairly simple use case that is failing randomly with some sort of order dependency in our RSpec test suite...
The model...

class Post < ActiveRecord::Base
  belongs_to :user
  include PublicActivity::Model
  tracked owner: ->{controller, model){controller.current_user if controller.present?}, recipient: ->(controller, model){model.user}
end

The test...

PublicActivity.with_tracking do
  p = Post.create(user: user)
  expect(p.activities.order(created_at: :asc).last.recipient).to eq user
end

This test randomly fails as if the PublicActivity.with_tracking is not enabling the activity tracking. The test passes when run singularly and when run in our CI suite most of the time, but every now and again with a certan random seed, it will fail deterministically.

We are going to experiment some more with a fork to see if we can track it down and provde more information here, but wanted to open an issue in case someone else has found the same behavior. One suggestion might be to use a mock/stub in the with_tracking function instead of changing the config to isolate the behavior.

Thanks for a great gem!

commented

Oh my, we discovered this elsewhere in our test suite that tests a background worker class, hence the order dependency...

User.public_activity_off

So sorry for the false alarm, the with_tracking method is working perfectly.