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

wip

parent 518b2697
No related branches found
No related tags found
No related merge requests found
......@@ -45,12 +45,14 @@ class Communication::Website::GitFile < ApplicationRecord
def should_update?
!should_destroy? &&
(
different_path? || different_sha?
different_path? ||
different_sha?
)
end
def should_destroy?
will_be_destroyed || path.nil?
will_be_destroyed ||
path.nil?
end
def path
......@@ -71,8 +73,16 @@ class Communication::Website::GitFile < ApplicationRecord
protected
# Real sha on the git repo
def git_sha_for(path)
website.git_repository.git_sha path
end
def previous_git_sha
@previous_git_sha ||= git_sha_for(previous_path)
end
def git_sha
@git_sha ||= website.git_repository.git_sha previous_path
@git_sha ||= git_sha_for(path)
end
# Based on content, with the provider's algorithm (sha1 or sha256)
......@@ -81,14 +91,17 @@ class Communication::Website::GitFile < ApplicationRecord
end
def exists_on_git?
!git_sha.nil?
previous_git_sha.present? || # The file exists where it was last time
(
previous_path.nil? && # Never saved in the database
git_sha.present? # but it exists in the git repo
)
end
def synchronized_with_git?
exists_on_git? &&
(
git_sha == previous_sha || git_sha == previous_sha256
)
exists_on_git? && # File exists
previous_path == path && # at the same place
previous_git_sha == previous_sha # with the same content
end
def different_path?
......
......@@ -36,3 +36,5 @@ test_post:
website: website_with_github
title: Test
slug: test
published: true
published_at: 2010-11-28 00:00:00
......@@ -23,14 +23,8 @@
require "test_helper"
class Communication::Website::GitFileTest < ActiveSupport::TestCase
test "github should_create?" do
test "should_create? for a new file" 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'
assert file.should_create?
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