iknow_view_models 2.10.1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +119 -0
  3. data/.travis.yml +31 -0
  4. data/Appraisals +6 -16
  5. data/gemfiles/{rails_7_0.gemfile → rails_6_0_beta.gemfile} +2 -2
  6. data/iknow_view_models.gemspec +3 -5
  7. data/lib/iknow_view_models/version.rb +1 -1
  8. data/lib/view_model/active_record/association_data.rb +206 -92
  9. data/lib/view_model/active_record/association_manipulation.rb +22 -12
  10. data/lib/view_model/active_record/cache/cacheable_view.rb +3 -13
  11. data/lib/view_model/active_record/cache.rb +2 -2
  12. data/lib/view_model/active_record/cloner.rb +11 -11
  13. data/lib/view_model/active_record/controller.rb +0 -2
  14. data/lib/view_model/active_record/update_context.rb +21 -3
  15. data/lib/view_model/active_record/update_data.rb +43 -45
  16. data/lib/view_model/active_record/update_operation.rb +265 -153
  17. data/lib/view_model/active_record/visitor.rb +9 -6
  18. data/lib/view_model/active_record.rb +94 -74
  19. data/lib/view_model/after_transaction_runner.rb +3 -18
  20. data/lib/view_model/callbacks.rb +2 -2
  21. data/lib/view_model/changes.rb +24 -16
  22. data/lib/view_model/config.rb +6 -2
  23. data/lib/view_model/deserialization_error.rb +31 -0
  24. data/lib/view_model/deserialize_context.rb +2 -6
  25. data/lib/view_model/error_view.rb +6 -5
  26. data/lib/view_model/record/attribute_data.rb +11 -6
  27. data/lib/view_model/record.rb +44 -24
  28. data/lib/view_model/serialize_context.rb +2 -63
  29. data/lib/view_model/test_helpers/arvm_builder.rb +2 -4
  30. data/lib/view_model/traversal_context.rb +2 -2
  31. data/lib/view_model.rb +21 -13
  32. data/shell.nix +1 -1
  33. data/test/helpers/arvm_test_models.rb +4 -12
  34. data/test/helpers/arvm_test_utilities.rb +6 -0
  35. data/test/helpers/controller_test_helpers.rb +6 -6
  36. data/test/helpers/viewmodel_spec_helpers.rb +63 -52
  37. data/test/unit/view_model/access_control_test.rb +88 -37
  38. data/test/unit/view_model/active_record/belongs_to_test.rb +110 -178
  39. data/test/unit/view_model/active_record/cache_test.rb +11 -5
  40. data/test/unit/view_model/active_record/cloner_test.rb +1 -1
  41. data/test/unit/view_model/active_record/controller_test.rb +12 -20
  42. data/test/unit/view_model/active_record/has_many_test.rb +540 -316
  43. data/test/unit/view_model/active_record/has_many_through_poly_test.rb +12 -15
  44. data/test/unit/view_model/active_record/has_many_through_test.rb +15 -58
  45. data/test/unit/view_model/active_record/has_one_test.rb +288 -135
  46. data/test/unit/view_model/active_record/poly_test.rb +0 -1
  47. data/test/unit/view_model/active_record/shared_test.rb +21 -39
  48. data/test/unit/view_model/active_record/version_test.rb +3 -2
  49. data/test/unit/view_model/active_record_test.rb +5 -63
  50. data/test/unit/view_model/callbacks_test.rb +1 -0
  51. data/test/unit/view_model/record_test.rb +0 -32
  52. data/test/unit/view_model/traversal_context_test.rb +13 -12
  53. metadata +15 -25
  54. data/.github/workflows/gem-push.yml +0 -31
  55. data/.github/workflows/test.yml +0 -65
  56. data/gemfiles/rails_6_0.gemfile +0 -9
  57. data/gemfiles/rails_6_1.gemfile +0 -9
  58. data/test/unit/view_model/active_record/optional_attribute_view_test.rb +0 -58
@@ -1,65 +0,0 @@
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,9 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "minitest-ci"
6
- gem "activerecord", "~> 6.0.0"
7
- gem "activesupport", "~> 6.0.0"
8
-
9
- gemspec path: "../"
@@ -1,9 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "minitest-ci"
6
- gem "activerecord", "~> 6.1.0"
7
- gem "activesupport", "~> 6.1.0"
8
-
9
- gemspec path: "../"
@@ -1,58 +0,0 @@
1
- require_relative "../../../helpers/arvm_test_utilities.rb"
2
- require_relative "../../../helpers/arvm_test_models.rb"
3
-
4
- require "minitest/autorun"
5
-
6
- require "view_model/active_record"
7
-
8
- class ViewModel::ActiveRecord::AttributeViewTest < ActiveSupport::TestCase
9
- include ARVMTestUtilities
10
-
11
- def before_all
12
- super
13
-
14
- build_viewmodel(:Thing) do
15
- define_schema do |t|
16
- t.integer :a
17
- t.integer :b
18
- end
19
-
20
- define_model do
21
- end
22
-
23
- define_viewmodel do
24
- attribute :a
25
- attribute :b, optional: true
26
- end
27
- end
28
- end
29
-
30
- def setup
31
- super
32
- @thing = Thing.create!(a: 1, b: 2)
33
-
34
- @skel = { "_type" => "Thing",
35
- "_version" => 1,
36
- "id" => @thing.id }
37
- end
38
-
39
- def test_optional_not_serialized
40
- view, _refs = serialize_with_references(ThingView.new(@thing))
41
-
42
- assert_equal(@skel.merge("a" => 1), view)
43
- end
44
-
45
- def test_optional_included
46
- view, _refs = serialize_with_references(ThingView.new(@thing),
47
- serialize_context: ThingView.new_serialize_context(include: :b))
48
-
49
- assert_equal(@skel.merge("a" => 1, "b" => 2), view)
50
- end
51
-
52
- def test_pruned_not_included
53
- view, _refs = serialize_with_references(ThingView.new(@thing),
54
- serialize_context: ThingView.new_serialize_context(include: :b, prune: :a))
55
-
56
- assert_equal(@skel.merge("b" => 2), view)
57
- end
58
- end