[Git][noosfero/noosfero][master] 2 commits: CommentHandler delayed job saves the context locale
Joenio Costa
gitlab at mg.gitlab.com
Mon May 30 14:23:48 BRT 2016
Joenio Costa pushed to branch master at Noosfero / noosfero
Commits:
7fdd7fbf by Gabriel Silva at 2016-05-23T20:22:02+00:00
CommentHandler delayed job saves the context locale
Signed-off-by: Gabriel Silva <gabriel93.silva at gmail.com>
- - - - -
5bac7a05 by Joenio Costa at 2016-05-30T17:23:32+00:00
Merge branch 'delayed_job_locale' into 'master'
CommentHandler delayed job saves the context locale
Delayed jobs didn't have access to the correct locale, and the templates were not being translated. Saving the current locale in the job during the creation solves the problem.
See merge request !942
- - - - -
2 changed files:
- app/models/comment_handler.rb
- test/unit/comment_handler_test.rb
Changes:
=====================================
app/models/comment_handler.rb
=====================================
--- a/app/models/comment_handler.rb
+++ b/app/models/comment_handler.rb
@@ -1,8 +1,16 @@
-class CommentHandler < Struct.new(:comment_id, :method)
+class CommentHandler < Struct.new(:comment_id, :method, :locale)
+ def initialize(*args)
+ super
+ self.locale ||= FastGettext.locale
+ end
def perform
+ saved_locale = FastGettext.locale
+ FastGettext.locale = locale
+
comment = Comment.find(comment_id)
comment.send(method)
+ FastGettext.locale = saved_locale
rescue ActiveRecord::RecordNotFound
# just ignore non-existing comments
end
=====================================
test/unit/comment_handler_test.rb
=====================================
--- a/test/unit/comment_handler_test.rb
+++ b/test/unit/comment_handler_test.rb
@@ -21,4 +21,14 @@ class CommentHandlerTest < ActiveSupport::TestCase
handler.perform
end
+ should 'save locale from creation context and not change current locale' do
+ FastGettext.stubs(:locale).returns("pt")
+ handler = CommentHandler.new(5, :whatever_method)
+
+ FastGettext.stubs(:locale).returns("en")
+ assert_equal "pt", handler.locale
+
+ handler.perform
+ assert_equal "en", FastGettext.locale
+ end
end
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/dffe0249dbd4df0d830596026cf6e454709a4da2...5bac7a05a76d1a38dbd733deca77c1e308c3c408
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20160530/23e441aa/attachment-0001.html>
More information about the Noosfero-dev
mailing list