diff --git a/app/controllers/public/invite_controller.rb b/app/controllers/public/invite_controller.rb index 2fa0b1f..5c448b5 100644 --- a/app/controllers/public/invite_controller.rb +++ b/app/controllers/public/invite_controller.rb @@ -22,7 +22,7 @@ class InviteController < PublicController webmail_import_addresses = params[:webmail_import_addresses] contacts_to_invite = Invitation.join_contacts(manual_import_addresses, webmail_import_addresses) if !contacts_to_invite.empty? - Delayed::Job.enqueue InvitationJob.new(current_user.person.id, contacts_to_invite, params[:mail_template], profile.id, @contact_list.id) + Delayed::Job.enqueue InvitationJob.new(current_user.person.id, contacts_to_invite, params[:mail_template], profile.id, @contact_list.id, locale) session[:notice] = _('Your invitations are being sent.') if profile.person? redirect_to :controller => 'profile', :action => 'friends' diff --git a/lib/invitation_job.rb b/lib/invitation_job.rb index aa5c9cd..a084453 100644 --- a/lib/invitation_job.rb +++ b/lib/invitation_job.rb @@ -1,8 +1,10 @@ -class InvitationJob < Struct.new(:person_id, :contacts_to_invite, :message, :profile_id, :contact_list_id) +class InvitationJob < Struct.new(:person_id, :contacts_to_invite, :message, :profile_id, :contact_list_id, :locale) def perform - person = Person.find(person_id) - profile = Profile.find(profile_id) - Invitation.invite(person, contacts_to_invite, message, profile) - ContactList.find(contact_list_id).destroy + Noosfero.with_locale(locale) do + person = Person.find(person_id) + profile = Profile.find(profile_id) + Invitation.invite(person, contacts_to_invite, message, profile) + ContactList.find(contact_list_id).destroy + end end end diff --git a/test/functional/invite_controller_test.rb b/test/functional/invite_controller_test.rb index cd9225d..b7a8d99 100644 --- a/test/functional/invite_controller_test.rb +++ b/test/functional/invite_controller_test.rb @@ -225,4 +225,12 @@ class InviteControllerTest < ActionController::TestCase assert_redirected_to :action => 'select_address_book' end + should 'set locale in the background job' do + @controller.stubs(:locale).returns('pt') + + contact_list = ContactList.create + post :select_friends, :profile => profile.identifier, :manual_import_addresses => "#{friend.name} <#{friend.email}>", :import_from => "manual", :mail_template => "click: ", :contact_list => contact_list.id + assert_equal 'pt', Delayed::Job.first.payload_object.locale + end + end diff --git a/test/unit/invitation_job_test.rb b/test/unit/invitation_job_test.rb index 604334f..91d1621 100644 --- a/test/unit/invitation_job_test.rb +++ b/test/unit/invitation_job_test.rb @@ -19,4 +19,10 @@ class InvitationJobTest < ActiveSupport::TestCase end end + should 'change locale according to the locale informed' do + job = InvitationJob.new(nil, nil, nil, nil, nil, 'pt') + Noosfero.expects(:with_locale).with('pt') + job.perform + end + end -- libgit2 0.21.2