From 36d0a532a4e24abcee8cad540bcd072186ba0b26 Mon Sep 17 00:00:00 2001 From: Justin Gordon Date: Sun, 26 Jan 2014 18:41:18 -1000 Subject: [PATCH 1/2] Set Resque.inline to match when setting ResqueSpec.inline This is helpful when using the resque-heroku gem, as it disconnects the database connection unless Resque.inline? per this commit: https://github.com/simple10/resque-heroku/commit/a8395541ee74fbfcf0c07e8109686ea8c92c570f The writer for ResqueSpec.inline = is what sets the value for Resque.inline --- lib/resque_spec.rb | 7 ++++++- spec/resque_spec/helpers_spec.rb | 8 ++++++++ spec/resque_spec_spec.rb | 9 +++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/resque_spec.rb b/lib/resque_spec.rb index 7af346b..3d52462 100644 --- a/lib/resque_spec.rb +++ b/lib/resque_spec.rb @@ -5,9 +5,14 @@ module ResqueSpec extend self - attr_accessor :inline + attr_reader :inline attr_accessor :disable_ext + def inline=(value) + Resque.inline = value + @inline = value + end + def dequeue(queue_name, klass, *args) queue_by_name(queue_name).delete_if do |job| job[:class] == klass.to_s && args.empty? || job[:args] == args diff --git a/spec/resque_spec/helpers_spec.rb b/spec/resque_spec/helpers_spec.rb index 191e623..536a856 100644 --- a/spec/resque_spec/helpers_spec.rb +++ b/spec/resque_spec/helpers_spec.rb @@ -89,6 +89,14 @@ end ResqueSpec.inline.should eq status end + + it "sets Resque.inline as #{status} when inside the block" do + ResqueSpec.inline = status + with_resque do + Resque.inline.should eq true + end + Resque.inline.should eq status + end end end end diff --git a/spec/resque_spec_spec.rb b/spec/resque_spec_spec.rb index d32eb0d..642338c 100644 --- a/spec/resque_spec_spec.rb +++ b/spec/resque_spec_spec.rb @@ -77,6 +77,10 @@ }.not_to change(NameFromClassMethod, :invocations) end + it "sets Resque.inline to false" do + expect(Resque.inline).to be_false + end + it "does not change the behavior of enqueue" do ResqueSpec.enqueue(:queue_name, NameFromClassMethod, 1) ResqueSpec.queue_by_name(:queue_name).should include({ class: NameFromClassMethod.to_s, args: [1] }) @@ -92,6 +96,10 @@ }.to change(NameFromClassMethod, :invocations).by(1) end + it "sets Resque.inline to true" do + expect(Resque.inline).to be_true + end + it "does not enqueue" do ResqueSpec.enqueue(:queue_name, NameFromClassMethod, 1) ResqueSpec.queue_by_name(:queue_name).should be_empty @@ -279,6 +287,7 @@ ResqueSpec.inline = true ResqueSpec.reset! ResqueSpec.inline.should be_false + Resque.inline.should be_false end end end From 59ed2b9547b461bac4824427f64dfd7ba7e23726 Mon Sep 17 00:00:00 2001 From: Justin Gordon Date: Sun, 26 Jan 2014 19:58:51 -1000 Subject: [PATCH 2/2] Set Resque.inline to true when performing a job. This ensures that resque-heroku does not close the connection. --- lib/resque_spec.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/resque_spec.rb b/lib/resque_spec.rb index 3d52462..d24118d 100644 --- a/lib/resque_spec.rb +++ b/lib/resque_spec.rb @@ -85,7 +85,10 @@ def new_job(queue_name, payload) end def perform(queue_name, payload) + original = Resque.inline + Resque.inline = true new_job(queue_name, payload).perform + Resque.inline = original end def perform_or_store(queue_name, payload)