iknow_view_models 3.7.2 → 3.7.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: 887749dfc0bd40e748de9293d6fea68595d41e395a3ccfca73a655c627e51fb0
4
- data.tar.gz: bb16fe56a4a81f5055912d38e07766185aa082f3f4b28344369f15f8cf8078dd
3
+ metadata.gz: c4284905ecbec0ee35c1d61c687ed9bc12dd9030ea600f34584e97333a559141
4
+ data.tar.gz: 5270dfdfed945d140452555a32dbdd08ffdbc61dc26d0a6133eced8a3e261244
5
5
  SHA512:
6
- metadata.gz: a8174361c58a44ade71e1976ce72b1a642e11c98d2005e40ea7f7598dae4f4eebe9c8b9ada7ed4d3c883436970e7d82890cc6580335112d1dbfdd66b8ac05730
7
- data.tar.gz: 428b12acca9472a0dab1a4795f0edb4ff36805577a3722c3202b5934933a87fa3917efdd1859a3a1618677d48e79bb2304423dbe74537d173bdfec7ec839be36
6
+ metadata.gz: 63e53371c1511303ce3d425ccbb586148f116d110b524f3c9ab442936ce9b8456b07aeb269f1da3a5dc410549cb4f1f7a4d64c28e797bf6de8931eb9d2cdaee3
7
+ data.tar.gz: 21cc10407f402a6c371c516e08f35664655693518d4d0b78b9d84293a90f019b2b343c6c650b1331643135f8d4f634833deee6aec87cc31c45a461a0ae9fb979
@@ -0,0 +1,31 @@
1
+ name: Publish Ruby Gem
2
+
3
+ on:
4
+ push:
5
+ branches: [ "master" ]
6
+
7
+ jobs:
8
+ build:
9
+ name: Build + Publish
10
+ runs-on: ubuntu-latest
11
+ permissions:
12
+ contents: read
13
+ packages: write
14
+
15
+ steps:
16
+ - uses: actions/checkout@v3
17
+ - name: Set up Ruby 2.7
18
+ uses: ruby/setup-ruby@v1
19
+ with:
20
+ ruby-version: 2.7
21
+
22
+ - name: Publish to RubyGems
23
+ run: |
24
+ mkdir -p $HOME/.gem
25
+ touch $HOME/.gem/credentials
26
+ chmod 0600 $HOME/.gem/credentials
27
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
28
+ gem build *.gemspec
29
+ gem push *.gem
30
+ env:
31
+ GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
@@ -0,0 +1,65 @@
1
+ name: Run Tests
2
+
3
+ on:
4
+ pull_request:
5
+ branches: "**"
6
+
7
+ permissions:
8
+ contents: read
9
+ checks: write
10
+ pull-requests: write
11
+
12
+ jobs:
13
+ test:
14
+ runs-on: ubuntu-latest
15
+
16
+ services:
17
+ postgres:
18
+ image: postgres:13-alpine
19
+ ports:
20
+ - "5432:5432"
21
+ env:
22
+ POSTGRES_DB: iknow_view_models
23
+ POSTGRES_USER: rails
24
+ POSTGRES_PASSWORD: password
25
+
26
+ strategy:
27
+ fail-fast: false
28
+ matrix:
29
+ ruby-version: ['2.7', '3.0', '3.1', '3.2']
30
+ include:
31
+ - ruby-version: '2.7'
32
+ bundle-gemfile: gemfiles/rails_5_2.gemfile
33
+ - ruby-version: '3.0'
34
+ bundle-gemfile: gemfiles/rails_6_0.gemfile
35
+ - ruby-version: '3.1'
36
+ bundle-gemfile: gemfiles/rails_6_1.gemfile
37
+ - ruby-version: '3.2'
38
+ bundle-gemfile: gemfiles/rails_7_0.gemfile
39
+
40
+ env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps
41
+ BUNDLE_GEMFILE: ${{ github.workspace }}/${{ matrix.bundle-gemfile }}
42
+ DATABASE_URL: "postgres://rails:password@localhost:5432/iknow_view_models"
43
+
44
+ steps:
45
+ - uses: actions/checkout@v3
46
+ - name: Set up Ruby
47
+ uses: ruby/setup-ruby@v1
48
+ with:
49
+ ruby-version: ${{ matrix.ruby-version }}
50
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
51
+ - name: Run tests
52
+ run: bundle exec rake test
53
+ - name: Upload result
54
+ uses: actions/upload-artifact@v3
55
+ if: always()
56
+ with:
57
+ path: test/reports/
58
+ name: test_results_${{ matrix.ruby-version }}
59
+ - name: Test Report
60
+ uses: dorny/test-reporter@v1
61
+ if: always()
62
+ with:
63
+ name: Minitest Tests - ${{ matrix.ruby-version }}
64
+ path: test/reports/*.xml
65
+ reporter: java-junit
@@ -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.4'
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
@@ -12,11 +12,19 @@ class ViewModel::ErrorView < ViewModel::Record
12
12
  def serialize_view(json, serialize_context: nil)
13
13
  json.set! :class, exception.class.name
14
14
  json.backtrace exception.backtrace
15
- if (cause = exception.cause)
16
- json.cause do
17
- json.set! :class, cause.class.name
18
- json.backtrace cause.backtrace
19
- end
15
+
16
+ json.cause do
17
+ cause = exception.cause
18
+ next json.null! unless cause
19
+
20
+ json.set! :class, cause.class.name
21
+ json.backtrace cause.backtrace
22
+ end
23
+
24
+ json.context do
25
+ next json.null! unless exception.respond_to?(:to_honeybadger_context)
26
+
27
+ json.merge! cause.to_honeybadger_context
20
28
  end
21
29
  end
22
30
  end
@@ -8,11 +8,18 @@ require 'view_model/active_record/controller'
8
8
 
9
9
  require 'acts_as_manual_list'
10
10
 
11
- db_config_path = File.join(File.dirname(__FILE__), '../config/database.yml')
12
- db_config = YAML.safe_load(File.open(db_config_path))
13
- raise 'Test database configuration missing' unless db_config['test']
11
+ db_config =
12
+ if (url = ENV['DATABASE_URL'])
13
+ url
14
+ else
15
+ db_config_path = File.join(File.dirname(__FILE__), '../config/database.yml')
16
+ yaml = YAML.safe_load(File.open(db_config_path))
17
+ raise 'Test database configuration missing' unless yaml['test']
14
18
 
15
- ActiveRecord::Base.establish_connection(db_config['test'])
19
+ yaml['test']
20
+ end
21
+
22
+ ActiveRecord::Base.establish_connection(db_config)
16
23
 
17
24
  # Remove test tables if any exist
18
25
  %w[labels parents children targets poly_ones poly_twos owners
@@ -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.4
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-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -381,8 +381,9 @@ executables: []
381
381
  extensions: []
382
382
  extra_rdoc_files: []
383
383
  files:
384
- - ".circleci/config.yml"
385
384
  - ".envrc"
385
+ - ".github/workflows/gem-push.yml"
386
+ - ".github/workflows/test.yml"
386
387
  - ".gitignore"
387
388
  - ".idea/codeStyleSettings.xml"
388
389
  - ".rubocop.yml"
@@ -509,7 +510,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
509
510
  - !ruby/object:Gem::Version
510
511
  version: '0'
511
512
  requirements: []
512
- rubygems_version: 3.3.26
513
+ rubygems_version: 3.1.6
513
514
  signing_key:
514
515
  specification_version: 4
515
516
  summary: ViewModels provide a means of encapsulating a collection of related data
data/.circleci/config.yml DELETED
@@ -1,134 +0,0 @@
1
- version: 2.1
2
-
3
- executors:
4
- ruby-pg:
5
- parameters:
6
- ruby-version:
7
- type: string
8
- default: "2.7"
9
- pg-version:
10
- type: string
11
- default: "12.10"
12
- gemfile:
13
- type: string
14
- default: "Gemfile"
15
- environment:
16
- PGHOST: 127.0.0.1
17
- PGUSER: eikaiwa
18
- docker:
19
- - image: cimg/ruby:<< parameters.ruby-version >>
20
- environment:
21
- BUNDLE_JOBS: 3
22
- BUNDLE_RETRY: 3
23
- BUNDLE_PATH: vendor/bundle
24
- RAILS_ENV: test
25
- BUNDLE_GEMFILE: << parameters.gemfile >>
26
- - image: cimg/postgres:<< parameters.pg-version >>
27
- environment:
28
- POSTGRES_USER: eikaiwa
29
- POSTGRES_DB: iknow_view_models
30
- POSTGRES_PASSWORD: ""
31
-
32
- jobs:
33
- test:
34
- parameters:
35
- ruby-version:
36
- type: string
37
- pg-version:
38
- type: string
39
- gemfile:
40
- type: string
41
- executor:
42
- name: ruby-pg
43
- ruby-version: << parameters.ruby-version >>
44
- pg-version: << parameters.pg-version >>
45
- gemfile: << parameters.gemfile >>
46
- parallelism: 1
47
- steps:
48
- - checkout
49
-
50
- - run:
51
- # Remove the non-appraisal gemfile for safety: we never want to use it.
52
- name: Prepare bundler
53
- command: bundle -v && rm Gemfile
54
-
55
- - run:
56
- name: Compute a gemfile lock
57
- command: bundle lock && cp "${BUNDLE_GEMFILE}.lock" /tmp/gem-lock
58
-
59
- - restore_cache:
60
- keys:
61
- - iknow_viewmodels-<< parameters.ruby-version >>-{{ checksum "/tmp/gem-lock" }}
62
- - iknow_viewmodels-
63
-
64
- - run:
65
- name: Bundle Install
66
- command: bundle check || bundle install
67
-
68
- - save_cache:
69
- key: iknow_viewmodels-<< parameters.ruby-version >>-{{ checksum "/tmp/gem-lock" }}
70
- paths:
71
- - vendor/bundle
72
-
73
- - run:
74
- name: Wait for DB
75
- command: dockerize -wait tcp://localhost:5432 -timeout 1m
76
-
77
- - run:
78
- name: Run minitest
79
- command: bundle exec rake test
80
-
81
- - store_test_results:
82
- path: test/reports
83
-
84
- publish:
85
- executor: ruby-pg
86
- steps:
87
- - checkout
88
- - run:
89
- name: Setup Rubygems
90
- command: |
91
- mkdir ~/.gem &&
92
- echo -e "---\r\n:rubygems_api_key: $RUBYGEMS_API_KEY" > ~/.gem/credentials &&
93
- chmod 0600 ~/.gem/credentials
94
- - run:
95
- name: Publish to Rubygems
96
- command: |
97
- gem build iknow_view_models.gemspec
98
- gem push iknow_view_models-*.gem
99
-
100
- workflows:
101
- version: 2.1
102
- build:
103
- jobs:
104
- - test:
105
- name: 'ruby 2.7 rails 5.2 pg 12'
106
- ruby-version: "2.7"
107
- pg-version: "12.10"
108
- gemfile: gemfiles/rails_5_2.gemfile
109
- - test:
110
- name: 'ruby 2.7 rails 6.0 pg 12'
111
- ruby-version: "2.7"
112
- pg-version: "12.10"
113
- gemfile: gemfiles/rails_6_0.gemfile
114
- - test:
115
- name: 'ruby 2.7 rails 6.1 pg 12'
116
- ruby-version: "2.7"
117
- pg-version: "12.10"
118
- gemfile: gemfiles/rails_6_1.gemfile
119
- - test:
120
- name: 'ruby 3.0 rails 6.1 pg 12'
121
- ruby-version: "3.0"
122
- pg-version: "12.10"
123
- gemfile: gemfiles/rails_6_1.gemfile
124
- - test:
125
- name: 'ruby 3.1 rails 7.0 pg 13'
126
- ruby-version: "3.1"
127
- pg-version: "13.6"
128
- gemfile: gemfiles/rails_7_0.gemfile
129
- - publish:
130
- filters:
131
- branches:
132
- only: master
133
- tags:
134
- ignore: /.*/