aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/application
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2012-05-04 05:44:21 -0700
committerJosé Valim <jose.valim@gmail.com>2012-05-04 05:44:21 -0700
commitffad3600ea01cda457b447fafd4d38907f4d0bfb (patch)
tree92eb0e987a128b9d983d139564ec759b8ea2543f /railties/test/application
parent3d9673d8f6fdb5e330b2a276df288834058a5260 (diff)
parent7a6116b633479effe81a820d84aaf29572cc3412 (diff)
downloadrails-ffad3600ea01cda457b447fafd4d38907f4d0bfb.tar.gz
rails-ffad3600ea01cda457b447fafd4d38907f4d0bfb.tar.bz2
rails-ffad3600ea01cda457b447fafd4d38907f4d0bfb.zip
Merge pull request #6153 from carlosantoniodasilva/queue-consumer
Configurable queue consumer
Diffstat (limited to 'railties/test/application')
-rw-r--r--railties/test/application/queue_test.rb39
1 files changed, 36 insertions, 3 deletions
diff --git a/railties/test/application/queue_test.rb b/railties/test/application/queue_test.rb
index 71b0c2bc38..da8bdeed52 100644
--- a/railties/test/application/queue_test.rb
+++ b/railties/test/application/queue_test.rb
@@ -63,7 +63,7 @@ module ApplicationTests
test "in test mode, the queue can be observed" do
app("test")
- job = Class.new(Struct.new(:id)) do
+ job = Struct.new(:id) do
def run
end
end
@@ -79,7 +79,7 @@ module ApplicationTests
assert_equal jobs, Rails.queue.jobs
end
- test "a custom queue implementation can be provided" do
+ def setup_custom_queue
add_to_env_config "production", <<-RUBY
require "my_queue"
config.queue = MyQueue
@@ -94,10 +94,14 @@ module ApplicationTests
RUBY
app("production")
+ end
+
+ test "a custom queue implementation can be provided" do
+ setup_custom_queue
assert_kind_of MyQueue, Rails.queue
- job = Class.new(Struct.new(:id, :ran)) do
+ job = Struct.new(:id, :ran) do
def run
self.ran = true
end
@@ -108,5 +112,34 @@ module ApplicationTests
assert_equal true, job1.ran
end
+
+ test "a custom consumer implementation can be provided" do
+ add_to_env_config "production", <<-RUBY
+ require "my_queue_consumer"
+ config.queue_consumer = MyQueueConsumer
+ RUBY
+
+ app_file "lib/my_queue_consumer.rb", <<-RUBY
+ class MyQueueConsumer < Rails::Queueing::ThreadedConsumer
+ attr_reader :started
+
+ def start
+ @started = true
+ self
+ end
+ end
+ RUBY
+
+ app("production")
+
+ assert_kind_of MyQueueConsumer, Rails.application.queue_consumer
+ assert Rails.application.queue_consumer.started
+ end
+
+ test "default consumer is not used with custom queue implementation" do
+ setup_custom_queue
+
+ assert_nil Rails.application.queue_consumer
+ end
end
end