Skip to content

Commit

Permalink
OD-1671 Only include notes separator if notes are present (#194)
Browse files Browse the repository at this point in the history
* OD-1671 Only include notes separator if notes are present

* OD-1671 Better Ruby syntax

* OD-1671 Add tests

---------

Co-authored-by: Ariana <[email protected]>
  • Loading branch information
ariana-paris and Ariana authored Jul 23, 2023
1 parent 33307c2 commit 25b3cb9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
17 changes: 11 additions & 6 deletions app/models/story.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ def as_json(options = {})
summaryTooLong: summary && summary.size > 1250,
chapters: chapters.sort_by(&:position).map { |c|
c.as_json(only: [:id, :title, :position])
.merge!(
title: (c.title.blank? ? "Chapter #{c.position}" : c.title),
textLength: c.text.size,
textTooLong: c.text.size > 510_000 # Same as Archive MAX_LENGTH
).except!(:content)
.merge!(
title: (c.title.blank? ? "Chapter #{c.position}" : c.title),
textLength: c.text.size,
textTooLong: c.text.size > 510_000 # Same as Archive MAX_LENGTH
).except!(:content)
}
)
end
Expand All @@ -53,7 +53,12 @@ def to_work(archive_config, host)
language_code,
categories,
tags,
"#{archive_config.stories_note}\n<br/><br/><p>--</p><br/>#{notes}",
"#{archive_config.stories_note}\n" +
if notes.present?
"<br/><br/><p>--</p><br/>#{notes}"
else
""
end,
id,
summary,
chapters.map { |c| chapter_url(c, host: host) }
Expand Down
7 changes: 6 additions & 1 deletion app/models/story_link.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ def to_bookmark(archive_config)
characters,
language_code,
archive_config.collection_name,
"#{archive_config.bookmarks_note}\n<br/><br/><p>--</p><br/>#{notes}",
"#{archive_config.bookmarks_note}\n" +
if notes.present?
"<br/><br/><p>--</p><br/>#{notes}"
else
""
end,
tags,
false,
false
Expand Down
7 changes: 7 additions & 0 deletions spec/models/story_link_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
describe StoryLink, type: :model do
let!(:author1) { create(:author_with_stories, audit_comment: "Test") }
let(:story_link) { create(:story_link, author_id: author1.id, notes: "Original Notes", audit_comment: "Test") }
let(:story_link_no_notes) { create(:story_link, author_id: author1.id, audit_comment: "Test") }

it 'converts a story link to a bookmark with all fields correct' do
config = create(:archive_config, bookmarks_note: "Bookmark note")
Expand All @@ -11,6 +12,12 @@
expect(bookmark.language_code).to eq "en"
end

it 'doesn’t include a separator if no notes are present' do
config = create(:archive_config, bookmarks_note: "Bookmark note")
bookmark = story_link_no_notes.to_bookmark(config)
expect(bookmark.notes).to eq "Bookmark note\n"
end

it 'returns a summary too long error in json object' do
stub_const("SUMMARY_LENGTH", 4)
story = StoryLink.new(
Expand Down
7 changes: 7 additions & 0 deletions spec/models/story_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

let!(:author1) { create(:author_with_stories, audit_comment: "Test") }
let(:story1) { create(:story, author_id: author1.id, notes: "Original Notes", language_code: "de", audit_comment: "Test") }
let(:story_no_notes) { create(:story, author_id: author1.id, audit_comment: "Test") }

it 'converts a story with all fields correctly' do
config = create(:archive_config, stories_note: "Story note")
Expand All @@ -14,6 +15,12 @@
expect(work.language_code).to eq "de"
end

it 'doesn’t include a separator if no notes are present' do
config = create(:archive_config, stories_note: "Story note")
work = story_no_notes.to_work(config, "test")
expect(work.notes).to eq "Story note\n"
end

it 'returns a summary too long error in json object' do
stub_const("SUMMARY_LENGTH", 4)
story = Story.new(
Expand Down

0 comments on commit 25b3cb9

Please sign in to comment.