From 08f57bfb8f46e9f521b7d324fc47fe00d93f42bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Fri, 12 Oct 2012 14:42:26 -0300 Subject: [PATCH] Move the TestQueue tests to the proper file --- .../test/queueing/test_queue_test.rb | 44 +++++++++++++++++ railties/test/application/queue_test.rb | 47 ------------------- 2 files changed, 44 insertions(+), 47 deletions(-) diff --git a/activesupport/test/queueing/test_queue_test.rb b/activesupport/test/queueing/test_queue_test.rb index e398a48beaf99..451fb68d3ec31 100644 --- a/activesupport/test/queueing/test_queue_test.rb +++ b/activesupport/test/queueing/test_queue_test.rb @@ -99,4 +99,48 @@ def test_drain assert job.ran?, "The job runs synchronously when the queue is drained" assert_equal job.thread_id, Thread.current.object_id end + + class IdentifiableJob + def initialize(id) + @id = id + end + + def ==(other) + other.same_id?(@id) + end + + def same_id?(other_id) + other_id == @id + end + + def run + end + end + + def test_queue_can_be_observed + jobs = (1..10).map do |id| + IdentifiableJob.new(id) + end + + jobs.each do |job| + @queue.push job + end + + assert_equal jobs, @queue.jobs + end + + def test_adding_an_unmarshallable_job + anonymous_class_instance = Struct.new(:run).new + + assert_raises TypeError do + @queue.push anonymous_class_instance + end + end + + def test_attempting_to_add_a_reference_to_itself + job = {reference: @queue} + assert_raises TypeError do + @queue.push job + end + end end diff --git a/railties/test/application/queue_test.rb b/railties/test/application/queue_test.rb index 5e7b938cbb8a1..58173afc69595 100644 --- a/railties/test/application/queue_test.rb +++ b/railties/test/application/queue_test.rb @@ -69,45 +69,6 @@ def ran? refute job.ran_in_different_thread?, "Expected job to run in the same thread" end - class IdentifiableJob - def initialize(id) - @id = id - end - - def ==(other) - other.same_id?(@id) - end - - def same_id?(other_id) - other_id == @id - end - - def run - end - end - - test "in test mode, the queue can be observed" do - app("test") - - jobs = (1..10).map do |id| - IdentifiableJob.new(id) - end - - jobs.each do |job| - Rails.queue.push job - end - - assert_equal jobs, Rails.queue.jobs - end - - test "in test mode, adding an unmarshallable job will raise an exception" do - app("test") - anonymous_class_instance = Struct.new(:run).new - assert_raises TypeError do - Rails.queue.push anonymous_class_instance - end - end - test "attempting to marshal a queue will raise an exception" do app("test") assert_raises TypeError do @@ -115,14 +76,6 @@ def run end end - test "attempting to add a reference to itself to the queue will raise an exception" do - app("test") - job = {reference: Rails.queue} - assert_raises TypeError do - Rails.queue.push job - end - end - def setup_custom_queue add_to_env_config "production", <<-RUBY require "my_queue"