title: RSpec double as ActiveJob argument
body: <p>I need to test a class that submits an ActiveJob using <code>perform_later</code> with RSpec doubles as arguments</p>
  
  <p>My class does at some point</p>
  
  <pre><code>def register_event!
      MyJob \
      .set(wait_until: event.end_date + 1.day) \
      .perform_later(
        event: event,
        reviewer: event.random_participant,
      )
  </code></pre>
  
  <p>The associated RSpec test </p>
  
  <pre><code>let(:event) { create(:event, participants: [participant_double]) }
  let(:participant_double) { global_id_instance_double(User) }
  let(:job_params) { event: event, reviewer: participant_double }
  
  describe MyClass do 
    it 'creates a Job' do
      ActiveJob::Base.queue_adapter = :test
      expect { subject.register_event! } \
      .to have_enqueued_job(MyJob) \
      .at(event.end_date) \
      .with(**job_params)
    end  
  </code></pre>
  
  <p>I get an error </p>
  
  <pre><code>ActiveJob::DeserializationError:
     Error while trying to deserialize arguments: undefined method `find' for RSpec::Mocks::InstanceVerifyingDouble:Class
   # /Users/Cyril/.rvm/gems/ruby-2.3.3/gems/globalid-0.4.0/lib/global_id/locator.rb:130:in `locate'
   # /Users/Cyril/.rvm/gems/ruby-2.3.3/gems/globalid-0.4.0/lib/global_id/locator.rb:155:in `block in locate'
   # /Users/Cyril/.rvm/gems/ruby-2.3.3/gems/globalid-0.4.0/lib/global_id/locator.rb:167:in `unscoped'
   # /Users/Cyril/.rvm/gems/ruby-2.3.3/gems/globalid-0.4.0/lib/global_id/locator.rb:155:in `locate'
   # /Users/Cyril/.rvm/gems/ruby-2.3.3/gems/globalid-0.4.0/lib/global_id/locator.rb:17:in `locate'
   # /Users/Cyril/.rvm/gems/ruby-2.3.3/gems/activejob-5.0.2/lib/active_job/arguments.rb:111:in `deserialize_global_id'
   # /Users/Cyril/.rvm/gems/ruby-2.3.3/gems/activejob-5.0.2/lib/active_job/arguments.rb:97:in `deserialize_argument'
   # /Users/Cyril/.rvm/gems/ruby-2.3.3/gems/activejob-5.0.2/lib/active_job/arguments.rb:121:in `block in deserialize_hash'
   # /Users/Cyril/.rvm/gems/ruby-2.3.3/gems/activesupport-5.0.2/lib/active_support/core_ext/hash/transform_values.rb:16:in `block in transform_values'
   # /Users/Cyril/.rvm/gems/ruby-2.3.3/gems/activesupport-5.0.2/lib/active_support/core_ext/hash/transform_values.rb:15:in `each'
   # /Users/Cyril/.rvm/gems/ruby-2.3.3/gems/activesupport-5.0.2/lib/active_support/core_ext/hash/transform_values.rb:15:in `transform_values'
   # /Users/Cyril/.rvm/gems/ruby-2.3.3/gems/activejob-5.0.2/lib/active_job/arguments.rb:121:in `deserialize_hash'
   # /Users/Cyril/.rvm/gems/ruby-2.3.3/gems/activejob-5.0.2/lib/active_job/arguments.rb:99:in `deserialize_argument'
   # /Users/Cyril/.rvm/gems/ruby-2.3.3/gems/activejob-5.0.2/lib/active_job/arguments.rb:51:in `block in deserialize'
   # /Users/Cyril/.rvm/gems/ruby-2.3.3/gems/activejob-5.0.2/lib/active_job/arguments.rb:51:in `map'
   # /Users/Cyril/.rvm/gems/ruby-2.3.3/gems/activejob-5.0.2/lib/active_job/arguments.rb:51:in `deserialize'
   # ./spec/services/event_booker_service_specs.rb:72:in `block (4 levels) in &lt;top (required)&gt;'
   # /Users/Cyril/.rvm/gems/ruby-2.3.3/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:287:in `load'
   # /Users/Cyril/.rvm/gems/ruby-2.3.3/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:287:in `block in load'
   # /Users/Cyril/.rvm/gems/ruby-2.3.3/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:259:in `load_dependency'
   # /Users/Cyril/.rvm/gems/ruby-2.3.3/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:287:in `load'
   # /Users/Cyril/.rvm/gems/ruby-2.3.3/gems/spring-commands-rspec-1.0.4/lib/spring/commands/rspec.rb:18:in `call'
  </code></pre>
  
  <p>*Note that the line corrsponding to <code>event_booker_service_specs</code> points to the code extract <code>expect { subject.register_event! } \</code> mentionned above</p>
  
  <p>For information I'm using the code for GlobalID found there : <a href="https://gist.github.com/tylerhunt/3decf5a32873625110c1" rel="nofollow noreferrer">https://gist.github.com/tylerhunt/3decf5a32873625110c1</a></p>