Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct diff behavior for first revision #463

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion app/models/diffed_revision.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def initialize(revision, record)
def diff
@diff ||= Differ.diff_by_line(
after[content_attribute],
before[content_attribute]
before_content
)
end

Expand Down Expand Up @@ -42,6 +42,11 @@ def before
@before ||= YAML.load(@revision.object)
end

def before_content
harmonized_version = before[content_attribute].include?("\r\n") ? before[content_attribute] : before[content_attribute].gsub("\n", "\r\n")
@revision.previous.event == 'create' ? harmonized_version : before[content_attribute]
end

def after
# Note: PaperTrail::Version#object will return `nil` if its event type
# is `create` - but in theory, @revision.next below should always return
Expand Down