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: 887749dfc0bd40e748de9293d6fea68595d41e395a3ccfca73a655c627e51fb0
4
- data.tar.gz: bb16fe56a4a81f5055912d38e07766185aa082f3f4b28344369f15f8cf8078dd
3
+ metadata.gz: c8326292714cd7c35f3abdfab45e1384ab1e4e7c393a09270667761b657490b4
4
+ data.tar.gz: 76b36a08882c48264b991b0b2098de2559c860e0ff6b8a10d25932182773352a
5
5
  SHA512:
6
- metadata.gz: a8174361c58a44ade71e1976ce72b1a642e11c98d2005e40ea7f7598dae4f4eebe9c8b9ada7ed4d3c883436970e7d82890cc6580335112d1dbfdd66b8ac05730
7
- data.tar.gz: 428b12acca9472a0dab1a4795f0edb4ff36805577a3722c3202b5934933a87fa3917efdd1859a3a1618677d48e79bb2304423dbe74537d173bdfec7ec839be36
6
+ metadata.gz: b0ec39c9fd67c59a790b9327645880c5742994789adb29fe944dea737196edc3bbc23e623ce73a9d5d4a0968efefc404ce05b60c28f9740f4cbfa8c27d2076d6
7
+ data.tar.gz: 396e3640cab86908afa4a7c1d768499613f432033b6fa0fa87da8657e575bb889c574685ee27032439d41a4fa5cd4795fc1f98f7481f82338e9bf9eb53b11ea8
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IknowViewModels
4
- VERSION = '3.7.2'
4
+ VERSION = '3.7.3'
5
5
  end
@@ -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.2
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-23 00:00:00.000000000 Z
11
+ date: 2023-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack