Skip to content
Snippets Groups Projects
Commit 0561cc63 authored by Arnaud Levy's avatar Arnaud Levy
Browse files

wip tests

parent ba333054
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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 %>
......
git_file_1:
about: test_post (Communication::Website::Post)
website: website_with_github
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment