klastera 1.5.5.2 → 1.5.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c4b18c6803bcea9323fe454de8293d219fca55d5fade1913dc31e01dadf16efd
|
|
4
|
+
data.tar.gz: 184638381c45f93db22d2bec40c8d2536c0722dd8ec54d7f3f508502ebe73514
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 27bd431138c5c6f17f296e2e49a3aaff2846011aca1feb53e500f1eba5e60c0b98f1b69dfc0f9fad9b8c886069882744152fc3b89a4a14951dd21f87a2f3d2c6
|
|
7
|
+
data.tar.gz: d64254e8c67a7b54d49179f58721547ead68bd363dd4cd6174addd2a13957a21b795da9118289df8f9a228807388d4da8ab6e3639a00447dd3f04cb57e379f08
|
|
@@ -54,14 +54,19 @@ module Klastera::Concerns::Clusterizable
|
|
|
54
54
|
)
|
|
55
55
|
end
|
|
56
56
|
|
|
57
|
+
# No cuenta las filas marcadas para destruir: quitar una zona con el basurero y agregar otra en
|
|
58
|
+
# el mismo guardado deja una sola zona al final, y no debe rechazarse.
|
|
57
59
|
def has_one_cluster_entity
|
|
58
|
-
if cluster_entities.length > 1
|
|
60
|
+
if cluster_entities.reject(&:marked_for_destruction?).length > 1
|
|
59
61
|
return errors.add(:cluster_entities, I18n.t('klastera.messages.has_one_cluster_entity'))
|
|
60
62
|
end
|
|
61
63
|
end
|
|
62
64
|
|
|
65
|
+
# No cuenta las filas marcadas para destruir: quitar una zona con el basurero y volver a agregar
|
|
66
|
+
# la misma en el mismo guardado deja una sola fila al final, y no es un duplicado.
|
|
63
67
|
def uniqueness_of_cluster_entity_record
|
|
64
|
-
|
|
68
|
+
vigentes = cluster_entities.reject(&:marked_for_destruction?)
|
|
69
|
+
if vigentes.map(&:cluster_id).uniq.size != vigentes.size
|
|
65
70
|
return errors.add(:cluster_entities, I18n.t('klastera.messages.duplicated_cluster_entity') )
|
|
66
71
|
end
|
|
67
72
|
end
|
data/lib/klastera/version.rb
CHANGED
|
@@ -39,5 +39,43 @@ module Klastera
|
|
|
39
39
|
assert entity.cluster_entities.any?(&:marked_for_destruction?)
|
|
40
40
|
assert entity.cluster_entities.any? { |c| c.new_record? && c.cluster_id == otro.id }
|
|
41
41
|
end
|
|
42
|
+
|
|
43
|
+
# Entidad que permite una sola zona (por defecto): quitar una y agregar otra en el mismo guardado
|
|
44
|
+
# deja una sola, y la validacion no debe contar la fila marcada para destruir.
|
|
45
|
+
test "acepta quitar una zona y agregar otra en el mismo guardado" do
|
|
46
|
+
entity, ce, = build_entity_with_cluster
|
|
47
|
+
otro = ::Cluster.create!(organization: entity.organization, name: "otro-#{SecureRandom.hex(2)}")
|
|
48
|
+
entity.assign_attributes(cluster_entities_attributes: {
|
|
49
|
+
"0" => { "id" => ce.id, "_destroy" => "1" },
|
|
50
|
+
"1" => { "cluster_id" => otro.id.to_s, "_destroy" => "false" }
|
|
51
|
+
})
|
|
52
|
+
entity.valid?
|
|
53
|
+
assert_not entity.errors[:cluster_entities].any? { |m| m == I18n.t('klastera.messages.has_one_cluster_entity') }
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
test "sigue rechazando dos zonas vigentes en una entidad de una sola zona" do
|
|
57
|
+
entity, _ce, = build_entity_with_cluster
|
|
58
|
+
otro = ::Cluster.create!(organization: entity.organization, name: "otro2-#{SecureRandom.hex(2)}")
|
|
59
|
+
entity.assign_attributes(cluster_entities_attributes: { "1" => { "cluster_id" => otro.id.to_s, "_destroy" => "false" } })
|
|
60
|
+
entity.valid?
|
|
61
|
+
assert entity.errors[:cluster_entities].any?
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
test "acepta quitar una zona y volver a agregar la misma en el mismo guardado" do
|
|
65
|
+
entity, ce, cluster = build_entity_with_cluster
|
|
66
|
+
entity.assign_attributes(cluster_entities_attributes: {
|
|
67
|
+
"0" => { "id" => ce.id, "_destroy" => "1" },
|
|
68
|
+
"1" => { "cluster_id" => cluster.id.to_s, "_destroy" => "false" }
|
|
69
|
+
})
|
|
70
|
+
entity.valid?
|
|
71
|
+
assert_not entity.errors[:cluster_entities].any? { |m| m == I18n.t('klastera.messages.duplicated_cluster_entity') }
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
test "sigue rechazando la misma zona dos veces vigente" do
|
|
75
|
+
entity, _ce, cluster = build_entity_with_cluster
|
|
76
|
+
entity.assign_attributes(cluster_entities_attributes: { "1" => { "cluster_id" => cluster.id.to_s, "_destroy" => "false" } })
|
|
77
|
+
entity.valid?
|
|
78
|
+
assert entity.errors[:cluster_entities].any?
|
|
79
|
+
end
|
|
42
80
|
end
|
|
43
81
|
end
|