title: ActiveJob Serialization: no call to deserialize
body: <p>So I'm trying to implement the fairly straightforward example from <a href="http://api.rubyonrails.org/classes/ActiveJob/Core.html#method-i-deserialize" rel="nofollow">here</a> which overrides ActiveJobs' serialize et deserialize methods to save an attempt_number integer between job retries.</p>
  
  <p>I have tried implementing the example into my project, on RAILS 4.2.7.1, which results in the following:</p>
  
  <ul>
  <li><p>A job class that is very bare bone and uses an 'active_elastic_job' queue</p>
  
  <pre><code>class Job &lt; ActiveJob::Base
    queue_as :a_queue
  
    def serialize
      super.merge('attempt_number' =&gt; (@attempt_number || 0) + 1)
    end
  
    def deserialize(job_data)
      super
      @attempt_number = job_data['attempt_number']
    end
  
    rescue_from(Exceptions::NetworkError) do |error|
      logger.info "#{error}"
      if @attempt_number &gt; 10
        logger.info "Drop"
      else
        logger.info "Attempt #{@attempt_number}"
        retry_job wait: 1.hour
      end
    end
  
    def perform(id)
       ...
    end
  end
  </code></pre></li>
  <li><p>A Model that uses the Job on after_create</p>
  
  <pre><code>class Model
    after_create do
      Job.perform_later(self.id)
    end
  end
  </code></pre></li>
  <li><p>And finally a RSpec test aimed to trigger a retry through Webmock</p>
  
  <pre><code>RSpec.describe CategorizerJob, type: :job do
    include ActiveJob::TestHelper
  
    # Some let calls for url, json and create
  
    context 'retry ctx' do
  
     it '404' do
       stub_request(:get, url).to_return(body: json, status: 404)
  
       perform_enqueued_jobs do
         expect_any_instance_of(Job)
         .to receive(:retry_job).with(wait: 1.hour)
         create()
       end
     end
  
  end
  </code></pre></li>
  </ul>
  
  <p>Now here is the issue, it seems the deserialize methods never gets called as I've tried adding a binding.pry in it but to no avail.
  All I get is the below issue when running RSpec which I assume is cause by the missing call to deserialize:</p>
  
  <pre><code>    Failure/Error: if @attempt_number &gt; 10
  
           NoMethodError:
            undefined method `&gt;' for nil:NilClass
  </code></pre>
  
  <p>Anyone could help me with that ? If even with an alternative way to achieve similar functionality.</p>