From b11bb11968bdaa64faab8ccc2406dc7b9a0e07aa Mon Sep 17 00:00:00 2001 From: Nicolas Florentin Date: Thu, 28 Sep 2023 08:49:36 +0200 Subject: [PATCH] Fix a bug: rss/projects was failing with project without image --- CHANGELOG.md | 1 + app/views/rss/events/index.xml.builder | 4 +++- app/views/rss/projects/index.xml.builder | 4 +++- test/integration/rss/events_test.rb | 13 +++++++++++++ test/integration/rss/projects_test.rb | 13 +++++++++++++ 5 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 test/integration/rss/events_test.rb create mode 100644 test/integration/rss/projects_test.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index c2e5bf3c7..cf24fa613 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Fix a bug: unable to sync projects with openprojects - Fix a bug: public availabilities (no user) was buggy (server error) - Fix a bug: unable to generate statistic +- Fix a bug: rss/projects was failing with project without image - [TODO DEPLOY] `rails fablab:openlab:bulk_export` - [TODO DEPLOY] `rails fablab:openlab:bulk_update` diff --git a/app/views/rss/events/index.xml.builder b/app/views/rss/events/index.xml.builder index b0a1942c6..1f03c90c1 100644 --- a/app/views/rss/events/index.xml.builder +++ b/app/views/rss/events/index.xml.builder @@ -22,7 +22,9 @@ xml.rss version: '2.0', 'xmlns:xCal' => 'urn:ietf:params:xml:ns:xcal' do xml.xCal :dtend do xml.text! event.availability.end_at.strftime('%FT%T%:z') end - xml.enclosure url: root_url + event.event_image.attachment.large.url, length: event.event_image.attachment.large.size, type: event.event_image.attachment.content_type if event.event_image + if event.event_image&.attachment? + xml.enclosure url: root_url + event.event_image.attachment.large.url, length: event.event_image.attachment.large.size, type: event.event_image.attachment.content_type + end xml.category event.category.name end end diff --git a/app/views/rss/projects/index.xml.builder b/app/views/rss/projects/index.xml.builder index 29e24057a..54525e2de 100644 --- a/app/views/rss/projects/index.xml.builder +++ b/app/views/rss/projects/index.xml.builder @@ -17,7 +17,9 @@ xml.rss version: '2.0' do xml.link root_url + '#!/projects/' + project.slug xml.author project.author&.user&.profile&.full_name xml.description project.description - xml.enclosure url: root_url + project.project_image.attachment.large.url, length: project.project_image.attachment.large.size, type: project.project_image.attachment.content_type if project.project_image + if project.project_image&.attachment? + xml.enclosure url: root_url + project.project_image.attachment.large.url, length: project.project_image.attachment.large.size, type: project.project_image.attachment.content_type + end end end end diff --git a/test/integration/rss/events_test.rb b/test/integration/rss/events_test.rb new file mode 100644 index 000000000..47972f271 --- /dev/null +++ b/test/integration/rss/events_test.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'test_helper' +module Rss; end + +class Rss::EventsTestTest < ActionDispatch::IntegrationTest + test '#index' do + get rss_events_path + + assert_response :success + assert Nokogiri::XML(response.body).errors.empty? + end +end \ No newline at end of file diff --git a/test/integration/rss/projects_test.rb b/test/integration/rss/projects_test.rb new file mode 100644 index 000000000..cf4945f2e --- /dev/null +++ b/test/integration/rss/projects_test.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'test_helper' +module Rss; end + +class Rss::ProjectsTestTest < ActionDispatch::IntegrationTest + test '#index' do + get rss_projects_path + + assert_response :success + assert Nokogiri::XML(response.body).errors.empty? + end +end \ No newline at end of file