Skip to content

Spawning Clockfile jobs inside tests #38

Description

@jensb

Hi,
I started using ruby-clock in a Rails project and so far I love it, great job!
I have one question though: Is it possible to directly execute specific Clockfile tasks synchronously, as in 'now'?
I think this would make a lot of sense for integration testing. For example,

# app/models/user.rb
# ...
def self.create_remote_users
   where(state: 'pending').each do |user|
      if MyRemoteApi.create_user(...) ; user.activate! ; end
   end
end

# Clockfile
every '1 minute' do
    # ... more minutely jobs
    User.create_remote_users
end

# tests/integration/user_integration_test.rb
# this should create a User account
# A cronjob then checks for new Users and creates a user profile on a remote system too
test 'does create remote user too' do
   post '/signup', params: {...}
   assert_response :success
   RubyClock.execute_tasks_for.every '1 minute'       # or RubyClock.execute_tasks_for.cron '0 0 0 * *' , or ...
   assert_equal 'success', MyRemoteApi.login_as(...)
end

This way, I can not just check if my async remote APi job works well (this would be a unit test) but also if I call it at the right point and if it is included in the correct cronjob.

Is something like this possible with ruby-clock? If not, do you think it makes sense to implement it?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions