diff --git a/app/models/communication/website/git_file.rb b/app/models/communication/website/git_file.rb index 4ade6aec3f007a6d9a1a6d01f1bb92617906d229..219a46db117213af546e104020e633fe9f2e0094 100644 --- a/app/models/communication/website/git_file.rb +++ b/app/models/communication/website/git_file.rb @@ -33,12 +33,9 @@ class Communication::Website::GitFile < ApplicationRecord website.git_repository.add_git_file git_file end - def synchronized_with_git? - git_sha == previous_sha || git_sha == previous_sha256 - end - def should_create? !should_destroy? && + !exists_on_git? && ( !synchronized_with_git? || previous_path.nil? || @@ -49,7 +46,7 @@ class Communication::Website::GitFile < ApplicationRecord def should_update? !should_destroy? && ( - different_path || different_sha + different_path? || different_sha? ) end @@ -61,14 +58,6 @@ class Communication::Website::GitFile < ApplicationRecord @path ||= about.git_path(website)&.gsub(/\/+/, '/') end - def different_path - previous_path != path - end - - def different_sha - previous_sha != sha && previous_sha != sha256 - end - def sha # Git SHA-1 is calculated from the String "blob <length>\x00<contents>" # Source: https://alblue.bandlem.com/2011/08/git-tip-of-week-objects.html @@ -92,6 +81,25 @@ class Communication::Website::GitFile < ApplicationRecord protected + def exists_on_git? + !git_sha.nil? + end + + def synchronized_with_git? + exists_on_git? && + ( + git_sha == previous_sha || git_sha == previous_sha256 + ) + end + + def different_path? + previous_path != path + end + + def different_sha? + previous_sha != sha && previous_sha != sha256 + end + def git_sha @git_sha ||= website.git_repository.git_sha previous_path end diff --git a/app/views/admin/communication/website/blocks/templates/partners/_static.html.erb b/app/views/admin/communication/website/blocks/templates/partners/_static.html.erb index 34559a6b29d82832dd95874dec7272a3d39bbe79..ef381ee8d59ccb402bd9f8d40d8476fae94f965b 100644 --- a/app/views/admin/communication/website/blocks/templates/partners/_static.html.erb +++ b/app/views/admin/communication/website/blocks/templates/partners/_static.html.erb @@ -5,11 +5,18 @@ partners: <% element['partners'].each do |partner| + logo_id = nil + if partner.has_key?('logo') + logo = partner['logo'] + if logo.is_a?(Hash) && logo.has_key?('id') + logo_id = logo['id'] + end + end %> - name: "<%= partner['name'] %>" url: "<%= partner['url'] %>" - <% unless partner.dig('logo', 'id').blank? %> - logo: "<%= partner['logo']['id'] %>" + <% if logo_id %> + logo: "<%= logo_id %>" <% end %> <% end %> <% end %> diff --git a/test/fixtures/communication/website/git_files.yml b/test/fixtures/communication/website/git_files.yml new file mode 100644 index 0000000000000000000000000000000000000000..c9b6c57aa206ea8330b69a387b90e8d4cbbe00ba --- /dev/null +++ b/test/fixtures/communication/website/git_files.yml @@ -0,0 +1,3 @@ +git_file_1: + about: test_post (Communication::Website::Post) + website: website_with_github diff --git a/test/models/communication/website/git_file_test.rb b/test/models/communication/website/git_file_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..bbde17e003d519d9c9831658635469b6fcdb1902 --- /dev/null +++ b/test/models/communication/website/git_file_test.rb @@ -0,0 +1,14 @@ +require "test_helper" + +class Communication::Website::GitFileTest < ActiveSupport::TestCase + test "github should_create?" do + file = communication_website_git_files(:git_file_1) + # This is wrong! Fixtures must be prepared properly + assert_not file.should_create? + end + + test "github correct sha" do + file = communication_website_git_files(:git_file_1) + assert_equal file.sha, '5d387e7e2da68026aeb0cfc2e6a67f509a3e1ff6' + end +end