diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index fea105b55..e5da8319e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -62,7 +62,7 @@ jobs: MQ_BETA_ENABLED: ${{ env.MQ_BETA_ENABLED }} run: yarn test:rails - name: Upload Code Coverage - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: code-coverage path: coverage/ diff --git a/app/controllers/tpi/home_controller.rb b/app/controllers/tpi/home_controller.rb index 67feee9a2..84dd48c51 100644 --- a/app/controllers/tpi/home_controller.rb +++ b/app/controllers/tpi/home_controller.rb @@ -2,7 +2,7 @@ module TPI class HomeController < TPIController def index @case_studies = CaseStudy.all - @sector_clusters = TPISectorCluster.all.group_by(&:slug).transform_values(&:first) + @sector_clusters = TPISectorCluster.includes(:sectors).group_by(&:slug).transform_values(&:first) page = TPIPage.find_by(slug: 'homepage-content') @home_content = { @@ -29,7 +29,7 @@ def index } @latest_researches = Publication .published - .includes([:image_attachment, :author_image_attachment]) + .includes([image_attachment: :blob, author_image_attachment: :blob, file_attachment: :blob]) .order(publication_date: :desc) .take(3) diff --git a/app/helpers/file_helper.rb b/app/helpers/file_helper.rb index bd985ae8b..ba3cb8d35 100644 --- a/app/helpers/file_helper.rb +++ b/app/helpers/file_helper.rb @@ -5,4 +5,8 @@ def preview_file_tag(file, options = {}) link_to "Uploaded file: #{file.blob.filename}", rails_blob_path(file), options.merge(target: '_blank') end + + def format_of(file) + Mime::Type.lookup(file.content_type).symbol + end end diff --git a/app/models/bank_assessment.rb b/app/models/bank_assessment.rb index 329f179dd..1aec7d95f 100644 --- a/app/models/bank_assessment.rb +++ b/app/models/bank_assessment.rb @@ -11,7 +11,7 @@ # class BankAssessment < ApplicationRecord belongs_to :bank - has_many :results, class_name: 'BankAssessmentResult' + has_many :results, class_name: 'BankAssessmentResult', dependent: :destroy validates_presence_of :assessment_date validates :assessment_date, date_after: Date.new(2010, 12, 31) diff --git a/app/views/tpi/home/index.html.erb b/app/views/tpi/home/index.html.erb index 493feb070..f9929994f 100644 --- a/app/views/tpi/home/index.html.erb +++ b/app/views/tpi/home/index.html.erb @@ -144,7 +144,7 @@
<% @latest_researches.each_with_index do |research, index| %>
- <%= link_to tpi_publication_download_file_path(slug: research.slug), target: '_blank', class: 'research-box' do %> + <%= link_to tpi_publication_download_file_path(slug: research.slug, format: format_of(research.file)), target: '_blank', class: 'research-box' do %>
<% if research.author_image.present? %> diff --git a/app/views/tpi/publications/_list.html.erb b/app/views/tpi/publications/_list.html.erb index f3c5e9c34..df1024b45 100644 --- a/app/views/tpi/publications/_list.html.erb +++ b/app/views/tpi/publications/_list.html.erb @@ -11,7 +11,7 @@ <% if publication.summary.present? %> <%= link_to publication.title, tpi_publication_path(id: publication.slug), class: 'link is-strong' %> <% else %> - <%= link_to publication.title, tpi_publication_download_file_path(slug: publication.slug), target: '_blank', class: 'link is-strong' %> + <%= link_to publication.title, tpi_publication_download_file_path(slug: publication.slug, format: format_of(publication.file)), target: '_blank', class: 'link is-strong' %> <% end %> <% else %> <%= link_to publication.title, show_news_article_tpi_publication_path(id: publication.id), class: "link is-strong" %> diff --git a/app/views/tpi/publications/show.html.erb b/app/views/tpi/publications/show.html.erb index 92fbb2461..c3967a924 100644 --- a/app/views/tpi/publications/show.html.erb +++ b/app/views/tpi/publications/show.html.erb @@ -25,7 +25,7 @@ <%= @publication.summary&.html_safe %>
- <%= link_to 'Download file', tpi_publication_download_file_path(slug: @publication.slug), target: '_blank', class: 'button is-primary' %> + <%= link_to 'Download file', tpi_publication_download_file_path(slug: @publication.slug, format: format_of(@publication.file)), target: '_blank', class: 'button is-primary' %>