use IDs in CopyProjectJob; send mail synchronously

also moved the job into the workers directory
pull/2462/head
Markus Kahl 10 years ago
parent bd4f3c4235
commit ba7d247817
  1. 4
      app/controllers/copy_projects_controller.rb
  2. 16
      app/workers/copy_project_job.rb
  3. 4
      spec/models/copy_project_job_spec.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],

@ -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,

@ -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

Loading…
Cancel
Save