inertia_rails 1.7.0 → 1.9.2

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: 91a7d64f22c5d539db5dcfe7527b2bde7d4661bbab098ce75c6d6822a036dec7
4
- data.tar.gz: 64e327c2079918628e2ff6ef21a85959691a48ed7493006cb280bff504fdfe41
3
+ metadata.gz: 84d7a55c30678d9984236bdca8442ff34268cb09ff8795560d0506678acf9ab8
4
+ data.tar.gz: 48308b96e0e2cf06c70027649acc8e992f280743fd5cae05c70a49c4d8ec343e
5
5
  SHA512:
6
- metadata.gz: de83b986de171f75fb64f28f1610e6ff7960722ea586c9ac2183dc99e6ef96fab2e5e5009e580766d595d6594ad3b7b14555b054f5302d03c7d7ac26fd4d3df8
7
- data.tar.gz: dca78a5fbb54dac45a328958dc026f9fb08428bb860fad36835c18ce7814e892329cdad6ab860faef9b095e672485a3b40748c7a7c27cdad8d9d7f90d9526b5d
6
+ metadata.gz: b8ab3b00e2ee6a44649924fd60aefad32bd5bd33621a12c45ddb692f49d7220a4f1a3837334d983ce614a30c9144249c23f280918b8fbc9b75aef2f97cfad04d
7
+ data.tar.gz: de4d10ec3200f4d45a50c2a1cb2abcc479182f4cee135b9401f43679ad1e296031c644982b9d2fa5e5a5875f1fe909b8dfcda941e933927028b0f7cbdbbb8d97
@@ -8,7 +8,7 @@ jobs:
8
8
  fail-fast: false
9
9
  matrix:
10
10
  ruby: [2.6, 2.7]
11
- rails: ['5.0', '5.1', '5.2', '6.0']
11
+ rails: ['5.0', '5.1', '5.2', '6.0', '6.1']
12
12
 
13
13
  runs-on: ubuntu-latest
14
14
  name: Test against Ruby ${{ matrix.ruby }} / Rails ${{ matrix.rails }}
data/Appraisals CHANGED
@@ -1,3 +1,7 @@
1
+ appraise "rails-6.1" do
2
+ gem "rails", "~> 6.1.0"
3
+ end
4
+
1
5
  appraise "rails-6.0" do
2
6
  gem "rails", "~> 6.0.3", '>= 6.0.3.2'
3
7
  end
data/CHANGELOG.md CHANGED
@@ -4,6 +4,27 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [1.9.2] - 2021-02-23
8
+
9
+ * Improve method for detecting whether a user used the RSpec helpers without adding `inertia: true` to the spec
10
+ * Emit a warning when expecting an Inertia response in RSpec and never reaching a `render inertia:` call
11
+
12
+ ## [1.9.1] - 2021-02-10
13
+
14
+ * Define `redirect_to` and `redirect_back` as public methods for compatibility with other code using them
15
+
16
+ ## [1.9.0] - 2021-01-17
17
+
18
+ * Added the same inertia awareness that redirect_to has to redirect_back
19
+
20
+ ## [1.8.0] - 2020-12-08
21
+
22
+ * Add `inertia` route helper feature
23
+
24
+ ## [1.7.1] - 2020-11-24
25
+
26
+ * Fix the definition for InertiaRails::Lazy to avoid an uninitialized constant error when booting an application.
27
+
7
28
  ## [1.7.0] - 2020-11-24
8
29
 
9
30
  * Add support for "lazy" props while rendering. These are props that never compute on the initial page load. The only render during a partial update that calls for them explicitly.
@@ -0,0 +1,7 @@
1
+ module InertiaRails
2
+ class StaticController < ::ApplicationController
3
+ def static
4
+ render inertia: params[:component]
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 6.1.0"
6
+
7
+ gemspec path: "../"
@@ -33,4 +33,5 @@ Gem::Specification.new do |spec|
33
33
  spec.add_development_dependency "rails-controller-testing"
34
34
  spec.add_development_dependency "sqlite3"
35
35
  spec.add_development_dependency "appraisal"
36
+ spec.add_development_dependency "responders"
36
37
  end
data/lib/inertia_rails.rb CHANGED
@@ -4,6 +4,7 @@ require 'inertia_rails/engine'
4
4
  require 'patches/debug_exceptions'
5
5
  require 'patches/better_errors'
6
6
  require 'patches/request'
7
+ require 'patches/mapper'
7
8
 
8
9
  ActionController::Renderers.add :inertia do |component, options|
