From 73a4cb7a55a2e5b82d87c99ded2a93bd88120409 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Fri, 29 Aug 2025 17:29:49 -0400 Subject: [PATCH] Use partial for software update list in admin area --- .../_software_update.html.haml | 11 +++++++++ .../admin/software_updates/index.html.haml | 10 +------- spec/system/admin/software_updates_spec.rb | 23 +++++++++++-------- 3 files changed, 26 insertions(+), 18 deletions(-) create mode 100644 app/views/admin/software_updates/_software_update.html.haml diff --git a/app/views/admin/software_updates/_software_update.html.haml b/app/views/admin/software_updates/_software_update.html.haml new file mode 100644 index 00000000000..6de7effdb8e --- /dev/null +++ b/app/views/admin/software_updates/_software_update.html.haml @@ -0,0 +1,11 @@ +%tr{ id: dom_id(software_update) } + %td= software_update.version + %td= t("admin.software_updates.types.#{software_update.type}") + %td{ class: class_names(critical: software_update.urgent?) } + - if software_update.urgent? + = t('admin.software_updates.critical_update') + %td.release-notes + - if software_update.release_notes? + = table_link_to 'link', + t('admin.software_updates.release_notes'), + software_update.release_notes diff --git a/app/views/admin/software_updates/index.html.haml b/app/views/admin/software_updates/index.html.haml index d2ba115590a..25de175a7be 100644 --- a/app/views/admin/software_updates/index.html.haml +++ b/app/views/admin/software_updates/index.html.haml @@ -18,12 +18,4 @@ %th %th %tbody - - @software_updates.each do |update| - %tr - %td= update.version - %td= t("admin.software_updates.types.#{update.type}") - - if update.urgent? - %td.critical= t('admin.software_updates.critical_update') - - else - %td - %td= table_link_to 'link', t('admin.software_updates.release_notes'), update.release_notes + = render collection: @software_updates, partial: 'admin/software_updates/software_update' diff --git a/spec/system/admin/software_updates_spec.rb b/spec/system/admin/software_updates_spec.rb index d9e4bf36fa6..311af9d1227 100644 --- a/spec/system/admin/software_updates_spec.rb +++ b/spec/system/admin/software_updates_spec.rb @@ -3,23 +3,28 @@ require 'rails_helper' RSpec.describe 'finding software updates through the admin interface' do - before do - Fabricate(:software_update, version: '99.99.99', type: 'major', urgent: true, release_notes: 'https://github.com/mastodon/mastodon/releases/v99') - Fabricate(:software_update, version: '3.5.0', type: 'major', urgent: true, release_notes: 'https://github.com/mastodon/mastodon/releases/v3.5.0') + before { sign_in Fabricate(:owner_user) } - sign_in Fabricate(:owner_user), scope: :user - end + let!(:latest_release) { Fabricate(:software_update, version: '99.99.99', type: 'major', urgent: true, release_notes: 'https://github.com/mastodon/mastodon/releases/v99') } + let!(:other_release) { Fabricate(:software_update, version: '98.0.0', type: 'major', release_notes: '') } + let!(:outdated_release) { Fabricate(:software_update, version: '3.5.0', type: 'major', urgent: true, release_notes: 'https://github.com/mastodon/mastodon/releases/v3.5.0') } it 'shows a link to the software updates page, which links to release notes' do visit settings_profile_path click_on I18n.t('admin.critical_update_pending') - expect(page).to have_title(I18n.t('admin.software_updates.title')) + expect(page) + .to have_title(I18n.t('admin.software_updates.title')) + .and have_content(latest_release.version) + .and have_content(other_release.version) + .and have_no_content(outdated_release.version) - expect(page).to have_content('99.99.99') - .and have_no_content('3.5.0') + within("#software_update_#{other_release.id}") do + expect(find('.release-notes').value).to be_nil + end click_on I18n.t('admin.software_updates.release_notes') - expect(page).to have_current_path('https://github.com/mastodon/mastodon/releases/v99', url: true) + expect(page) + .to have_current_path('https://github.com/mastodon/mastodon/releases/v99', url: true) end end