2017-03-15 9 views
0

Resque로 수행 한 백그라운드 작업 테스트를 작성하는 방법을 이해하는 데 도움이되는 안내서가 있습니까? 백그라운드 작업 테스트의 Resque 오류

내가지고있어 오류입니다 : 내 컨트롤러에서

PortfoliosControllerTest#test_html_destroy_test: 
NoMethodError: undefined method `id' for nil:NilClass 
    test/standard_controller_tests.rb:354:in `block in do_html_destroy' 
    test/standard_controller_tests.rb:353:in `do_html_destroy' 
    test/standard_controller_tests.rb:38:in `block (2 levels) in `standard_controller_tests'` 

Error: 
DCollectionPagesControllerTest#test_html_destroy_test: 
ArgumentError: wrong number of arguments (given 2, expected 1) 
    app/background_jobs/destroy_portal_job.rb:4:in `perform' 
    test/standard_controller_tests.rb:360:in `do_html_destroy' 
    test/standard_controller_tests.rb:38:in `block (2 levels) in standard_controller_tests' 

을, 내가 가진 :

class DestroyPortalJob < BackgroundJobBase 
    @queue = :destroy 

    def self.perform(portal_id) 
    super do 
     interesting_collections.each do |collection| 
     if klass = collection.singularize.camelize.try(:safe_constantize) 
      klass.where(portal_id: portal_id).each do |object| 
      begin 
      @portal.destroy! 
      rescue => e 
      puts "Failed destroy!" 
      end 
      end 
      @portal.destroy! 
      puts "Delete!" 
     end 
     end 
    end 
    end 
end 

그리고 :

def destroy 
portal_slug = params[:id] 
portal = Portal.find_by_slug(portal_slug) 
@portal = Portal.find(portal_slug) 
update_history(@portal) 

# set delete duties to resque 
if @portal.destroy! 
    Resque.enqueue(DestroyPortalJob, @portal.id) 

    flash[:notice] = 'Portal deleted successfully.' 
    redirect_to action: :archive_index 

    update_history(portal) 

elsif @portal == nil 
    flash[:notice] = 'That portal does not exist' 
    redirect_to action: :archive_index 

    end 
end 

것은 그런 다음이 내 백그라운드 작업입니다 그렇다면 내 시험에서 이것이 내가 가진 것입니다 :

def destroy 
portal_slug = params[:id] 
portal = Portal.find_by_slug(portal_slug) 
@portal = Portal.find(portal_slug) 
update_history(@portal) 

# set delete duties to resque 
if @portal.destroy! 
    Resque.enqueue(DestroyPortalJob, @portal.id) 

    flash[:notice] = 'Portal deleted successfully.' 
    redirect_to action: :archive_index 

    update_history(portal) 

elsif @portal == nil 
    flash[:notice] = 'That portal does not exist' 
    redirect_to action: :archive_index 
    end 
end 

도움이나 조언을 주시면 대단히 감사하겠습니다.

답변