inertia_rails 1.1.0 → 1.2.0

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: bc3cc396a4feb3b70226c2a54881faf1d3a502a05171bcc146b83df472b89b18
4
- data.tar.gz: a8b6b651202a33eab122d6c4768bed7d485ffb6c5e5f411b1d0b04cd156780ad
3
+ metadata.gz: fdaebfad8721ec7747b79081270577ca65181b95c3351675387ac133645fe392
4
+ data.tar.gz: ed0d9bf04ab9af128c4cad90c3e2af57d15ae5a92699f28e5893c9340743e3f3
5
5
  SHA512:
6
- metadata.gz: 7c81fc5e1a5fd8f48f696dd49f9234ede89fac59234f22a1c5c90bafb92946917ecf2dfe454a7ad3cf03a886aea435331233a0a9eabaab8a8606f4525cd17e59
7
- data.tar.gz: 77fb640e2e8d21786d3f92f0830f9220c90aae67aeda6857b909db07bf71c020b4c5da2d78a208f80b90e531a56dced6a8a4a22e2a13df007d93ed93aecc2f31
6
+ metadata.gz: 4037238f6ba98d8dc82e8c5d852615a471e9d2396ab292be74740a7b40013c904043e92b4c724fac3d0aa9a47ee4f97f340c567ec2119eacf3fdb748b9097261
7
+ data.tar.gz: 6bef52dadbe2c8bfef33f8b4027e81219e58ed1263615b6c3fb97e3bb759166a115110237b80f4916b02133399b4bb8e60442ec5a5b7aca6b992ca24c6cd6b2d
data/.gitignore CHANGED
@@ -7,5 +7,12 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
 
