Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Implement `to_hash` instead of `to_h` to allow for implicit type casting

Klaus Zanders96e574904fe7
diff --git a/app/services/journals/create_service.rb b/app/services/journals/create_service.rb
index b002ad97548..c617afae04a 100644
--- a/app/services/journals/create_service.rb
+++ b/app/services/journals/create_service.rb
@@ -870,7 +870,7 @@ module Journals
def cause_sql(cause)
# Using the same encoder mechanism that ActiveRecord uses for json/jsonb columns
- ActiveSupport::JSON.encode(cause&.to_h || {})
+ ActiveSupport::JSON.encode(cause || {})
end
# Because we added the journal via bare metal sql, rails does not yet
@@ -906,7 +906,7 @@ module Journals
end
def same_cause?(predecessor, cause)
- (predecessor.cause.blank? && cause.blank?) || predecessor.cause == cause.to_h
+ (predecessor.cause.blank? && cause.blank?) || predecessor.cause == cause
end
def log_journal_creation(predecessor)
diff --git a/lib_static/plugins/acts_as_journalized/lib/cause_of_change/base.rb b/lib_static/plugins/acts_as_journalized/lib/cause_of_change/base.rb
index 40e1b610611..3be75e65a88 100644
--- a/lib_static/plugins/acts_as_journalized/lib/cause_of_change/base.rb
+++ b/lib_static/plugins/acts_as_journalized/lib/cause_of_change/base.rb
@@ -35,7 +35,7 @@ module CauseOfChange
@additional_attributes = additional_attributes
end
- def to_h
+ def to_hash
{ "type" => type }.merge(additional_attributes).deep_stringify_keys
end
@@ -44,13 +44,7 @@ module CauseOfChange
end
def ==(other)
- if other.is_a?(Hash)
- to_h == other
- else
- other.class == self.class &&
- type == other.type &&
- additional_attributes == other.additional_attributes
- end
+ to_hash == other.to_hash
end
end
end
diff --git a/lib_static/plugins/acts_as_journalized/lib/cause_of_change/no_cause.rb b/lib_static/plugins/acts_as_journalized/lib/cause_of_change/no_cause.rb
index e79ded31956..8e65d5d82c1 100644
--- a/lib_static/plugins/acts_as_journalized/lib/cause_of_change/no_cause.rb
+++ b/lib_static/plugins/acts_as_journalized/lib/cause_of_change/no_cause.rb
@@ -36,7 +36,7 @@ module CauseOfChange
true
end
- def to_h
+ def to_hash
{}
end
end