Commit 95be646d91be0fc8aa2078d977c11b8f770b4845
1 parent
f7de17d2
Exists in
master
and in
23 other branches
Set a locale in the background tasks
(ActionItem1640)
Showing
4 changed files
with
22 additions
and
6 deletions
Show diff stats
app/controllers/public/invite_controller.rb
| @@ -22,7 +22,7 @@ class InviteController < PublicController | @@ -22,7 +22,7 @@ class InviteController < PublicController | ||
| 22 | webmail_import_addresses = params[:webmail_import_addresses] | 22 | webmail_import_addresses = params[:webmail_import_addresses] |
| 23 | contacts_to_invite = Invitation.join_contacts(manual_import_addresses, webmail_import_addresses) | 23 | contacts_to_invite = Invitation.join_contacts(manual_import_addresses, webmail_import_addresses) |
| 24 | if !contacts_to_invite.empty? | 24 | if !contacts_to_invite.empty? |
| 25 | - Delayed::Job.enqueue InvitationJob.new(current_user.person.id, contacts_to_invite, params[:mail_template], profile.id, @contact_list.id) | 25 | + Delayed::Job.enqueue InvitationJob.new(current_user.person.id, contacts_to_invite, params[:mail_template], profile.id, @contact_list.id, locale) |
| 26 | session[:notice] = _('Your invitations are being sent.') | 26 | session[:notice] = _('Your invitations are being sent.') |
| 27 | if profile.person? | 27 | if profile.person? |
| 28 | redirect_to :controller => 'profile', :action => 'friends' | 28 | redirect_to :controller => 'profile', :action => 'friends' |
lib/invitation_job.rb
| 1 | -class InvitationJob < Struct.new(:person_id, :contacts_to_invite, :message, :profile_id, :contact_list_id) | 1 | +class InvitationJob < Struct.new(:person_id, :contacts_to_invite, :message, :profile_id, :contact_list_id, :locale) |
| 2 | def perform | 2 | def perform |
| 3 | - person = Person.find(person_id) | ||
| 4 | - profile = Profile.find(profile_id) | ||
| 5 | - Invitation.invite(person, contacts_to_invite, message, profile) | ||
| 6 | - ContactList.find(contact_list_id).destroy | 3 | + Noosfero.with_locale(locale) do |
| 4 | + person = Person.find(person_id) | ||
| 5 | + profile = Profile.find(profile_id) | ||
| 6 | + Invitation.invite(person, contacts_to_invite, message, profile) | ||
| 7 | + ContactList.find(contact_list_id).destroy | ||
| 8 | + end | ||
| 7 | end | 9 | end |
| 8 | end | 10 | end |
test/functional/invite_controller_test.rb
| @@ -225,4 +225,12 @@ class InviteControllerTest < ActionController::TestCase | @@ -225,4 +225,12 @@ class InviteControllerTest < ActionController::TestCase | ||
| 225 | assert_redirected_to :action => 'select_address_book' | 225 | assert_redirected_to :action => 'select_address_book' |
| 226 | end | 226 | end |
| 227 | 227 | ||
| 228 | + should 'set locale in the background job' do | ||
| 229 | + @controller.stubs(:locale).returns('pt') | ||
| 230 | + | ||
| 231 | + contact_list = ContactList.create | ||
| 232 | + post :select_friends, :profile => profile.identifier, :manual_import_addresses => "#{friend.name} <#{friend.email}>", :import_from => "manual", :mail_template => "click: <url>", :contact_list => contact_list.id | ||
| 233 | + assert_equal 'pt', Delayed::Job.first.payload_object.locale | ||
| 234 | + end | ||
| 235 | + | ||
| 228 | end | 236 | end |
test/unit/invitation_job_test.rb
| @@ -19,4 +19,10 @@ class InvitationJobTest < ActiveSupport::TestCase | @@ -19,4 +19,10 @@ class InvitationJobTest < ActiveSupport::TestCase | ||
| 19 | end | 19 | end |
| 20 | end | 20 | end |
| 21 | 21 | ||
| 22 | + should 'change locale according to the locale informed' do | ||
| 23 | + job = InvitationJob.new(nil, nil, nil, nil, nil, 'pt') | ||
| 24 | + Noosfero.expects(:with_locale).with('pt') | ||
| 25 | + job.perform | ||
| 26 | + end | ||
| 27 | + | ||
| 22 | end | 28 | end |