10
+ /spec/dummy/db/*.sqlite3
11
+ /spec/dummy/db/*.sqlite3-journal
12
+ /spec/dummy/db/log/*.log
13
+ /spec/dummy/tmp/
14
+ /spec/dummy/.sass-cache
15
+ /spec/dummy/log/
16
+
10
17
  # rspec failure tracking
11
18
  .rspec_status
data/.rspec CHANGED
@@ -1,3 +1,3 @@
1
1
  --format documentation
2
2
  --color
3
- --require spec_helper
3
+ --require rails_helper
data/CHANGELOG.md CHANGED
@@ -4,6 +4,16 @@ 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.2.0] - 2019-11-1
8
+
9
+ ### Added
10
+
11
+ * Added rspec helpers
12
+
13
+ ### Fixed
14
+
15
+ * Make sure that `inertia_share` properties are reset before each request
16
+
7
17
  ## [1.1.0] - 2019-10-24
8
18
 
9
19
  ### Changed
@@ -27,5 +27,8 @@ Gem::Specification.new do |spec|
27
27
 
28
28
  spec.add_development_dependency "bundler", "~> 2.0"
29
29
  spec.add_development_dependency "rake", "~> 10.0"
30
- spec.add_development_dependency "rspec", "~> 3.0"
30
+ spec.add_development_dependency "rspec-rails", "~> 3.0"
31
+ spec.add_development_dependency "rails"
32
+ spec.add_development_dependency "rails-controller-testing"
33
+ spec.add_development_dependency "sqlite3"
31
34
  end
@@ -28,6 +28,11 @@ module InertiaRails
28
28
  shared_blocks.push(block)
29
29
  end
30
30
 
31
+ def self.reset!
32
+ self.shared_plain_data = {}
33
+ self.shared_blocks = []
34
+ end
35
+
31
36
  private
32
37
 
33
38
  module Configuration
@@ -35,7 +40,7 @@ module InertiaRails
35
40
  mattr_accessor(:version) { nil }
36
41
 
37
42
  def self.evaluated_version
38
- version.respond_to?(:call) ? version.call : version
43
+ self.version.respond_to?(:call) ? self.version.call : self.version
39
44
  end
40
45
  end
41
46
 
@@ -7,6 +7,8 @@ module InertiaRails
7
7
  def call(env)
8
8
  status, headers, body = @app.call(env)
9
9
  request = ActionDispatch::Request.new(env)
10
+
11
+ ::InertiaRails.reset!
10
12
 
11
13
  return [status, headers, body] unless env['HTTP_X_INERTIA'].present?
12
14
 
@@ -0,0 +1,117 @@
1
+ require "rspec/core"
2
+ require "rspec/matchers"
3
+
4
+ module InertiaRails
5
+ module RSpec
6
+ class InertiaRenderWrapper
7
+ attr_reader :view_data, :props, :component
8
+
9
+ def initialize
10
+ @view_data = nil
11
+ @props = nil
12
+ @component = nil
13
+ end
14
+
15
+ def call(params)
16
+ set_values(params)
17
+ @render_method&.call(params)
18
+ end
19
+
20
+ def wrap_render(render_method)
21
+ @render_method = render_method
22
+ self
23
+ end
24
+
25
+ protected
26
+
27
+ def set_values(params)
28
+ @view_data = params[:locals].except(:page)
29
+ @props = params[:locals][:page][:props]
30
+ @component = params[:locals][:page][:component]
31
+ end
32
+ end
33
+
34
+ module Helpers
35
+ def inertia
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
+
38
+ @_inertia_render_wrapper
39
+ end
40
+
41
+ def expect_inertia
42
+ expect(inertia)
43
+ end
44
+
45
+ def inertia_wrap_render(render)
46
+ @_inertia_render_wrapper = InertiaRenderWrapper.new.wrap_render(render)
47
+ end
48
+
49
+ protected
50
+
51
+ def inertia_tests_setup?
52
+ @_inertia_render_wrapper.present?
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ RSpec.configure do |config|
59
+ config.include ::InertiaRails::RSpec::Helpers
60
+
61
+ config.before(:each, inertia: true) do
62
+ new_renderer = InertiaRails::Renderer.method(:new)
63
+ allow(InertiaRails::Renderer).to receive(:new) do |component, controller, request, response, render, named_args|
64
+ new_renderer.call(component, controller, request, response, inertia_wrap_render(render), named_args)
65
+ end
66
+ end
67
+ end
68
+
69
+ RSpec::Matchers.define :have_exact_props do |expected_props|
70
+ match do |inertia|
71
+ expect(inertia.props).to eq expected_props
72
+ end
73
+
74
+ failure_message do |inertia|
75
+ "expected inertia props to receive #{expected_props}, instead received #{inertia.props || 'nothing'}"
76
+ end
77
+ end
78
+
79
+ RSpec::Matchers.define :include_props do |expected_props|
80
+ match do |inertia|
81
+ expect(inertia.props).to include expected_props
82
+ end
83
+
84
+ failure_message do |inertia|
85
+ "expected inertia props to include #{expected_props}, instead received #{inertia.props || 'nothing'}"
86
+ end
87
+ end
88
+
89
+ RSpec::Matchers.define :render_component do |expected_component|
90
+ match do |inertia|
91
+ expect(inertia.component).to eq expected_component
92
+ end
93
+
94
+ failure_message do |inertia|
95
+ "expected rendered inertia component to be #{expected_component}, instead received #{inertia.component || 'nothing'}"
96
+ end
97
+ end
98
+
99
+ RSpec::Matchers.define :have_exact_view_data do |expected_view_data|
100
+ match do |inertia|
101
+ expect(inertia.view_data).to eq expected_view_data
102
+ end
103
+
104
+ failure_message do |inertia|
105
+ "expected inertia view data to receive #{expected_view_data}, instead received #{inertia.view_data || 'nothing'}"
106
+ end
107
+ end
108
+
109
+ RSpec::Matchers.define :include_view_data do |expected_view_data|
110
+ match do |inertia|
111
+ expect(inertia.view_data).to include expected_view_data
112
+ end
113
+
114
+ failure_message do |inertia|
115
+ "expected inertia view data to include #{expected_view_data}, instead received #{inertia.view_data || 'nothing'}"
116
+ end
117
+ end
@@ -1,3 +1,3 @@
1
1
  module InertiaRails
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  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.1.0
4
+ version: 1.2.0
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: 2019-10-24 00:00:00.000000000 Z
13
+ date: 2019-11-01 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -41,7 +41,7 @@ dependencies:
41
41
  - !ruby/object:Gem::Version
42
42
  version: '10.0'
43
43
  - !ruby/object:Gem::Dependency
44
- name: rspec
44
+ name: rspec-rails
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - "~>"
@@ -54,6 +54,48 @@ dependencies:
54
54
  - - "~>"
55
55
  - !ruby/object:Gem::Version
56
56
  version: '3.0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: rails
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ - !ruby/object:Gem::Dependency
72
+ name: rails-controller-testing
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ - !ruby/object:Gem::Dependency
86
+ name: sqlite3
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
57
99
  description:
58
100
  email:
59
101
  - brain@bellawatt.com
@@ -82,6 +124,7 @@ files:
82
124
  - lib/inertia_rails/inertia_rails.rb
83
125
  - lib/inertia_rails/middleware.rb
84
126
  - lib/inertia_rails/renderer.rb
127
+ - lib/inertia_rails/rspec.rb
85
128
  - lib/inertia_rails/version.rb
86
129
  homepage: https://github.com/inertiajs/inertia-rails/
87
130
  licenses: