quilt_rails 3.3.0 → 3.3.1

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: 368430de6c7c02cfc1a3c569997ca045cbd08afe6a463143740adf0c3d8c3989
4
- data.tar.gz: c0e39d8dd544865e466ea919fe3414c722411c0d0f91757a82abac333fb17f2a
3
+ metadata.gz: 16eb5798cc8dd719437110f06bb5cff4dc1bea6c79e1a9a49eedbba0b0ebd303
4
+ data.tar.gz: d2c9d7ab124b18b6535b57888f3fa5319913554a812e6f074a92eab962cd2f6d
5
5
  SHA512:
6
- metadata.gz: 65fec4f054fd578870567e4528ebd6b5e335877db8096d6af27775869a2fd7ecce8547ed6f0104c6e542cc58bb00ed98a2148a915198d4512f5eb769f2d023f8
7
- data.tar.gz: c17031bff1b39d21b771e062dbdc5745e78b937a21989b444ca46d68cee1d6ead8b7b00e8b2c0131b6f0d656fa8fed962a37241e3c244f05716e7a19b4eb1c36
6
+ metadata.gz: 0a032e43ca617b448cc77f7676a287a19259fed5a41fc4e2ccefa8730c5210f878bdb9bc59183fc0200df1593a42d63147158dedf1683a4db215af739ec18c11
7
+ data.tar.gz: 3d94f79c24568c45075d658e79428acd08c8fd7f15ccb1efd979767fdff97a1adedd637c4e04b50a31615934642d2d118093ee6f7ce8d32d1fba033a13b7a4af
data/Rakefile CHANGED
@@ -24,3 +24,5 @@ Rake::TestTask.new do |t|
24
24
  t.name = 'test:unit'
25
25
  t.pattern = 'test/quilt_rails/**/*_test.rb'
26
26
  end
27
+
28
+ task(default: %i(test))
@@ -8,9 +8,9 @@ module Quilt
8
8
  def create
9
9
  process_report
10
10
 
11
- render json: { result: 'success' }, status: 200
11
+ render(json: { result: 'success' }, status: 200)
12
12
  rescue ActionController::ParameterMissing => error
13
- render json: { error: error.message, status: 422 }
13
+ render(json: { error: error.message, status: 422 })
14
14
  end
15
15
  end
16
16
  end
@@ -12,7 +12,7 @@ module Quilt
12
12
  if File.exist?(procfile_path)
13
13
  append_file(procfile_path, File.read(File.expand_path(find_in_source_paths(procfile_path))))
14
14
  else
15
- copy_file procfile_path
15
+ copy_file(procfile_path)
16
16
  end
17
17
  end
18
18
 
@@ -20,12 +20,12 @@ module Quilt
20
20
  routes_path = "config/routes.rb"
21
21
 
22
22
  if File.exist?(routes_path)
23
- route "mount Quilt::Engine, at: '/'"
23
+ route("mount Quilt::Engine, at: '/'")
24
24
  else
25
- copy_file "routes.rb", routes_path
25
+ copy_file("routes.rb", routes_path)
26
26
  end
27
27
 
28
- say "Added Quilt engine mount"
28
+ say("Added Quilt engine mount")
29
29
  end
30
30
  end
31
31
  end
@@ -10,7 +10,7 @@ module Quilt
10
10
  def install_js_dependencies
11
11
  return if options.skip_yarn?
12
12
 
