iknow_view_models 2.8.5 → 2.8.6

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: 906f5e8368cc9b69c01b0fdf55f2f8475fc452cad35b5708f2bab63051892a93
4
- data.tar.gz: cce586636fa5abcc641b70f36afa264cf8f0c586d3c2ec3964e0e940d1981a4f
3
+ metadata.gz: d8f4644f2bf2710cf5f455959e820599c3452b2e460888fefeb2abd78f356db8
4
+ data.tar.gz: ec9f0b4cb3009b4e64fa3c77cfea24c716062220ba2de95d566ac0a758a10836
5
5
  SHA512:
6
- metadata.gz: 22de8467817ea6757571e10c7a53b5c2e187c1d5a82f5a67dba801db1aec0dfd40e3beb1eb2e6b3bc00d72f69a604d7216608fe9432cb876374af8134806c95c
7
- data.tar.gz: 9d4206f0b9a7eb1359ecdcacdd4627873467b0dd1b9f990b981937fc8fe253faa99cbfa962865f714842251d2b38a0b434b266953127433b5b06c0d112954732
6
+ metadata.gz: 1a268fef9e337366301b6d4bbc72138a06b8e6fdcc4929091550be15a36867d533d2a7394de88cdeb2d98a719572b0f1d9f6d7210eca5150f8b0ae40f959ed47
7
+ data.tar.gz: e327ca86167c3b94de129ffac178c6188c7a86ec5251c2a6779e6d85a820f6b518740264ffcd8a417e4d46ad7a78ebb2770ce25a95e74af6f42ba8904932a890
data/.envrc ADDED
@@ -0,0 +1 @@
1
+ eval "$(lorri direnv)"
data/.gitignore CHANGED
@@ -5,6 +5,8 @@
5
5
  .yardoc
6
6
  .byebug_history
7
7
  Gemfile.lock
8
+ nix/gem/Gemfile
9
+ nix/gem/gemset.nix
8
10
  InstalledFiles
9
11
  _yardoc
10
12
  coverage
@@ -35,6 +35,7 @@ Gem::Specification.new do |spec|
35
35
  spec.add_dependency "json_schema"
36
36
  spec.add_dependency "lazily"
37
37
  spec.add_dependency "renum"
38
+ spec.add_dependency "oj"
38
39
 
39
40
  spec.add_development_dependency "appraisal"
40
41
  spec.add_development_dependency "bundler"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IknowViewModels
4
- VERSION = '2.8.5'
4
+ VERSION = '2.8.6'
5
5
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "view_model"
3
+ require 'view_model'
4
+ require 'oj'
4
5
 
5
6
  module ViewModel::Controller
6
7
  extend ActiveSupport::Concern
@@ -18,7 +19,7 @@ module ViewModel::Controller
18
19
 
19
20
  # Render viewmodel(s) to a JSON API response as a String
20
21
  def prerender_viewmodel(viewmodel, status: nil, serialize_context: viewmodel.class.try(:new_serialize_context))
21
- Jbuilder.encode do |json|
22
+ encode_jbuilder do |json|
22
23
  json.data do
23
24
  ViewModel.serialize(viewmodel, json, serialize_context: serialize_context)
24
25
  end
@@ -45,7 +46,7 @@ module ViewModel::Controller
45
46
  json_view = wrap_json_view(json_view)
46
47
  json_references = wrap_json_view(json_references)
47
48
 
48
- Jbuilder.encode do |json|
49
+ encode_jbuilder do |json|
49
50
  json.data json_view
50
51
  if json_references.present?
51
52
  json.references do
@@ -104,8 +105,23 @@ module ViewModel::Controller
104
105
  end
105
106
  end
106
107
 
108
+ def encode_jbuilder
109
+ builder = Jbuilder.new do |json|
110
+ yield json
111
+ end
112
+
113
+ # Jbuilder#encode no longer uses MultiJson, but instead calls `.to_json`. In
114
+ # the context of ActiveSupport, we don't want this, because AS replaces the
115
+ # .to_json interface with its own .as_json, which demands that everything is
116
+ # reduced to a Hash before it can be JSON encoded. Using this is not only
117
+ # slightly more expensive in terms of allocations, but also defeats the
118
+ # purpose of our precompiled `CompiledJson` terminals. Instead serialize
119
+ # using OJ with options equivalent to those used by MultiJson.
120
+ Oj.dump(builder.attributes!, mode: :compat, time_format: :ruby, use_to_json: true)
121
+ end
122
+
107
123
  def render_jbuilder(status:)