9
10
  InertiaRails::Renderer.new(
@@ -20,17 +20,31 @@ module InertiaRails
20
20
  end
21
21
  end
22
22
 
23
+ def redirect_to(options = {}, response_options = {})
24
+ capture_inertia_errors(response_options)
25
+ super(options, response_options)
26
+ end
27
+
28
+ def redirect_back(fallback_location:, allow_other_host: true, **options)
29
+ capture_inertia_errors(options)
30
+ super(
31
+ fallback_location: fallback_location,
32
+ allow_other_host: allow_other_host,
33
+ **options,
34
+ )
35
+ end
36
+
37
+ private
38
+
23
39
  def inertia_location(url)
24
40
  headers['X-Inertia-Location'] = url
25
41
  head :conflict
26
42
  end
27
43
 
28
- def redirect_to(options = {}, response_options = {})
29
- if (inertia_errors = response_options.fetch(:inertia, {}).fetch(:errors, nil))
44
+ def capture_inertia_errors(options)
45
+ if (inertia_errors = options.dig(:inertia, :errors))
30
46
  session[:inertia_errors] = inertia_errors
31
47
  end
32
-
33
- super(options, response_options)
34
48
  end
35
49
  end
36
50
  end
@@ -1,26 +1,28 @@
1
- class InertiaRails::Lazy
2
- def initialize(value = nil, &block)
3
- @value = value
4
- @block = block
5
- end
1
+ module InertiaRails
2
+ class Lazy
3
+ def initialize(value = nil, &block)
4
+ @value = value
5
+ @block = block
6
+ end
6
7
 
7
- def call
8
- to_proc.call
9
- end
8
+ def call
9
+ to_proc.call
10
+ end
10
11
 
11
- def to_proc
12
- # This is called by controller.instance_exec, which changes self to the
13
- # controller instance. That makes the instance variables unavailable to the
14
- # proc via closure. Copying the instance variables to local variables before
15
- # the proc is returned keeps them in scope for the returned proc.
16
- value = @value
17
- block = @block
18
- if value.respond_to?(:call)
19
- value
20
- elsif value
21
- Proc.new { value }
22
- else
23
- block
12
+ def to_proc
13
+ # This is called by controller.instance_exec, which changes self to the
14
+ # controller instance. That makes the instance variables unavailable to the
15
+ # proc via closure. Copying the instance variables to local variables before
16
+ # the proc is returned keeps them in scope for the returned proc.
17
+ value = @value
18
+ block = @block
19
+ if value.respond_to?(:call)
20
+ value
21
+ elsif value
22
+ Proc.new { value }
23
+ else
24
+ block
25
+ end
24
26
  end
25
27
  end
26
28
  end
@@ -35,6 +35,9 @@ module InertiaRails
35
35
  def inertia
36
36
  raise 'Inertia test helpers aren\'t set up! Make sure you add inertia: true to describe blocks using inertia tests.' unless inertia_tests_setup?
37
37
 
38
+ if @_inertia_render_wrapper.nil? && !::RSpec.configuration.inertia[:skip_missing_renderer_warnings]
39
+ warn 'WARNING: the test never created an Inertia renderer. Maybe the code wasn\'t able to reach a `render inertia:` call? If this was intended, or you don\'t want to see this message, set ::RSpec.configuration.inertia[:skip_missing_renderer_warnings] = true'
40
+ end
38
41
  @_inertia_render_wrapper
39
42
  end
40
43
 
@@ -49,7 +52,7 @@ module InertiaRails
49
52
  protected
50
53
 
51
54
  def inertia_tests_setup?
52
- @_inertia_render_wrapper.present?
55
+ ::RSpec.current_example.metadata.fetch(:inertia, false)
53
56
  end
54
57
  end
55
58
  end
@@ -57,6 +60,9 @@ end
57
60
 
58
61
  RSpec.configure do |config|
59
62
  config.include ::InertiaRails::RSpec::Helpers
63
+ config.add_setting :inertia, default: {
64
+ skip_missing_renderer_warnings: false
65
+ }
60
66
 
61
67
  config.before(:each, inertia: true) do
62
68
  new_renderer = InertiaRails::Renderer.method(:new)
@@ -1,3 +1,3 @@
1
1
  module InertiaRails
2
- VERSION = "1.7.0"
2
+ VERSION = "1.9.2"
3
3
  end
@@ -0,0 +1,8 @@
1
+ ActionDispatch::Routing::Mapper.class_eval do
2
+ def inertia(args, &block)
3
+ route = args.keys.first
4
+ component = args.values.first
5
+
6
+ get(route => 'inertia_rails/static#static', defaults: {component: component})
7
+ end
8
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inertia_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Knoles
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2020-11-24 00:00:00.000000000 Z
13
+ date: 2021-02-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -110,6 +110,20 @@ dependencies:
110
110
  - - ">="
111
111
  - !ruby/object:Gem::Version
112
112
  version: '0'
113
+ - !ruby/object:Gem::Dependency
114
+ name: responders
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ type: :development
121
+ prerelease: false
122
+ version_requirements: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
113
127
  description:
114
128
  email:
115
129
  - brain@bellawatt.com
@@ -129,6 +143,7 @@ files:
129
143
  - LICENSE.txt
130
144
  - README.md
131
145
  - Rakefile
146
+ - app/controllers/inertia_rails/static_controller.rb
132
147
  - app/views/inertia.html.erb
133
148
  - bin/console
134
149
  - bin/setup
@@ -136,6 +151,7 @@ files:
136
151
  - gemfiles/rails_5.1.gemfile
137
152
  - gemfiles/rails_5.2.gemfile
138
153
  - gemfiles/rails_6.0.gemfile
154
+ - gemfiles/rails_6.1.gemfile
139
155
  - inertia_rails.gemspec
140
156
  - lib/inertia_rails.rb
141
157
  - lib/inertia_rails/controller.rb
@@ -150,6 +166,7 @@ files:
150
166
  - lib/patches/debug_exceptions.rb
151
167
  - lib/patches/debug_exceptions/patch-5-0.rb
152
168
  - lib/patches/debug_exceptions/patch-5-1.rb
169
+ - lib/patches/mapper.rb
153
170
  - lib/patches/request.rb
154
171
  homepage: https://github.com/inertiajs/inertia-rails
155
172
  licenses: