]> source.dussan.org Git - redmine.git/commitdiff
Use attribute writers instead of before_create callback to normalize comments and...
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 18 Jan 2015 11:43:58 +0000 (11:43 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 18 Jan 2015 11:43:58 +0000 (11:43 +0000)
Unlike other adapters, SQLite raises Encoding::UndefinedConversionError before the callback that reencodes attributes is called.

git-svn-id: http://svn.redmine.org/redmine/trunk@13896 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/changeset.rb

index 4991910706651df350214321f0a088e465124de6..c03296451d9c337317c866a2aeddc13eb873ec95 100644 (file)
@@ -69,6 +69,16 @@ class Changeset < ActiveRecord::Base
     end
   end
 
+  def committer=(arg)
+    write_attribute :committer,
+      self.class.to_utf8(arg, repository.try(:repo_log_encoding))
+  end
+
+  def comments=(arg)
+    write_attribute :comments,
+      self.class.normalize_comments(arg, repository.try(:repo_log_encoding))
+  end
+
   def committed_on=(date)
     self.commit_date = date
     super
@@ -92,9 +102,7 @@ class Changeset < ActiveRecord::Base
   end
 
   def before_create_cs
-    self.committer = self.class.to_utf8(self.committer, repository.repo_log_encoding)
-    self.comments  = self.class.normalize_comments(
-                       self.comments, repository.repo_log_encoding)
+    self.comments ||= ''
     self.user = repository.find_committer_user(self.committer)
   end