diff --git a/app/models/story.rb b/app/models/story.rb index 8f40bfb..c233543 100644 --- a/app/models/story.rb +++ b/app/models/story.rb @@ -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 @@ -53,7 +53,12 @@ def to_work(archive_config, host) language_code, categories, tags, - "#{archive_config.stories_note}\n

--


#{notes}", + "#{archive_config.stories_note}\n" + + if notes.present? + "

--


#{notes}" + else + "" + end, id, summary, chapters.map { |c| chapter_url(c, host: host) } diff --git a/app/models/story_link.rb b/app/models/story_link.rb index 2c3ff63..55809b1 100644 --- a/app/models/story_link.rb +++ b/app/models/story_link.rb @@ -38,7 +38,12 @@ def to_bookmark(archive_config) characters, language_code, archive_config.collection_name, - "#{archive_config.bookmarks_note}\n

--


#{notes}", + "#{archive_config.bookmarks_note}\n" + + if notes.present? + "

--


#{notes}" + else + "" + end, tags, false, false diff --git a/spec/models/story_link_spec.rb b/spec/models/story_link_spec.rb index f1707f5..18e8a8d 100644 --- a/spec/models/story_link_spec.rb +++ b/spec/models/story_link_spec.rb @@ -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") @@ -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( diff --git a/spec/models/story_spec.rb b/spec/models/story_spec.rb index c78a858..29f9532 100644 --- a/spec/models/story_spec.rb +++ b/spec/models/story_spec.rb @@ -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") @@ -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(