iknow_view_models 3.7.2 → 3.7.3
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8326292714cd7c35f3abdfab45e1384ab1e4e7c393a09270667761b657490b4
|
4
|
+
data.tar.gz: 76b36a08882c48264b991b0b2098de2559c860e0ff6b8a10d25932182773352a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0ec39c9fd67c59a790b9327645880c5742994789adb29fe944dea737196edc3bbc23e623ce73a9d5d4a0968efefc404ce05b60c28f9740f4cbfa8c27d2076d6
|
7
|
+
data.tar.gz: 396e3640cab86908afa4a7c1d768499613f432033b6fa0fa87da8657e575bb889c574685ee27032439d41a4fa5cd4795fc1f98f7481f82338e9bf9eb53b11ea8
|
@@ -163,7 +163,7 @@ class ViewModel::ActiveRecord
|
|
163
163
|
|
164
164
|
@release_pool.release_all!
|
165
165
|
|
166
|
-
if updated_viewmodels.present?
|
166
|
+
if updated_viewmodels.present? && deserialize_context.validate_deferred_constraints?
|
167
167
|
# Deferred database constraints may have been violated by changes during
|
168
168
|
# deserialization. VM::AR promises that any errors during deserialization
|
169
169
|
# will be raised as a ViewModel::DeserializationError, so check constraints
|
@@ -4,9 +4,21 @@ require 'view_model/traversal_context'
|
|
4
4
|
|
5
5
|
class ViewModel::DeserializeContext < ViewModel::TraversalContext
|
6
6
|
class SharedContext < ViewModel::TraversalContext::SharedContext
|
7
|
+
def initialize(validate_deferred_constraints: true, **rest)
|
8
|
+
super(**rest)
|
9
|
+
@validate_deferred_constraints = validate_deferred_constraints
|
10
|
+
end
|
11
|
+
|
12
|
+
# Should deferred database constraints be checked via SET CONSTRAINTS
|
13
|
+
# IMMEDIATE at the end of the deserialization operation
|
14
|
+
def validate_deferred_constraints?
|
15
|
+
@validate_deferred_constraints
|
16
|
+
end
|
7
17
|
end
|
8
18
|
|
9
19
|
def self.shared_context_class
|
10
20
|
SharedContext
|
11
21
|
end
|
22
|
+
|
23
|
+
delegate :validate_deferred_constraints?, to: :shared_context
|
12
24
|
end
|
@@ -556,5 +556,21 @@ class ViewModel::ActiveRecordTest < ActiveSupport::TestCase
|
|
556
556
|
|
557
557
|
assert_equal({ constraint: constraint, columns: columns, values: values, conflicts: conflicts, nodes: [] }, ex.meta)
|
558
558
|
end
|
559
|
+
|
560
|
+
def test_disabled_deferred_check
|
561
|
+
l1 = List.create!(value: 1)
|
562
|
+
l2 = List.create!
|
563
|
+
|
564
|
+
ctx = ListView.new_deserialize_context(validate_deferred_constraints: false)
|
565
|
+
alter_by_view!(ListView, l2, deserialize_context: ctx) do |view, refs|
|
566
|
+
view['value'] = 1
|
567
|
+
end
|
568
|
+
|
569
|
+
ex = assert_raises(::ActiveRecord::StatementInvalid) do
|
570
|
+
List.connection.execute('SET CONSTRAINTS ALL IMMEDIATE')
|
571
|
+
end
|
572
|
+
|
573
|
+
assert_equal(PG::ExclusionViolation, ex.cause.class)
|
574
|
+
end
|
559
575
|
end
|
560
576
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iknow_view_models
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.7.
|
4
|
+
version: 3.7.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- iKnow Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-01
|
11
|
+
date: 2023-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|