lib/draftsman/model.rb in draftsman-0.3.1 vs lib/draftsman/model.rb in draftsman-0.3.2
- old
+ new
@@ -118,15 +118,10 @@
# Returns whether or not `has_drafts` has been called on this model.
def draftable?
method_defined?(:draftsman_options)
end
- # Returns whether or not the included ActiveRecord can do `where.not(...)` style queries.
- def where_not?
- ActiveRecord::VERSION::STRING.to_f >= 4.0
- end
-
# Serializes attribute changes for `Draft#object_changes` attribute.
def serialize_draft_attribute_changes(changes)
# Don't serialize values before inserting into columns of type `JSON` on PostgreSQL databases.
return changes if self.draft_class.object_changes_col_is_json?
@@ -181,10 +176,15 @@
coder = Draftsman::Serializers::Yaml unless coder.respond_to?(:dump)
attributes[key] = coder.load(attributes[key])
end
end
end
+
+ # Returns whether or not the included ActiveRecord can do `where.not(...)` style queries.
+ def where_not?
+ ActiveRecord::VERSION::STRING.to_f >= 4.0
+ end
end
module InstanceMethods
# Returns whether or not this item has a draft.
def draft?
@@ -229,10 +229,16 @@
:object => object_attrs_for_draft_record
}
# Stash previous draft in case it needs to be reverted later
if self.draft?
- data[:previous_draft] = Draftsman.serializer.dump(send(self.class.draft_association_name).attributes)
+ attrs = send(self.class.draft_association_name).attributes
+
+ data[:previous_draft] = if self.class.draft_class.previous_changes_col_is_json?
+ attrs
+ else
+ Draftsman.serializer.dump(attrs)
+ end
end
data = merge_metadata_for_draft(data)
if send(self.class.draft_association_name).present?