From ba7d2478170ef23e630e40aec2d6c7d8d0cd1e3b Mon Sep 17 00:00:00 2001 From: Markus Kahl Date: Fri, 30 Jan 2015 13:41:37 +0000 Subject: [PATCH] use IDs in CopyProjectJob; send mail synchronously also moved the job into the workers directory --- app/controllers/copy_projects_controller.rb | 4 ++-- app/{models => workers}/copy_project_job.rb | 16 ++++++++++++---- spec/models/copy_project_job_spec.rb | 4 ++-- 3 files changed, 16 insertions(+), 8 deletions(-) rename app/{models => workers}/copy_project_job.rb (90%) diff --git a/app/controllers/copy_projects_controller.rb b/app/controllers/copy_projects_controller.rb index 543ef3a901..04d30d32e8 100644 --- a/app/controllers/copy_projects_controller.rb +++ b/app/controllers/copy_projects_controller.rb @@ -41,8 +41,8 @@ class CopyProjectsController < ApplicationController @copy_project.safe_attributes = params[:project] if @copy_project.valid? modules = params[:project][:enabled_module_names] || params[:enabled_modules] - copy_project_job = CopyProjectJob.new(User.current, - @project, + copy_project_job = CopyProjectJob.new(User.current.id, + @project.id, params[:project], modules, params[:only], diff --git a/app/models/copy_project_job.rb b/app/workers/copy_project_job.rb similarity index 90% rename from app/models/copy_project_job.rb rename to app/workers/copy_project_job.rb index 1af4b5ef78..d0db25b5d4 100644 --- a/app/models/copy_project_job.rb +++ b/app/workers/copy_project_job.rb @@ -27,8 +27,8 @@ # See doc/COPYRIGHT.rdoc for more details. #++ -class CopyProjectJob < Struct.new(:user, - :source_project, +class CopyProjectJob < Struct.new(:user_id, + :source_project_id, :target_project_params, :enabled_modules, :associations_to_copy, @@ -47,16 +47,24 @@ class CopyProjectJob < Struct.new(:user, end if target_project - UserMailer.delay.copy_project_succeeded(user, source_project, target_project, errors) + UserMailer.copy_project_succeeded(user, source_project, target_project, errors) else target_project_name = target_project_params[:name] - UserMailer.delay.copy_project_failed(user, source_project, target_project_name) + UserMailer.copy_project_failed(user, source_project, target_project_name) end end private + def user + @user ||= User.find user_id + end + + def source_project + @project ||= Project.find source_project_id + end + def create_project_copy(source_project, target_project_params, enabled_modules, diff --git a/spec/models/copy_project_job_spec.rb b/spec/models/copy_project_job_spec.rb index b0c23b3a0d..116c1873a7 100644 --- a/spec/models/copy_project_job_spec.rb +++ b/spec/models/copy_project_job_spec.rb @@ -41,8 +41,8 @@ describe CopyProjectJob, type: :model do let(:target_project) { FactoryGirl.create(:project) } let(:copy_job) { - CopyProjectJob.new user_de, - source_project, + CopyProjectJob.new user_de.id, + source_project.id, target_project, [], # enabled modules [], # associations