From 15e5789ae785c0c115832da62525bf596f0ce5e6 Mon Sep 17 00:00:00 2001 From: pabois <pierreandre.boissinot@noesya.coop> Date: Mon, 24 Apr 2023 16:02:37 +0200 Subject: [PATCH] test --- .../with_dependencies_synchronization.rb | 3 ++- .../communication/website/dependency_test.rb | 22 ++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/app/models/concerns/with_dependencies_synchronization.rb b/app/models/concerns/with_dependencies_synchronization.rb index 0079e7fed..ab1a97efe 100644 --- a/app/models/concerns/with_dependencies_synchronization.rb +++ b/app/models/concerns/with_dependencies_synchronization.rb @@ -7,7 +7,7 @@ module WithDependenciesSynchronization attr_accessor :dependencies_before_save before_save :compute_dependencies_before_save - after_save :cleanup_websites if :dependencies_missing_after_save? + after_save :cleanup_websites, if: :dependencies_missing_after_save? after_destroy :cleanup_websites end @@ -18,6 +18,7 @@ module WithDependenciesSynchronization end def dependencies_missing_after_save? + # byebug (@dependencies_before_save - recursive_dependencies_syncable).any? end diff --git a/test/models/communication/website/dependency_test.rb b/test/models/communication/website/dependency_test.rb index e8812d107..6252c5a66 100644 --- a/test/models/communication/website/dependency_test.rb +++ b/test/models/communication/website/dependency_test.rb @@ -2,14 +2,30 @@ require "test_helper" # rails test test/models/communication/website/dependency_test.rb class Communication::Website::DependencyTest < ActiveSupport::TestCase - test "page" do + def test_page_dependencies # Rien : 0 dépendances page = communication_website_pages(:page_with_no_dependency) assert_equal 0, page.recursive_dependencies.count - # On ajoute un block "Chapitre" : 7 dépendances (les 6 composants du chapitre + le chapitre) - page = communication_website_pages(:page_with_no_dependency) + # On ajoute un block "Chapitre" : 7 dépendances (les 6 composants du chapitre + le block lui même) page.blocks.create(position: 1, published: true, template_kind: :chapter) assert_equal 7, page.recursive_dependencies.count end + + def test_change_block_dependencies + page = communication_website_pages(:page_with_no_dependency) + + # On ajoute un block "OrganizationChart" lié à Arnaud : 9 dépendances (4 composants du organization_chart + 1 élément du organization_chart (arnaud) + 3 éléments liés à arnaud + le block lui-même) + block = page.blocks.create(position: 1, published: true, template_kind: :organization_chart) + block.data = "{ \"elements\": [ { \"id\": \"#{arnaud.id}\" } ] }" + block.save + + page = page.reload + + assert_equal 9, page.recursive_dependencies.count + + # On modifie le target du block + block.data = "{ \"elements\": [ { \"id\": \"#{olivia.id}\" } ] }" + block.save + end end -- GitLab