108
- response = Jbuilder.encode do |json|
124
+ response = encode_jbuilder do |json|
109
125
  yield json
110
126
  end
111
127
 
@@ -0,0 +1,41 @@
1
+ #! /usr/bin/env nix-shell
2
+ #! nix-shell -i ruby -p ruby -p bundler -p bundix
3
+ # frozen_string_literal: true
4
+
5
+ # Bundix doesn't support `gemspec` directive in Gemfiles, as it doesn't copy the
6
+ # gemspec (and its dependencies) into the store.
7
+ # This workaround is from https://github.com/manveru/bundix/issues/10#issuecomment-405879379
8
+
9
+ require 'shellwords'
10
+
11
+ def sh(*args)
12
+ warn args.shelljoin
13
+ system(*args) || raise
14
+ end
15
+
16
+ sh 'bundle', 'lock'
17
+
18
+ require 'fileutils'
19
+ require 'bundler'
20
+
21
+ lockfile = Bundler::LockfileParser.new(File.read('Gemfile.lock'))
22
+ gems = lockfile.specs.select { |spec| spec.source.is_a?(Bundler::Source::Rubygems) }
23
+ sources = [URI('https://rubygems.org/')] | gems.map(&:source).flat_map(&:remotes)
24
+
25
+ FileUtils.mkdir_p 'nix/gem'
26
+ Dir.chdir 'nix/gem' do
27
+ ['Gemfile', 'Gemfile.lock', 'gemset.nix'].each do |f|
28
+ File.delete(f) if File.exist?(f)
29
+ end
30
+
31
+ File.open('Gemfile', 'w') do |gemfile|
32
+ sources.each { |source| gemfile.puts "source #{source.to_s.inspect}" }
33
+ gemfile.puts
34
+
35
+ gems.each do |gem|
36
+ gemfile.puts "gem #{gem.name.inspect}, #{gem.version.to_s.inspect}"
37
+ end
38
+ end
39
+
40
+ sh 'bundix', '-l'
41
+ end
data/shell.nix ADDED
@@ -0,0 +1,20 @@
1
+ with import <nixpkgs> {};
2
+
3
+ (bundlerEnv {
4
+ name = "dev";
5
+ gemdir = ./nix/gem;
6
+
7
+ gemConfig = (defaultGemConfig.override { postgresql = postgresql_11; });
8
+
9
+ ruby = ruby_2_6.overrideAttrs (attrs: {
10
+ patches = (attrs.patches or []) ++ [
11
+ # RubyGems has a regression where you can no longer build certain gems
12
+ # outside their directory. Until this is merged, patch from the pull
13
+ # request.
14
+ (fetchpatch {
15
+ url = https://patch-diff.githubusercontent.com/raw/rubygems/rubygems/pull/2596.patch;
16
+ sha256 = "0m1s5brd30bqcr8v99sczihm83g270philx83kkw5bpix462fdm3";
17
+ })
18
+ ];
19
+ });
20
+ }).env
@@ -198,12 +198,15 @@ class DummyController
198
198
  end
199
199
 
200
200
  # Provide dummy Rails env
201
- module Rails
202
- def self.env
201
+ module RailsDummyEnv
202
+ def env
203
203
  'production'
204
204
  end
205
205
  end
206
206
 
207
+ module Rails; end
208
+ Rails.singleton_class.prepend(RailsDummyEnv)
209
+
207
210
  module ActionController
208
211
  class Parameters
209
212
  end
@@ -15,12 +15,16 @@ require "view_model/active_record"
15
15
 
16
16
  DUMMY_RAILS_CACHE = ActiveSupport::Cache::MemoryStore.new
17
17
 
18
- module Rails
19
- def self.cache
18
+ module RailsDummyCache
19
+ def cache
20
20
  DUMMY_RAILS_CACHE
21
21
  end
22
22
  end
23
23
 
