From 5a2745ee71bac406d0cdb91b6c738a85d9f04aff Mon Sep 17 00:00:00 2001 From: evazion Date: Sat, 1 Jul 2017 12:46:47 -0500 Subject: [PATCH] Fix post replacement controller test. Broken in 27aa9fe. Delayed jobs have to be enabled when creating a replacement, otherwise replacement will try to immediately delete the existing files, which fails because they're still in use. --- test/functional/post_replacements_controller_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/functional/post_replacements_controller_test.rb b/test/functional/post_replacements_controller_test.rb index 2d6823c45..d68cfd17f 100644 --- a/test/functional/post_replacements_controller_test.rb +++ b/test/functional/post_replacements_controller_test.rb @@ -3,6 +3,8 @@ require 'test_helper' class PostReplacementsControllerTest < ActionController::TestCase context "The post replacements controller" do setup do + Delayed::Worker.delay_jobs = true # don't delete the old images right away + @user = FactoryGirl.create(:user, can_approve_posts: true, created_at: 1.month.ago) CurrentUser.user = @user CurrentUser.ip_addr = "127.0.0.1" @@ -11,6 +13,10 @@ class PostReplacementsControllerTest < ActionController::TestCase @post_replacement = FactoryGirl.create(:post_replacement, post_id: @post.id) end + teardown do + Delayed::Worker.delay_jobs = false + end + context "create action" do should "render" do params = { @@ -24,6 +30,10 @@ class PostReplacementsControllerTest < ActionController::TestCase assert_difference("@post.replacements.size") do post :create, params, { user_id: @user.id } @post.reload + + Timecop.travel(Time.now + PostReplacement::DELETION_GRACE_PERIOD + 1.day) do + Delayed::Worker.new.work_off + end end assert_response :success