Normalizes strings before comparison

pull/629/head
Hagen Schink 11 years ago committed by Sebastian Schuster
parent aec54683d5
commit a48843a855
  1. 8
      app/models/journal.rb
  2. 4
      app/models/journal_manager.rb

@ -146,9 +146,11 @@ class Journal < ActiveRecord::Base
@changes = data.journaled_attributes.select{|_,v| !v.nil?}
.inject({}) { |h, (k, v)| h[k] = [nil, v]; h }
else
predecessor_data = predecessor.data.journaled_attributes
data.journaled_attributes.select{|k,v| v != predecessor_data[k]}.each do |k, v|
@changes[k] = [predecessor_data[k], v]
normalized_data = JournalManager.normalize_newlines(data.journaled_attributes)
normalized_predecessor_data = JournalManager.normalize_newlines(predecessor.data.journaled_attributes)
normalized_data.select{|k,v| v != normalized_predecessor_data[k]}.each do |k, v|
@changes[k] = [normalized_predecessor_data[k], v]
end
end

@ -205,13 +205,13 @@ class JournalManager
"Journal::#{journal_class_name(type)}".constantize
end
private
def self.normalize_newlines(data)
data.each_with_object({}) { |e, h| h[e[0]] = (e[1].kind_of?(String) ? e[1].gsub(/\r\n/,"\n")
: e[1]) }
end
private
def self.journal_class_name(type)
"#{base_class(type).name}Journal"
end

Loading…
Cancel
Save