24
+ # Ensure we have a dummy Rails, and then prepend our dummy cache
25
+ module Rails; end
26
+ Rails.singleton_class.prepend(RailsDummyCache)
27
+
24
28
  class ViewModel::ActiveRecord
25
29
  class CacheTest < ActiveSupport::TestCase
26
30
  using ViewModel::Utils::Collections
@@ -557,5 +557,4 @@ class ViewModel::ActiveRecord::ControllerTest < ActiveSupport::TestCase
557
557
  assert_equal({ 'data' => LabelView.new(old_label).to_hash },
558
558
  labelcontroller.hash_response)
559
559
  end
560
-
561
560
  end
@@ -0,0 +1,43 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/unit'
3
+ require 'minitest/hooks'
4
+
5
+ require_relative '../../helpers/arvm_test_utilities.rb'
6
+ require_relative '../../helpers/viewmodel_spec_helpers.rb'
7
+
8
+ require 'view_model'
9
+ require 'view_model/controller'
10
+
11
+ class ViewModel::ControllerTest < ActiveSupport::TestCase
12
+ include ARVMTestUtilities
13
+ extend Minitest::Spec::DSL
14
+
15
+ describe 'rendering prerendered json terminals' do
16
+ let(:controller) do
17
+ Class.new do
18
+ def self.rescue_from(*); end
19
+ include ViewModel::Controller
20
+ public :encode_jbuilder
21
+ end
22
+ end
23
+
24
+ let(:terminal) { { 'a' => 100 } }
25
+
26
+ let(:encoded_terminal) do
27
+ ViewModel::Controller::CompiledJson.new(Oj.dump(terminal, mode: :compat))
28
+ end
29
+
30
+ let(:expected_dump) { encode(terminal) }
31
+ let(:computed_dump) { encode(encoded_terminal) }
32
+
33
+ def encode(value)
34
+ controller.new.encode_jbuilder do |json|
35
+ json.x value
36
+ end
37
+ end
38
+
39
+ it 'passes through the prerendered data' do
40
+ assert_equal(expected_dump, computed_dump)
41
+ end
42
+ end
43
+ 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: 2.8.5
4
+ version: 2.8.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - iKnow Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-18 00:00:00.000000000 Z
11
+ date: 2019-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -192,6 +192,20 @@ dependencies:
192
192
  - - ">="
193
193
  - !ruby/object:Gem::Version
194
194
  version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: oj
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :runtime
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
195
209
  - !ruby/object:Gem::Dependency
196
210
  name: appraisal
197
211
  requirement: !ruby/object:Gem::Requirement
@@ -340,6 +354,7 @@ extensions: []
340
354
  extra_rdoc_files: []
341
355
  files:
342
356
  - ".circleci/config.yml"
357
+ - ".envrc"
343
358
  - ".gitignore"
344
359
  - ".idea/codeStyleSettings.xml"
345
360
  - ".travis.yml"
@@ -399,6 +414,8 @@ files:
399
414
  - lib/view_model/traversal_context.rb
400
415
  - lib/view_model/utils.rb
401
416
  - lib/view_model/utils/collections.rb
417
+ - nix/gem/generate.rb
418
+ - shell.nix
402
419
  - test/config/database.yml
403
420
  - test/helpers/arvm_test_models.rb
404
421
  - test/helpers/arvm_test_utilities.rb
@@ -427,6 +444,7 @@ files:
427
444
  - test/unit/view_model/active_record/version_test.rb
428
445
  - test/unit/view_model/active_record_test.rb
429
446
  - test/unit/view_model/callbacks_test.rb
447
+ - test/unit/view_model/controller_test.rb
430
448
  - test/unit/view_model/deserialization_error/unique_violation_test.rb
431
449
  - test/unit/view_model/record_test.rb
432
450
  - test/unit/view_model/traversal_context_test.rb
@@ -484,6 +502,7 @@ test_files:
484
502
  - test/unit/view_model/active_record/version_test.rb
485
503
  - test/unit/view_model/active_record_test.rb
486
504
  - test/unit/view_model/callbacks_test.rb
505
+ - test/unit/view_model/controller_test.rb
487
506
  - test/unit/view_model/deserialization_error/unique_violation_test.rb
488
507
  - test/unit/view_model/record_test.rb
489
508
  - test/unit/view_model/traversal_context_test.rb