13
- say "Installing react and types dependencies"
13
+ say("Installing react and types dependencies")
14
14
  system("yarn add "\
15
15
  "typescript@~3.8.0 "\
16
16
  "react@~16.11.0 "\
@@ -3,11 +3,12 @@ module Quilt
3
3
  end
4
4
 
5
5
  require "quilt_rails/version"
6
- require "quilt_rails/engine"
7
6
  require "quilt_rails/logger"
8
7
  require "quilt_rails/configuration"
9
8
  require "quilt_rails/react_renderable"
10
9
  require "quilt_rails/performance"
11
10
  require "quilt_rails/trusted_ui_server_csrf_strategy"
12
11
  require "quilt_rails/header_csrf_strategy"
12
+
13
+ require "quilt_rails/engine"
13
14
  require "quilt_rails/monkey_patches/active_support_reloader" if Rails.env.development?
@@ -1,15 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Quilt
4
- class Configuration
5
- attr_accessor :react_server_host, :react_server_protocol
3
+ require "active_support/ordered_options"
6
4
 
5
+ module Quilt
6
+ class Configuration < ActiveSupport::OrderedOptions
7
7
  def initialize
8
- ip = ENV['REACT_SERVER_IP'] || 'localhost'
9
- port = ENV['REACT_SERVER_PORT'] || 8081
8
+ super
9
+ react_server_ip = ENV['REACT_SERVER_IP'] || "localhost"
10
+ react_server_port = ENV['REACT_SERVER_PORT'] || 8081
11
+
12
+ self.react_server_host = "#{react_server_ip}:#{react_server_port}"
13
+ self.react_server_protocol = ENV['REACT_SERVER_PROTOCOL'] || "http"
14
+ self.mount = true
15
+ end
10
16
 
11
- @react_server_host = "#{ip}:#{port}"
12
- @react_server_protocol = ENV['REACT_SERVER_PROTOCOL'] || 'http'
17
+ def mount?
18
+ mount
13
19
  end
14
20
  end
15
21
 
@@ -4,9 +4,13 @@ module Quilt
4
4
  class Engine < ::Rails::Engine
5
5
  isolate_namespace Quilt
6
6
 
7
+ config.quilt = Quilt.configuration
8
+
7
9
  initializer(:mount_quilt, before: :add_builtin_route) do |app|
8
- app.routes.append do
9
- mount(Quilt::Engine, at: '/') unless has_named_route?(:quilt)
10
+ if config.quilt.mount?
11
+ app.routes.append do
12
+ mount(Quilt::Engine, at: '/') unless has_named_route?(:quilt)
13
+ end
10
14
  end
11
15
  end
12
16
  end
@@ -25,9 +25,10 @@ module Quilt
25
25
 
26
26
  class NoSameSiteHeaderError < StandardError
27
27
  def initialize
28
- # rubocop:disable LineLength
29
- super "CSRF verification failed. This request is missing the `x-shopify-react-xhr` header, or it does not have the expected value."
30
- # rubocop:enable LineLength
28
+ super(<<~MSG.squish)
29
+ CSRF verification failed. This request is missing the
30
+ `x-shopify-react-xhr` header, or it does not have the expected value.
31
+ MSG
31
32
  end
32
33
  end
33
34
  end
@@ -7,25 +7,39 @@ module Quilt
7
7
  attr_accessor :navigations
8
8
  attr_accessor :connection
9
9
 
10
- def self.from_params(params)
11
- params.transform_keys! { |key| key.underscore.to_sym }
12
- params[:connection] = { effectiveType: 'unknown' } if params[:connection].blank?
10
+ class << self
11
+ def from_params(params)
12
+ params.transform_keys! { |key| key.underscore.to_sym }
13
+ params[:connection] = { effectiveType: 'unknown' } if params[:connection].blank?
13
14
 
14
- connection = Connection.from_params(params[:connection])
15
+ connection = Connection.from_params(params[:connection])
15
16
 
16
- Report.new(
17
- connection: connection,
18
- navigations: (params[:navigations] || []).map do |navigation|
17
+ Report.new(
18
+ connection: connection,
19
+ navigations: build_navigations(params[:navigations], connection: connection),
20
+ events: build_events(params[:events], connection: connection),
21
+ )
22
+ end
23
+
24
+ private
25
+
26
+ def build_navigations(navigations_params, connection:)
27
+ navigations_params ||= []
28
+ navigations_params.map do |navigation|
19
29
  navigation = Navigation.from_params(navigation)
20
30
  navigation.connection = connection
21
31
  navigation
22
- end,
23
- events: (params[:events] || []).map do |event|
32
+ end
33
+ end
34
+
35
+ def build_events(events_params, connection:)
36
+ events_params ||= []
37
+ events_params.map do |event|
24
38
  event = Event.from_params(event)
25
39
  event.connection = connection
26
40
  event
27
- end,
28
- )
41
+ end
42
+ end
29
43
  end
30
44
 
31
45
  def initialize(events:, navigations:, connection:)
@@ -52,17 +52,19 @@ module Quilt
52
52
 
53
53
  class ReactServerNoResponseError < StandardError
54
54
  def initialize(url)
55
- # rubocop:disable LineLength
56
- super "Errno::ECONNREFUSED: Waiting for React server to boot up. If this error persists verify that @shopify/react-server is configured on #{url}"
57
- # rubocop:enable LineLength
55
+ super(<<~MSG.squish)
56
+ Errno::ECONNREFUSED: Waiting for React server to boot up.
57
+ If this error persists verify that @shopify/react-server is configured on #{url}"
58
+ MSG
58
59
  end
59
60
  end
60
61
 
61
62
  class DoNotIntegrationTestError < StandardError
62
63
  def initialize
63
- # rubocop:disable LineLength
64
- super "Do not try to use Rails integration tests on your quilt_rails app. Instead use Jest and @shopify/react-testing to test your React application directly."
65
- # rubocop:enable LineLength
64
+ super(<<~MSG.squish)
65
+ Do not try to use Rails integration tests on your quilt_rails app.
66
+ Instead use Jest and @shopify/react-testing to test your React application directly."
67
+ MSG
66
68
  end
67
69
  end
68
70
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Quilt
3
- VERSION = "3.3.0"
3
+ VERSION = "3.3.1"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quilt_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.0
4
+ version: 3.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mathew Allen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-10 00:00:00.000000000 Z
11
+ date: 2020-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties