diff --git a/.gitignore b/.gitignore
index 80066c2..fce8cc2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,4 +14,4 @@ breezy/build/**/*.js
props_template/performance/**/*.png
.tool-versions
testapp/
-superglue/
+*.sqlite3
diff --git a/Gemfile b/Gemfile
index 3b3d0a2..0a587ec 100644
--- a/Gemfile
+++ b/Gemfile
@@ -3,7 +3,7 @@ gemspec
gem 'rails', '~> 7.2.0'
gem 'selenium-webdriver'
-gem 'props_template'
+gem 'props_template', path: "../props_template"
gem 'standard'
gem 'capybara'
gem 'minitest'
diff --git a/app/channels/superglue/streams/broadcasts.rb b/app/channels/superglue/streams/broadcasts.rb
new file mode 100644
index 0000000..6321f40
--- /dev/null
+++ b/app/channels/superglue/streams/broadcasts.rb
@@ -0,0 +1,176 @@
+# Provides the broadcast actions in synchronous and asynchronous form for the Superglue::StreamsChannel.
+# See Superglue::Broadcastable for the user-facing API that invokes these methods with most of the paperwork filled out already.
+#
+# Can be used directly using something like Superglue::StreamsChannel.broadcast_remove_to :entries, target: 1.
+module Superglue::Streams::Broadcasts
+ # include Superglue::Streams::ActionHelper
+
+ # def broadcast_remove_to(*streamables, **opts)
+ # broadcast_action_to(*streamables, action: :remove, render: false, **opts)
+ # end
+
+ def broadcast_replace_to(*streamables, **opts)
+ broadcast_action_to(*streamables, action: :replace, **opts)
+ end
+
+ # def broadcast_update_to(*streamables, **opts)
+ # broadcast_action_to(*streamables, action: :update, **opts)
+ # end
+
+ # def broadcast_before_to(*streamables, **opts)
+ # broadcast_action_to(*streamables, action: :before, **opts)
+ # end
+
+ # def broadcast_after_to(*streamables, **opts)
+ # broadcast_action_to(*streamables, action: :after, **opts)
+ # end
+
+ def broadcast_append_to(*streamables, **opts)
+ broadcast_action_to(*streamables, action: :append, **opts)
+ end
+
+ def broadcast_prepend_to(*streamables, **opts)
+ broadcast_action_to(*streamables, action: :prepend, **opts)
+ end
+
+ def broadcast_refresh_to(*streamables, **opts)
+ request_id = Superglue.current_request_id
+ content = JSON.generate({
+ type: "message",
+ action: "refresh",
+ requestId: request_id,
+ options: opts
+ })
+ broadcast_stream_to(*streamables, content: content)
+ end
+
+ def broadcast_action_to(*streamables, action:, target: nil, targets: nil, options: {}, **rendering)
+ locals = rendering[:locals] || {}
+ targets = (target ? [target] : targets)
+
+ targets = targets.map do |item|
+ convert_to_superglue_fragment_id(item)
+ end
+
+ locals[:broadcast_targets] = targets
+ locals[:broadcast_action] = action
+ locals[:broadcast_options] = options
+ rendering[:locals] = locals
+
+ broadcast_stream_to(*streamables, content: render_broadcast_action(rendering))
+ end
+
+ def broadcast_replace_later_to(*streamables, **opts)
+ broadcast_action_later_to(*streamables, action: :replace, **opts)
+ end
+
+ # def broadcast_update_later_to(*streamables, **opts)
+ # broadcast_action_later_to(*streamables, action: :update, **opts)
+ # end
+
+ # def broadcast_before_later_to(*streamables, **opts)
+ # broadcast_action_later_to(*streamables, action: :before, **opts)
+ # end
+
+ # def broadcast_after_later_to(*streamables, **opts)
+ # broadcast_action_later_to(*streamables, action: :after, **opts)
+ # end
+
+ ### convert_to_turbo_stream_dom_id ican use this as the fragment name!
+
+ def broadcast_append_later_to(*streamables, **opts)
+ broadcast_action_later_to(*streamables, action: :append, **opts)
+ end
+
+ def broadcast_prepend_later_to(*streamables, **opts)
+ broadcast_action_later_to(*streamables, action: :prepend, **opts)
+ end
+
+ def broadcast_refresh_later_to(*streamables, request_id: Superglue.current_request_id, **opts)
+ stream_name = stream_name_from(streamables)
+
+ refresh_debouncer_for(*streamables, request_id: request_id).debounce do
+ content = JSON.generate({
+ type: "message",
+ action: "refresh",
+ requestId: request_id,
+ options: opts
+ })
+
+ Superglue::Streams::BroadcastStreamJob.perform_later stream_name, content: content
+ end
+ end
+
+ def broadcast_action_later_to(*streamables, action:, target: nil, targets: nil, options: {}, **rendering)
+ streamables.flatten!
+ streamables.compact_blank!
+
+ return unless streamables.present?
+
+ targets = (target ? [target] : targets).map do |item|
+ convert_to_superglue_fragment_id(item)
+ end
+
+ # bugs
+ # ActionBroadcastJOB doesn't take in targets
+ # targets does not work with multi ids
+ Superglue::Streams::ActionBroadcastJob.perform_later \
+ stream_name_from(streamables), action: action, targets: targets, options: options, **rendering
+ end
+
+ # def broadcast_render_to(*streamables, **rendering)
+ # broadcast_stream_to(*streamables, content: render_format(:superglue_stream, **rendering))
+ # end
+
+ # def broadcast_render_later_to(*streamables, **rendering)
+ # Superglue::Streams::BroadcastJob.perform_later stream_name_from(streamables), **rendering
+ # end
+
+ def broadcast_stream_to(*streamables, content:)
+ streamables.flatten!
+ streamables.compact_blank!
+
+ return unless streamables.present?
+
+ ActionCable.server.broadcast stream_name_from(streamables), content
+ end
+
+ def refresh_debouncer_for(*streamables, request_id: nil) # :nodoc:
+ Superglue::ThreadDebouncer.for("superglue-refresh-debouncer-#{stream_name_from(streamables.including(request_id))}")
+ end
+
+ private
+
+ def convert_to_superglue_fragment_id(target, include_selector: false)
+ target_array = Array.wrap(target)
+ if target_array.any? { |value| value.respond_to?(:to_key) }
+ ActionView::RecordIdentifier.dom_id(*target_array)
+ else
+ target
+ end
+ end
+
+ def render_format(format, **rendering)
+ rendering[:layout] = "superglue/layouts/fragment"
+ ApplicationController.render(formats: [format], **rendering)
+ end
+
+ def render_broadcast_action(rendering)
+ # content = rendering.delete(:content) # i should remove content
+ # html = rendering.delete(:html) # i should add json and stringify it
+ render = rendering.delete(:render)
+ json = rendering.delete(:json)
+
+ if render == false
+ nil
+ elsif rendering.present?
+ if json
+ rendering[:partial] = "superglue/body"
+ rendering[:locals] ||= {}
+ rendering[:locals][:broadcast_json] = json
+ end
+
+ render_format(:json, **rendering)
+ end
+ end
+end
diff --git a/app/channels/superglue/streams/stream_name.rb b/app/channels/superglue/streams/stream_name.rb
new file mode 100644
index 0000000..c20cb5f
--- /dev/null
+++ b/app/channels/superglue/streams/stream_name.rb
@@ -0,0 +1,32 @@
+# Stream names are how we identify which updates should go to which users. All streams run over the same
+# Superglue::StreamsChannel, but each with their own subscription. Since stream names are exposed directly to the user
+# via the HTML stream subscription tags, we need to ensure that the name isn't tampered with, so the names are signed
+# upon generation and verified upon receipt. All verification happens through the Superglue.signed_stream_verifier.
+module Superglue::Streams::StreamName
+ # Used by Superglue::StreamsChannel to verify a signed stream name.
+ def verified_stream_name(signed_stream_name)
+ Superglue.signed_stream_verifier.verified signed_stream_name
+ end
+
+ # Used by Superglue::StreamsHelper#Superglue_stream_from(*streamables) to generate a signed stream name.
+ def signed_stream_name(streamables)
+ Superglue.signed_stream_verifier.generate stream_name_from(streamables)
+ end
+
+ module ClassMethods
+ # Can be used by custom Superglue stream channels to obtain signed stream name from params
+ def verified_stream_name_from_params
+ self.class.verified_stream_name(params[:signed_stream_name])
+ end
+ end
+
+ private
+
+ def stream_name_from(streamables)
+ if streamables.is_a?(Array)
+ streamables.map { |streamable| stream_name_from(streamable) }.join(':')
+ else
+ streamables.then { |streamable| streamable.try(:to_gid_param) || streamable.to_param }
+ end
+ end
+end
diff --git a/app/channels/superglue/streams_channel.rb b/app/channels/superglue/streams_channel.rb
new file mode 100644
index 0000000..c43be4d
--- /dev/null
+++ b/app/channels/superglue/streams_channel.rb
@@ -0,0 +1,13 @@
+class Superglue::StreamsChannel < ActionCable::Channel::Base
+ extend Superglue::Streams::StreamName
+ extend Superglue::Streams::Broadcasts
+ include Superglue::Streams::StreamName::ClassMethods
+
+ def subscribed
+ if stream_name = verified_stream_name_from_params
+ stream_from stream_name
+ else
+ reject
+ end
+ end
+end
diff --git a/app/controllers/concerns/superglue/request_id_tracking.rb b/app/controllers/concerns/superglue/request_id_tracking.rb
new file mode 100644
index 0000000..0b94446
--- /dev/null
+++ b/app/controllers/concerns/superglue/request_id_tracking.rb
@@ -0,0 +1,13 @@
+module Superglue::RequestIdTracking
+ extend ActiveSupport::Concern
+
+ included do
+ around_action :superglue_tracking_request_id
+ end
+
+ private
+
+ def superglue_tracking_request_id(&block)
+ Superglue.with_request_id(request.headers["X-Superglue-Request-Id"], &block)
+ end
+end
diff --git a/app/helpers/superglue/streams/action_helper.rb b/app/helpers/superglue/streams/action_helper.rb
new file mode 100644
index 0000000..245a514
--- /dev/null
+++ b/app/helpers/superglue/streams/action_helper.rb
@@ -0,0 +1,12 @@
+module Superglue::Streams::ActionHelper
+ private
+
+ def convert_to_superglue_fragment_id(target, include_selector: false)
+ target_array = Array.wrap(target)
+ if target_array.any? { |value| value.respond_to?(:to_key) }
+ ActionView::RecordIdentifier.dom_id(*target_array)
+ else
+ target
+ end
+ end
+end
diff --git a/app/jobs/superglue/streams/action_broadcast_job.rb b/app/jobs/superglue/streams/action_broadcast_job.rb
new file mode 100644
index 0000000..761b422
--- /dev/null
+++ b/app/jobs/superglue/streams/action_broadcast_job.rb
@@ -0,0 +1,8 @@
+# The job that powers all the broadcast_$action_later broadcasts available in Turbo::Streams::Broadcasts.
+class Superglue::Streams::ActionBroadcastJob < ActiveJob::Base
+ discard_on ActiveJob::DeserializationError
+
+ def perform(stream, action:, targets:, options: {}, **rendering)
+ Superglue::StreamsChannel.broadcast_action_to stream, action: action, targets: targets, options: options, **rendering
+ end
+end
diff --git a/app/jobs/superglue/streams/broadcast_stream_job.rb b/app/jobs/superglue/streams/broadcast_stream_job.rb
new file mode 100644
index 0000000..1d0cbb0
--- /dev/null
+++ b/app/jobs/superglue/streams/broadcast_stream_job.rb
@@ -0,0 +1,7 @@
+class Superglue::Streams::BroadcastStreamJob < ActiveJob::Base
+ discard_on ActiveJob::DeserializationError
+
+ def perform(stream, content:)
+ Superglue::StreamsChannel.broadcast_stream_to(stream, content: content)
+ end
+end
diff --git a/app/models/concerns/superglue/broadcastable.rb b/app/models/concerns/superglue/broadcastable.rb
new file mode 100644
index 0000000..c66f567
--- /dev/null
+++ b/app/models/concerns/superglue/broadcastable.rb
@@ -0,0 +1,210 @@
+module Superglue::Broadcastable
+ extend ActiveSupport::Concern
+
+ included do
+ thread_mattr_accessor :suppressed_superglue_broadcasts, instance_accessor: false
+ delegate :suppressed_superglue_broadcasts?, to: "self.class"
+ end
+
+ module ClassMethods
+ def broadcasts_to(stream, inserts_by: :append, target: broadcast_target_default, **rendering)
+ after_create_commit -> { broadcast_action_later_to(stream.try(:call, self) || send(stream), action: inserts_by, target: target.try(:call, self) || target, **rendering) }
+ after_update_commit -> { broadcast_replace_later_to(stream.try(:call, self) || send(stream), **rendering) }
+ after_destroy_commit -> { broadcast_remove_to(stream.try(:call, self) || send(stream)) }
+ end
+
+ def broadcasts(stream = model_name.plural, inserts_by: :append, target: broadcast_target_default, **rendering)
+ after_create_commit -> { broadcast_action_later_to(stream, action: inserts_by, target: target.try(:call, self) || target, **rendering) }
+ after_update_commit -> { broadcast_replace_later(**rendering) }
+ after_destroy_commit -> { broadcast_remove }
+ end
+
+ def broadcasts_refreshes_to(stream)
+ after_commit -> { broadcast_refresh_later_to(stream.try(:call, self) || send(stream)) }
+ end
+
+ def broadcasts_refreshes(stream = model_name.plural)
+ after_create_commit -> { broadcast_refresh_later_to(stream) }
+ after_update_commit -> { broadcast_refresh_later }
+ after_destroy_commit -> { broadcast_refresh }
+ end
+
+ def broadcast_target_default
+ model_name.plural
+ end
+
+ def suppressing_superglue_broadcasts(&block)
+ original, self.suppressed_superglue_broadcasts = suppressed_superglue_broadcasts, true
+ yield
+ ensure
+ self.suppressed_superglue_broadcasts = original
+ end
+
+ def suppressed_superglue_broadcasts?
+ suppressed_superglue_broadcasts
+ end
+ end
+
+ def broadcast_remove_to(*streamables, target: self, **rendering)
+ Superglue::StreamsChannel.broadcast_remove_to(*streamables, **extract_options_and_add_target(rendering, target: target)) unless suppressed_superglue_broadcasts?
+ end
+
+ def broadcast_remove(**rendering)
+ broadcast_remove_to self, **rendering
+ end
+
+ def broadcast_replace_to(*streamables, **rendering)
+ Superglue::StreamsChannel.broadcast_replace_to(*streamables, **extract_options_and_add_target(rendering, target: self)) unless suppressed_superglue_broadcasts?
+ end
+
+ def broadcast_replace(**rendering)
+ broadcast_replace_to self, **rendering
+ end
+
+ def broadcast_update_to(*streamables, **rendering)
+ Superglue::StreamsChannel.broadcast_update_to(*streamables, **extract_options_and_add_target(rendering, target: self)) unless suppressed_superglue_broadcasts?
+ end
+
+ def broadcast_update(**rendering)
+ broadcast_update_to self, **rendering
+ end
+
+ def broadcast_before_to(*streamables, target: nil, targets: nil, **rendering)
+ raise ArgumentError, "at least one of target or targets is required" unless target || targets
+
+ Superglue::StreamsChannel.broadcast_before_to(*streamables, **extract_options_and_add_target(rendering.merge(target: target, targets: targets)))
+ end
+
+ def broadcast_after_to(*streamables, target: nil, targets: nil, **rendering)
+ raise ArgumentError, "at least one of target or targets is required" unless target || targets
+
+ Superglue::StreamsChannel.broadcast_after_to(*streamables, **extract_options_and_add_target(rendering.merge(target: target, targets: targets)))
+ end
+
+ def broadcast_append_to(*streamables, target: broadcast_target_default, **rendering)
+ Superglue::StreamsChannel.broadcast_append_to(*streamables, **extract_options_and_add_target(rendering, target: target)) unless suppressed_superglue_broadcasts?
+ end
+
+ def broadcast_append(target: broadcast_target_default, **rendering)
+ broadcast_append_to self, target: target, **rendering
+ end
+
+ def broadcast_prepend_to(*streamables, target: broadcast_target_default, **rendering)
+ Superglue::StreamsChannel.broadcast_prepend_to(*streamables, **extract_options_and_add_target(rendering, target: target)) unless suppressed_superglue_broadcasts?
+ end
+
+ def broadcast_prepend(target: broadcast_target_default, **rendering)
+ broadcast_prepend_to self, target: target, **rendering
+ end
+
+ def broadcast_refresh_to(*streamables)
+ Superglue::StreamsChannel.broadcast_refresh_to(*streamables) unless suppressed_superglue_broadcasts?
+ end
+
+ def broadcast_refresh
+ broadcast_refresh_to self
+ end
+
+ def broadcast_action_to(*streamables, action:, target: broadcast_target_default, attributes: {}, **rendering)
+ Superglue::StreamsChannel.broadcast_action_to(*streamables, action: action, attributes: attributes, **extract_options_and_add_target(rendering, target: target)) unless suppressed_superglue_broadcasts?
+ end
+
+ def broadcast_action(action, target: broadcast_target_default, attributes: {}, **rendering)
+ broadcast_action_to self, action: action, target: target, attributes: attributes, **rendering
+ end
+
+ def broadcast_replace_later_to(*streamables, **rendering)
+ Superglue::StreamsChannel.broadcast_replace_later_to(*streamables, **extract_options_and_add_target(rendering, target: self)) unless suppressed_superglue_broadcasts?
+ end
+
+ def broadcast_replace_later(**rendering)
+ broadcast_replace_later_to self, **rendering
+ end
+
+ def broadcast_update_later_to(*streamables, **rendering)
+ Superglue::StreamsChannel.broadcast_update_later_to(*streamables, **extract_options_and_add_target(rendering, target: self)) unless suppressed_superglue_broadcasts?
+ end
+
+ def broadcast_update_later(**rendering)
+ broadcast_update_later_to self, **rendering
+ end
+
+ def broadcast_append_later_to(*streamables, target: broadcast_target_default, **rendering)
+ Superglue::StreamsChannel.broadcast_append_later_to(*streamables, **extract_options_and_add_target(rendering, target: target)) unless suppressed_superglue_broadcasts?
+ end
+
+ def broadcast_append_later(target: broadcast_target_default, **rendering)
+ broadcast_append_later_to self, target: target, **rendering
+ end
+
+ def broadcast_prepend_later_to(*streamables, target: broadcast_target_default, **rendering)
+ Superglue::StreamsChannel.broadcast_prepend_later_to(*streamables, **extract_options_and_add_target(rendering, target: target)) unless suppressed_superglue_broadcasts?
+ end
+
+ def broadcast_prepend_later(target: broadcast_target_default, **rendering)
+ broadcast_prepend_later_to self, target: target, **rendering
+ end
+
+ def broadcast_refresh_later_to(*streamables)
+ Superglue::StreamsChannel.broadcast_refresh_later_to(*streamables, request_id: Superglue.current_request_id) unless suppressed_superglue_broadcasts?
+ end
+
+ def broadcast_refresh_later
+ broadcast_refresh_later_to self
+ end
+
+ def broadcast_action_later_to(*streamables, action:, target: broadcast_target_default, attributes: {}, **rendering)
+ Superglue::StreamsChannel.broadcast_action_later_to(*streamables, action: action, attributes: attributes, **extract_options_and_add_target(rendering, target: target)) unless suppressed_superglue_broadcasts?
+ end
+
+ def broadcast_action_later(action:, target: broadcast_target_default, attributes: {}, **rendering)
+ broadcast_action_later_to self, action: action, target: target, attributes: attributes, **rendering
+ end
+
+ def broadcast_render(**rendering)
+ broadcast_render_to self, **rendering
+ end
+
+ def broadcast_render_to(*streamables, **rendering)
+ Superglue::StreamsChannel.broadcast_render_to(*streamables, **extract_options_and_add_target(rendering, target: self)) unless suppressed_superglue_broadcasts?
+ end
+
+ def broadcast_render_later(**rendering)
+ broadcast_render_later_to self, **rendering
+ end
+
+ def broadcast_render_later_to(*streamables, **rendering)
+ Superglue::StreamsChannel.broadcast_render_later_to(*streamables, **extract_options_and_add_target(rendering)) unless suppressed_superglue_broadcasts?
+ end
+
+ private
+
+ def broadcast_target_default
+ self.class.broadcast_target_default
+ end
+
+ def extract_options_and_add_target(rendering = {}, target: broadcast_target_default)
+ broadcast_rendering_with_defaults(rendering).tap do |options|
+ options[:target] = target if !options.key?(:target) && !options.key?(:targets)
+ end
+ end
+
+ def broadcast_rendering_with_defaults(options)
+ options.tap do |o|
+ # Add the current instance into the locals with the element name (which is the un-namespaced name)
+ # as the key. This parallels how the ActionView::ObjectRenderer would create a local variable.
+ o[:locals] = (o[:locals] || {}).reverse_merge(model_name.element.to_sym => self).compact
+
+ if o[:html] || o[:partial]
+ return o
+ elsif o[:template] || o[:renderable]
+ o[:layout] = false
+ elsif o[:render] == false
+ return o
+ else
+ # if none of these options are passed in, it will set a partial from #to_partial_path
+ o[:partial] ||= to_partial_path
+ end
+ end
+ end
+end
diff --git a/app/models/superglue/debouncer.rb b/app/models/superglue/debouncer.rb
new file mode 100644
index 0000000..40dfc1b
--- /dev/null
+++ b/app/models/superglue/debouncer.rb
@@ -0,0 +1,25 @@
+class Superglue::Debouncer
+ attr_reader :delay, :scheduled_task
+
+ DEFAULT_DELAY = 0.5
+
+ def initialize(delay: DEFAULT_DELAY)
+ @delay = delay
+ @scheduled_task = nil
+ end
+
+ def debounce(&block)
+ scheduled_task&.cancel unless scheduled_task&.complete?
+ @scheduled_task = Concurrent::ScheduledTask.execute(delay, &block)
+ end
+
+ def wait
+ scheduled_task&.wait(wait_timeout)
+ end
+
+ private
+
+ def wait_timeout
+ delay + 1
+ end
+end
diff --git a/app/models/superglue/thread_debouncer.rb b/app/models/superglue/thread_debouncer.rb
new file mode 100644
index 0000000..f1e6abf
--- /dev/null
+++ b/app/models/superglue/thread_debouncer.rb
@@ -0,0 +1,29 @@
+# A decorated debouncer that will store instances in the current thread clearing them
+# after the debounced logic triggers.
+class Superglue::ThreadDebouncer
+ delegate :wait, to: :debouncer
+
+ def self.for(key, delay: Superglue::Debouncer::DEFAULT_DELAY)
+ Thread.current[key] ||= new(key, Thread.current, delay: delay)
+ end
+
+ private_class_method :new
+
+ def initialize(key, thread, delay:)
+ @key = key
+ @debouncer = Superglue::Debouncer.new(delay: delay)
+ @thread = thread
+ end
+
+ def debounce
+ debouncer.debounce do
+ yield.tap do
+ thread[key] = nil
+ end
+ end
+ end
+
+ private
+
+ attr_reader :key, :debouncer, :thread
+end
diff --git a/app/views/superglue/body.json.props b/app/views/superglue/body.json.props
new file mode 100644
index 0000000..c1e5fb9
--- /dev/null
+++ b/app/views/superglue/body.json.props
@@ -0,0 +1,8 @@
+# json.disable_deferments!
+json.data broadcast_json
+
+json.fragments json.fragments!
+json.type "message"
+json.action broadcast_action
+json.targets broadcast_targets
+json.options broadcast_options
diff --git a/app/views/superglue/layouts/_fragment.json.props b/app/views/superglue/layouts/_fragment.json.props
new file mode 100644
index 0000000..c29cc10
--- /dev/null
+++ b/app/views/superglue/layouts/_fragment.json.props
@@ -0,0 +1,11 @@
+# json.disable_deferments!
+
+json.data do
+ yield
+end
+
+json.fragments json.fragments!
+json.type "message"
+json.action broadcast_action
+json.targets broadcast_targets
+json.options broadcast_options
diff --git a/lib/superglue.rb b/lib/superglue.rb
index b0a095d..c456bf4 100644
--- a/lib/superglue.rb
+++ b/lib/superglue.rb
@@ -1,40 +1,38 @@
-require "superglue/helpers"
-require "superglue/redirection"
-require "superglue/rendering"
-require "superglue/resolver"
-require "props_template"
-require "form_props"
+require 'superglue/helpers'
+require 'superglue/rendering'
+require 'superglue/resolver'
+require 'superglue/engine'
+require 'props_template'
+require 'form_props'
module Superglue
- module Controller
- include Redirection
- include Helpers
+ extend ActiveSupport::Autoload
- def self.included(base)
- base.include ::Superglue::Rendering
- if base.respond_to?(:helper_method)
- base.helper_method :param_to_dig_path
- base.helper_method :render_props
- end
- end
- end
+ mattr_accessor :draw_routes, default: true
- class Engine < ::Rails::Engine
- config.superglue = ActiveSupport::OrderedOptions.new
- config.superglue.auto_include = true
+ thread_mattr_accessor :current_request_id
- initializer :superglue do |app|
- ActiveSupport.on_load(:action_controller) do
- next if self != ActionController::Base
+ class << self
+ attr_writer :signed_stream_verifier_key
- if app.config.superglue.auto_include
- include Controller
+ def signed_stream_verifier
+ @signed_stream_verifier ||= ActiveSupport::MessageVerifier.new(
+ signed_stream_verifier_key,
+ digest: 'SHA256',
+ serializer: JSON
+ )
+ end
+
+ def signed_stream_verifier_key
+ @signed_stream_verifier_key or raise ArgumentError, 'Superglue requires a signed_stream_verifier_key'
+ end
- prepend_view_path(
- Superglue::Resolver.new(Rails.root.join("app/views"))
- )
- end
- end
+ def with_request_id(request_id)
+ old_request_id = current_request_id
+ self.current_request_id = request_id
+ yield
+ ensure
+ self.current_request_id = old_request_id
end
end
end
diff --git a/lib/superglue/engine.rb b/lib/superglue/engine.rb
new file mode 100644
index 0000000..b6ebdb3
--- /dev/null
+++ b/lib/superglue/engine.rb
@@ -0,0 +1,38 @@
+module Superglue
+ module Controller
+ include Helpers
+
+ def self.included(base)
+ base.include ::Superglue::Rendering
+ return unless base.respond_to?(:helper_method)
+
+ base.helper_method :param_to_dig_path
+ base.helper_method :render_props
+ end
+ end
+
+ class Engine < ::Rails::Engine
+ config.superglue = ActiveSupport::OrderedOptions.new
+ config.superglue.auto_include = true
+
+ initializer :superglue do |app|
+ ActiveSupport.on_load(:action_controller) do
+ next if self != ActionController::Base
+
+ include Controller
+ include Superglue::RequestIdTracking
+
+ prepend_view_path(
+ Superglue::Resolver.new(Rails.root.join("app/views"))
+ )
+ end
+ end
+
+ initializer "superglue.signed_stream_verifier_key" do
+ config.after_initialize do
+ Superglue.signed_stream_verifier_key = config.superglue.signed_stream_verifier_key ||
+ Rails.application.key_generator.generate_key("superglue/signed_stream_verifier_key")
+ end
+ end
+ end
+end
diff --git a/lib/superglue/redirection.rb b/lib/superglue/redirection.rb
deleted file mode 100644
index 36c049d..0000000
--- a/lib/superglue/redirection.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-module Superglue
- module Redirection
- def _compute_redirect_to_location(request, options)
- computed_location = URI.parse(super)
- next_param = Rack::Utils
- .parse_nested_query(computed_location.query)
-
- if request.params[:__] == "0"
- computed_location.query = next_param.merge({__: "0"}).to_query
- end
-
- computed_location.to_s
- end
-
- def redirect_back_with_props_at(opts)
- if request.referrer && params[:props_at]
- referrer_url = URI.parse(request.referrer)
- referrer_url.query = Rack::Utils
- .parse_nested_query(referrer_url.query)
- .merge({props_at: params[:props_at]})
- .to_query
-
- redirect_to referrer_url.to_s, opts
- else
- redirect_back(opts)
- end
- end
- end
-end
diff --git a/test/dummy/Rakefile b/test/dummy/Rakefile
new file mode 100644
index 0000000..9a5ea73
--- /dev/null
+++ b/test/dummy/Rakefile
@@ -0,0 +1,6 @@
+# Add your own tasks in files placed in lib/tasks ending in .rake,
+# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
+
+require_relative "config/application"
+
+Rails.application.load_tasks
diff --git a/test/views/render/admin/index.jsx b/test/dummy/app/assets/images/.keep
similarity index 100%
rename from test/views/render/admin/index.jsx
rename to test/dummy/app/assets/images/.keep
diff --git a/test/dummy/app/assets/stylesheets/application.css b/test/dummy/app/assets/stylesheets/application.css
new file mode 100644
index 0000000..0ebd7fe
--- /dev/null
+++ b/test/dummy/app/assets/stylesheets/application.css
@@ -0,0 +1,15 @@
+/*
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
+ * listed below.
+ *
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
+ *
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
+ * files in this directory. Styles in this file should be added after the last require_* statement.
+ * It is generally better to create a new file per style scope.
+ *
+ *= require_tree .
+ *= require_self
+ */
diff --git a/test/dummy/app/controllers/admin/comments_controller.rb b/test/dummy/app/controllers/admin/comments_controller.rb
new file mode 100644
index 0000000..71c16fe
--- /dev/null
+++ b/test/dummy/app/controllers/admin/comments_controller.rb
@@ -0,0 +1,16 @@
+module Admin
+ class ScopedController < ApplicationController
+ # require "action_view/testing/resolvers"
+
+ before_action :use_jsx_rendering_defaults
+
+ append_view_path(Superglue::Resolver.new("test/views"))
+ append_view_path "test/views"
+
+ layout "application"
+
+ def show
+ render "admin/posts/index"
+ end
+ end
+end
diff --git a/test/dummy/app/controllers/admin/posts_controller.rb b/test/dummy/app/controllers/admin/posts_controller.rb
new file mode 100644
index 0000000..be94dde
--- /dev/null
+++ b/test/dummy/app/controllers/admin/posts_controller.rb
@@ -0,0 +1,14 @@
+module Admin
+ class PostsController < ApplicationController
+ before_action :use_jsx_rendering_defaults
+
+ append_view_path(Superglue::Resolver.new("test/views"))
+ append_view_path "test/views"
+
+ layout "layouts/jsx_application"
+
+ def show
+ render "admin/posts/index"
+ end
+ end
+end
diff --git a/test/dummy/app/controllers/application_controller.rb b/test/dummy/app/controllers/application_controller.rb
new file mode 100644
index 0000000..8d08250
--- /dev/null
+++ b/test/dummy/app/controllers/application_controller.rb
@@ -0,0 +1,6 @@
+class ApplicationController < ActionController::Base
+ # Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has.
+ allow_browser versions: :modern
+
+ # superglue_template "application/superglue"
+end
diff --git a/test/views/render/simple.jsx b/test/dummy/app/controllers/concerns/.keep
similarity index 100%
rename from test/views/render/simple.jsx
rename to test/dummy/app/controllers/concerns/.keep
diff --git a/test/dummy/app/controllers/jsx_controller.rb b/test/dummy/app/controllers/jsx_controller.rb
new file mode 100644
index 0000000..c77eabb
--- /dev/null
+++ b/test/dummy/app/controllers/jsx_controller.rb
@@ -0,0 +1,72 @@
+class JsxController < ApplicationController
+ before_action :use_jsx_rendering_defaults, except: [:valid_pair_no_defaults]
+
+ append_view_path(Superglue::Resolver.new("test/views"))
+ append_view_path "test/views"
+
+ layout "layouts/jsx_application"
+
+ def simple
+ end
+
+ def simple_explicit
+ render :simple
+ end
+
+ def valid_pair
+ end
+
+ def valid_pair_no_defaults
+ render :valid_pair
+ end
+
+ def valid_single
+ render :valid_single
+ end
+
+ def uncommon_pair
+ end
+
+ def bad_single
+ end
+
+ def bad_pair
+ end
+
+ def render_does_not_exist
+ render :does_not_exist
+ end
+
+ def simple_render_with_no_superglue_template
+ self._superglue_template = "superglue-template-does-not-exist"
+ render :valid_pair
+ end
+
+ def unsupported_option_file
+ render file: "jsx/simple.html.erb"
+ end
+
+ def unsupported_option_inline
+ render inline: "blah"
+ end
+
+ def unsupported_option_html
+ render html: "
"
+ end
+
+ def unsupported_option_body
+ render body: ""
+ end
+
+ def unsupported_option_partial
+ render partial: "some-partial"
+ end
+
+ def unsupported_option_plain
+ render plain: "plain"
+ end
+
+ def form_authenticity_token
+ "secret"
+ end
+end
diff --git a/test/dummy/app/controllers/request_ids_controller.rb b/test/dummy/app/controllers/request_ids_controller.rb
new file mode 100644
index 0000000..0add059
--- /dev/null
+++ b/test/dummy/app/controllers/request_ids_controller.rb
@@ -0,0 +1,5 @@
+class RequestIdsController < ApplicationController
+ def show
+ render json: {request_id: Superglue.current_request_id}
+ end
+end
diff --git a/test/dummy/app/helpers/application_helper.rb b/test/dummy/app/helpers/application_helper.rb
new file mode 100644
index 0000000..de6be79
--- /dev/null
+++ b/test/dummy/app/helpers/application_helper.rb
@@ -0,0 +1,2 @@
+module ApplicationHelper
+end
diff --git a/test/dummy/app/jobs/application_job.rb b/test/dummy/app/jobs/application_job.rb
new file mode 100644
index 0000000..d394c3d
--- /dev/null
+++ b/test/dummy/app/jobs/application_job.rb
@@ -0,0 +1,7 @@
+class ApplicationJob < ActiveJob::Base
+ # Automatically retry jobs that encountered a deadlock
+ # retry_on ActiveRecord::Deadlocked
+
+ # Most jobs are safe to ignore if the underlying records are no longer available
+ # discard_on ActiveJob::DeserializationError
+end
diff --git a/test/dummy/app/mailers/application_mailer.rb b/test/dummy/app/mailers/application_mailer.rb
new file mode 100644
index 0000000..3c34c81
--- /dev/null
+++ b/test/dummy/app/mailers/application_mailer.rb
@@ -0,0 +1,4 @@
+class ApplicationMailer < ActionMailer::Base
+ default from: "from@example.com"
+ layout "mailer"
+end
diff --git a/test/dummy/app/models/application_record.rb b/test/dummy/app/models/application_record.rb
new file mode 100644
index 0000000..b63caeb
--- /dev/null
+++ b/test/dummy/app/models/application_record.rb
@@ -0,0 +1,3 @@
+class ApplicationRecord < ActiveRecord::Base
+ primary_abstract_class
+end
diff --git a/test/dummy/app/models/article.rb b/test/dummy/app/models/article.rb
new file mode 100644
index 0000000..586b442
--- /dev/null
+++ b/test/dummy/app/models/article.rb
@@ -0,0 +1,17 @@
+class Article < ApplicationRecord
+ include Superglue::Broadcastable
+
+ has_many :comments
+
+ validates :body, presence: true
+
+ broadcasts "overriden-stream", target: "overriden-target"
+
+ def to_gid_param
+ to_param
+ end
+
+ def to_param
+ body.parameterize
+ end
+end
diff --git a/test/dummy/app/models/board.rb b/test/dummy/app/models/board.rb
new file mode 100644
index 0000000..f06aaea
--- /dev/null
+++ b/test/dummy/app/models/board.rb
@@ -0,0 +1,4 @@
+class Board < ApplicationRecord
+ include Superglue::Broadcastable
+ broadcasts_refreshes
+end
diff --git a/test/dummy/app/models/comment.rb b/test/dummy/app/models/comment.rb
new file mode 100644
index 0000000..fc65a83
--- /dev/null
+++ b/test/dummy/app/models/comment.rb
@@ -0,0 +1,11 @@
+class Comment < ApplicationRecord
+ include Superglue::Broadcastable
+ belongs_to :article
+
+ validates :body, presence: true
+
+ broadcasts_to ->(comment) { [comment.article, :comments] },
+ target: ->(comment) { "article_#{comment.article_id}_comments" },
+ partial: "comments/different_comment",
+ locals: {highlight: true}
+end
diff --git a/test/views/render/uncommon_pair.jsx b/test/dummy/app/models/concerns/.keep
similarity index 100%
rename from test/views/render/uncommon_pair.jsx
rename to test/dummy/app/models/concerns/.keep
diff --git a/test/dummy/app/models/message.rb b/test/dummy/app/models/message.rb
new file mode 100644
index 0000000..9fe4df2
--- /dev/null
+++ b/test/dummy/app/models/message.rb
@@ -0,0 +1,4 @@
+class Message < ApplicationRecord
+ include Superglue::Broadcastable
+ delegate :to_s, to: :content, allow_nil: true
+end
diff --git a/test/dummy/app/models/users/profile.rb b/test/dummy/app/models/users/profile.rb
new file mode 100644
index 0000000..8837ee2
--- /dev/null
+++ b/test/dummy/app/models/users/profile.rb
@@ -0,0 +1,16 @@
+module Users
+ class Profile
+ include ActiveModel::Model
+ include Superglue::Broadcastable
+
+ attr_accessor :id, :name
+
+ def to_param
+ "users:profile:#{id}"
+ end
+
+ def to_partial_path
+ "users/profiles/profile"
+ end
+ end
+end
diff --git a/test/dummy/app/views/articles/_article.json.props b/test/dummy/app/views/articles/_article.json.props
new file mode 100644
index 0000000..007efda
--- /dev/null
+++ b/test/dummy/app/views/articles/_article.json.props
@@ -0,0 +1 @@
+json.body article.body
diff --git a/test/dummy/app/views/comments/_comment.json.props b/test/dummy/app/views/comments/_comment.json.props
new file mode 100644
index 0000000..347b91a
--- /dev/null
+++ b/test/dummy/app/views/comments/_comment.json.props
@@ -0,0 +1 @@
+json.body comment.body
diff --git a/test/dummy/app/views/comments/_different_comment.json.props b/test/dummy/app/views/comments/_different_comment.json.props
new file mode 100644
index 0000000..4b926dc
--- /dev/null
+++ b/test/dummy/app/views/comments/_different_comment.json.props
@@ -0,0 +1 @@
+json.different comment.body
diff --git a/test/dummy/app/views/layouts/application.html.erb b/test/dummy/app/views/layouts/application.html.erb
new file mode 100644
index 0000000..f25ae92
--- /dev/null
+++ b/test/dummy/app/views/layouts/application.html.erb
@@ -0,0 +1,27 @@
+
+
+
+ <%= content_for(:title) || "Dummy" %>
+
+
+
+ <%= csrf_meta_tags %>
+ <%= csp_meta_tag %>
+
+ <%= yield :head %>
+
+ <%# Enable PWA manifest for installable apps (make sure to enable in config/routes.rb too!) %>
+ <%#= tag.link rel: "manifest", href: pwa_manifest_path(format: :json) %>
+
+
+
+
+
+ <%# Includes all stylesheet files in app/assets/stylesheets %>
+ <%= stylesheet_link_tag :app %>
+
+
+
+ <%= yield %>
+
+
diff --git a/test/dummy/app/views/layouts/mailer.html.erb b/test/dummy/app/views/layouts/mailer.html.erb
new file mode 100644
index 0000000..3aac900
--- /dev/null
+++ b/test/dummy/app/views/layouts/mailer.html.erb
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+ <%= yield %>
+
+
diff --git a/test/dummy/app/views/layouts/mailer.text.erb b/test/dummy/app/views/layouts/mailer.text.erb
new file mode 100644
index 0000000..37f0bdd
--- /dev/null
+++ b/test/dummy/app/views/layouts/mailer.text.erb
@@ -0,0 +1 @@
+<%= yield %>
diff --git a/test/dummy/app/views/messages/_message.json.props b/test/dummy/app/views/messages/_message.json.props
new file mode 100644
index 0000000..4c86bd1
--- /dev/null
+++ b/test/dummy/app/views/messages/_message.json.props
@@ -0,0 +1 @@
+json.body "Goodbye!"
\ No newline at end of file
diff --git a/test/dummy/app/views/pwa/manifest.json.erb b/test/dummy/app/views/pwa/manifest.json.erb
new file mode 100644
index 0000000..a3c046e
--- /dev/null
+++ b/test/dummy/app/views/pwa/manifest.json.erb
@@ -0,0 +1,22 @@
+{
+ "name": "Dummy",
+ "icons": [
+ {
+ "src": "/icon.png",
+ "type": "image/png",
+ "sizes": "512x512"
+ },
+ {
+ "src": "/icon.png",
+ "type": "image/png",
+ "sizes": "512x512",
+ "purpose": "maskable"
+ }
+ ],
+ "start_url": "/",
+ "display": "standalone",
+ "scope": "/",
+ "description": "Dummy.",
+ "theme_color": "red",
+ "background_color": "red"
+}
diff --git a/test/dummy/app/views/pwa/service-worker.js b/test/dummy/app/views/pwa/service-worker.js
new file mode 100644
index 0000000..b3a13fb
--- /dev/null
+++ b/test/dummy/app/views/pwa/service-worker.js
@@ -0,0 +1,26 @@
+// Add a service worker for processing Web Push notifications:
+//
+// self.addEventListener("push", async (event) => {
+// const { title, options } = await event.data.json()
+// event.waitUntil(self.registration.showNotification(title, options))
+// })
+//
+// self.addEventListener("notificationclick", function(event) {
+// event.notification.close()
+// event.waitUntil(
+// clients.matchAll({ type: "window" }).then((clientList) => {
+// for (let i = 0; i < clientList.length; i++) {
+// let client = clientList[i]
+// let clientPath = (new URL(client.url)).pathname
+//
+// if (clientPath == event.notification.data.path && "focus" in client) {
+// return client.focus()
+// }
+// }
+//
+// if (clients.openWindow) {
+// return clients.openWindow(event.notification.data.path)
+// }
+// })
+// )
+// })
diff --git a/test/dummy/app/views/users/profiles/_profile.json.props b/test/dummy/app/views/users/profiles/_profile.json.props
new file mode 100644
index 0000000..ebd0aba
--- /dev/null
+++ b/test/dummy/app/views/users/profiles/_profile.json.props
@@ -0,0 +1 @@
+json.name profile.name
diff --git a/test/dummy/bin/dev b/test/dummy/bin/dev
new file mode 100755
index 0000000..5f91c20
--- /dev/null
+++ b/test/dummy/bin/dev
@@ -0,0 +1,2 @@
+#!/usr/bin/env ruby
+exec "./bin/rails", "server", *ARGV
diff --git a/test/dummy/bin/rails b/test/dummy/bin/rails
new file mode 100755
index 0000000..efc0377
--- /dev/null
+++ b/test/dummy/bin/rails
@@ -0,0 +1,4 @@
+#!/usr/bin/env ruby
+APP_PATH = File.expand_path("../config/application", __dir__)
+require_relative "../config/boot"
+require "rails/commands"
diff --git a/test/dummy/bin/rake b/test/dummy/bin/rake
new file mode 100755
index 0000000..4fbf10b
--- /dev/null
+++ b/test/dummy/bin/rake
@@ -0,0 +1,4 @@
+#!/usr/bin/env ruby
+require_relative "../config/boot"
+require "rake"
+Rake.application.run
diff --git a/test/dummy/bin/setup b/test/dummy/bin/setup
new file mode 100755
index 0000000..be3db3c
--- /dev/null
+++ b/test/dummy/bin/setup
@@ -0,0 +1,34 @@
+#!/usr/bin/env ruby
+require "fileutils"
+
+APP_ROOT = File.expand_path("..", __dir__)
+
+def system!(*args)
+ system(*args, exception: true)
+end
+
+FileUtils.chdir APP_ROOT do
+ # This script is a way to set up or update your development environment automatically.
+ # This script is idempotent, so that you can run it at any time and get an expectable outcome.
+ # Add necessary setup steps to this file.
+
+ puts "== Installing dependencies =="
+ system("bundle check") || system!("bundle install")
+
+ # puts "\n== Copying sample files =="
+ # unless File.exist?("config/database.yml")
+ # FileUtils.cp "config/database.yml.sample", "config/database.yml"
+ # end
+
+ puts "\n== Preparing database =="
+ system! "bin/rails db:prepare"
+
+ puts "\n== Removing old logs and tempfiles =="
+ system! "bin/rails log:clear tmp:clear"
+
+ unless ARGV.include?("--skip-server")
+ puts "\n== Starting development server =="
+ STDOUT.flush # flush the output before exec(2) so that it displays
+ exec "bin/dev"
+ end
+end
diff --git a/test/dummy/config.ru b/test/dummy/config.ru
new file mode 100644
index 0000000..4a3c09a
--- /dev/null
+++ b/test/dummy/config.ru
@@ -0,0 +1,6 @@
+# This file is used by Rack-based servers to start the application.
+
+require_relative "config/environment"
+
+run Rails.application
+Rails.application.load_server
diff --git a/test/dummy/config/application.rb b/test/dummy/config/application.rb
new file mode 100644
index 0000000..6e61f6b
--- /dev/null
+++ b/test/dummy/config/application.rb
@@ -0,0 +1,29 @@
+require_relative "boot"
+
+require "rails/all"
+
+# Require the gems listed in Gemfile, including any gems
+# you've limited to :test, :development, or :production.
+Bundler.require(*Rails.groups)
+
+module Dummy
+ class Application < Rails::Application
+ config.load_defaults Rails::VERSION::STRING.to_f
+
+ # For compatibility with applications that use this config
+ config.action_controller.include_all_helpers = false
+
+ # Please, add to the `ignore` list any other `lib` subdirectories that do
+ # not contain `.rb` files, or that should not be reloaded or eager loaded.
+ # Common ones are `templates`, `generators`, or `middleware`, for example.
+ config.autoload_lib(ignore: %w[assets tasks])
+
+ # Configuration for the application, engines, and railties goes here.
+ #
+ # These settings can be overridden in specific environments using the files
+ # in config/environments, which are processed later.
+ #
+ # config.time_zone = "Central Time (US & Canada)"
+ # config.eager_load_paths << Rails.root.join("extras")
+ end
+end
diff --git a/test/dummy/config/boot.rb b/test/dummy/config/boot.rb
new file mode 100644
index 0000000..116591a
--- /dev/null
+++ b/test/dummy/config/boot.rb
@@ -0,0 +1,5 @@
+# Set up gems listed in the Gemfile.
+ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../Gemfile", __dir__)
+
+require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])
+$LOAD_PATH.unshift File.expand_path("../../../lib", __dir__)
diff --git a/test/dummy/config/cable.yml b/test/dummy/config/cable.yml
new file mode 100644
index 0000000..98367f8
--- /dev/null
+++ b/test/dummy/config/cable.yml
@@ -0,0 +1,10 @@
+development:
+ adapter: async
+
+test:
+ adapter: test
+
+production:
+ adapter: redis
+ url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
+ channel_prefix: dummy_production
diff --git a/test/dummy/config/database.yml b/test/dummy/config/database.yml
new file mode 100644
index 0000000..01bebb5
--- /dev/null
+++ b/test/dummy/config/database.yml
@@ -0,0 +1,32 @@
+# SQLite. Versions 3.8.0 and up are supported.
+# gem install sqlite3
+#
+# Ensure the SQLite 3 gem is defined in your Gemfile
+# gem "sqlite3"
+#
+default: &default
+ adapter: sqlite3
+ pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
+ timeout: 5000
+
+development:
+ <<: *default
+ database: storage/development.sqlite3
+
+# Warning: The database defined as "test" will be erased and
+# re-generated from your development database when you run "rake".
+# Do not set this db to the same as development or production.
+test:
+ <<: *default
+ database: storage/test.sqlite3
+
+
+# SQLite3 write its data on the local filesystem, as such it requires
+# persistent disks. If you are deploying to a managed service, you should
+# make sure it provides disk persistence, as many don't.
+#
+# Similarly, if you deploy your application as a Docker container, you must
+# ensure the database is located in a persisted volume.
+production:
+ <<: *default
+ # database: path/to/persistent/storage/production.sqlite3
diff --git a/test/dummy/config/environment.rb b/test/dummy/config/environment.rb
new file mode 100644
index 0000000..cac5315
--- /dev/null
+++ b/test/dummy/config/environment.rb
@@ -0,0 +1,5 @@
+# Load the Rails application.
+require_relative "application"
+
+# Initialize the Rails application.
+Rails.application.initialize!
diff --git a/test/dummy/config/environments/development.rb b/test/dummy/config/environments/development.rb
new file mode 100644
index 0000000..263e0c4
--- /dev/null
+++ b/test/dummy/config/environments/development.rb
@@ -0,0 +1,69 @@
+require "active_support/core_ext/integer/time"
+
+Rails.application.configure do
+ # Settings specified here will take precedence over those in config/application.rb.
+
+ # Make code changes take effect immediately without server restart.
+ config.enable_reloading = true
+
+ # Do not eager load code on boot.
+ config.eager_load = false
+
+ # Show full error reports.
+ config.consider_all_requests_local = true
+
+ # Enable server timing.
+ config.server_timing = true
+
+ # Enable/disable Action Controller caching. By default Action Controller caching is disabled.
+ # Run rails dev:cache to toggle Action Controller caching.
+ if Rails.root.join("tmp/caching-dev.txt").exist?
+ config.action_controller.perform_caching = true
+ config.action_controller.enable_fragment_cache_logging = true
+ config.public_file_server.headers = { "cache-control" => "public, max-age=#{2.days.to_i}" }
+ else
+ config.action_controller.perform_caching = false
+ end
+
+ # Change to :null_store to avoid any caching.
+ config.cache_store = :memory_store
+
+ # Store uploaded files on the local file system (see config/storage.yml for options).
+ config.active_storage.service = :local
+
+ # Don't care if the mailer can't send.
+ config.action_mailer.raise_delivery_errors = false
+
+ # Make template changes take effect immediately.
+ config.action_mailer.perform_caching = false
+
+ # Set localhost to be used by links generated in mailer templates.
+ config.action_mailer.default_url_options = { host: "localhost", port: 3000 }
+
+ # Print deprecation notices to the Rails logger.
+ config.active_support.deprecation = :log
+
+ # Raise an error on page load if there are pending migrations.
+ config.active_record.migration_error = :page_load
+
+ # Highlight code that triggered database queries in logs.
+ config.active_record.verbose_query_logs = true
+
+ # Append comments with runtime information tags to SQL queries in logs.
+ config.active_record.query_log_tags_enabled = true
+
+ # Highlight code that enqueued background job in logs.
+ config.active_job.verbose_enqueue_logs = true
+
+ # Raises error for missing translations.
+ # config.i18n.raise_on_missing_translations = true
+
+ # Annotate rendered view with file names.
+ config.action_view.annotate_rendered_view_with_filenames = true
+
+ # Uncomment if you wish to allow Action Cable access from any origin.
+ # config.action_cable.disable_request_forgery_protection = true
+
+ # Raise error when a before_action's only/except options reference missing actions.
+ config.action_controller.raise_on_missing_callback_actions = true
+end
diff --git a/test/dummy/config/environments/production.rb b/test/dummy/config/environments/production.rb
new file mode 100644
index 0000000..1749607
--- /dev/null
+++ b/test/dummy/config/environments/production.rb
@@ -0,0 +1,89 @@
+require "active_support/core_ext/integer/time"
+
+Rails.application.configure do
+ # Settings specified here will take precedence over those in config/application.rb.
+
+ # Code is not reloaded between requests.
+ config.enable_reloading = false
+
+ # Eager load code on boot for better performance and memory savings (ignored by Rake tasks).
+ config.eager_load = true
+
+ # Full error reports are disabled.
+ config.consider_all_requests_local = false
+
+ # Turn on fragment caching in view templates.
+ config.action_controller.perform_caching = true
+
+ # Cache assets for far-future expiry since they are all digest stamped.
+ config.public_file_server.headers = { "cache-control" => "public, max-age=#{1.year.to_i}" }
+
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server.
+ # config.asset_host = "http://assets.example.com"
+
+ # Store uploaded files on the local file system (see config/storage.yml for options).
+ config.active_storage.service = :local
+
+ # Assume all access to the app is happening through a SSL-terminating reverse proxy.
+ config.assume_ssl = true
+
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
+ config.force_ssl = true
+
+ # Skip http-to-https redirect for the default health check endpoint.
+ # config.ssl_options = { redirect: { exclude: ->(request) { request.path == "/up" } } }
+
+ # Log to STDOUT with the current request id as a default log tag.
+ config.log_tags = [ :request_id ]
+ config.logger = ActiveSupport::TaggedLogging.logger(STDOUT)
+
+ # Change to "debug" to log everything (including potentially personally-identifiable information!)
+ config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "info")
+
+ # Prevent health checks from clogging up the logs.
+ config.silence_healthcheck_path = "/up"
+
+ # Don't log any deprecations.
+ config.active_support.report_deprecations = false
+
+ # Replace the default in-process memory cache store with a durable alternative.
+ # config.cache_store = :mem_cache_store
+
+ # Replace the default in-process and non-durable queuing backend for Active Job.
+ # config.active_job.queue_adapter = :resque
+
+ # Ignore bad email addresses and do not raise email delivery errors.
+ # Set this to true and configure the email server for immediate delivery to raise delivery errors.
+ # config.action_mailer.raise_delivery_errors = false
+
+ # Set host to be used by links generated in mailer templates.
+ config.action_mailer.default_url_options = { host: "example.com" }
+
+ # Specify outgoing SMTP server. Remember to add smtp/* credentials via rails credentials:edit.
+ # config.action_mailer.smtp_settings = {
+ # user_name: Rails.application.credentials.dig(:smtp, :user_name),
+ # password: Rails.application.credentials.dig(:smtp, :password),
+ # address: "smtp.example.com",
+ # port: 587,
+ # authentication: :plain
+ # }
+
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
+ # the I18n.default_locale when a translation cannot be found).
+ config.i18n.fallbacks = true
+
+ # Do not dump schema after migrations.
+ config.active_record.dump_schema_after_migration = false
+
+ # Only use :id for inspections in production.
+ config.active_record.attributes_for_inspect = [ :id ]
+
+ # Enable DNS rebinding protection and other `Host` header attacks.
+ # config.hosts = [
+ # "example.com", # Allow requests from example.com
+ # /.*\.example\.com/ # Allow requests from subdomains like `www.example.com`
+ # ]
+ #
+ # Skip DNS rebinding protection for the default health check endpoint.
+ # config.host_authorization = { exclude: ->(request) { request.path == "/up" } }
+end
diff --git a/test/dummy/config/environments/test.rb b/test/dummy/config/environments/test.rb
new file mode 100644
index 0000000..c2095b1
--- /dev/null
+++ b/test/dummy/config/environments/test.rb
@@ -0,0 +1,53 @@
+# The test environment is used exclusively to run your application's
+# test suite. You never need to work with it otherwise. Remember that
+# your test database is "scratch space" for the test suite and is wiped
+# and recreated between test runs. Don't rely on the data there!
+
+Rails.application.configure do
+ # Settings specified here will take precedence over those in config/application.rb.
+
+ # While tests run files are not watched, reloading is not necessary.
+ config.enable_reloading = false
+
+ # Eager loading loads your entire application. When running a single test locally,
+ # this is usually not necessary, and can slow down your test suite. However, it's
+ # recommended that you enable it in continuous integration systems to ensure eager
+ # loading is working properly before deploying your code.
+ config.eager_load = ENV["CI"].present?
+
+ # Configure public file server for tests with cache-control for performance.
+ config.public_file_server.headers = { "cache-control" => "public, max-age=3600" }
+
+ # Show full error reports.
+ config.consider_all_requests_local = true
+ config.cache_store = :null_store
+
+ # Render exception templates for rescuable exceptions and raise for other exceptions.
+ config.action_dispatch.show_exceptions = :rescuable
+
+ # Disable request forgery protection in test environment.
+ config.action_controller.allow_forgery_protection = false
+
+ # Store uploaded files on the local file system in a temporary directory.
+ config.active_storage.service = :test
+
+ # Tell Action Mailer not to deliver emails to the real world.
+ # The :test delivery method accumulates sent emails in the
+ # ActionMailer::Base.deliveries array.
+ config.action_mailer.delivery_method = :test
+
+ # Set host to be used by links generated in mailer templates.
+ config.action_mailer.default_url_options = { host: "example.com" }
+
+ # Print deprecation notices to the stderr.
+ config.active_support.deprecation = :stderr
+
+ # Raises error for missing translations.
+ # config.i18n.raise_on_missing_translations = true
+
+ # Annotate rendered view with file names.
+ # config.action_view.annotate_rendered_view_with_filenames = true
+
+ # Raise error when a before_action's only/except options reference missing actions.
+ config.action_controller.raise_on_missing_callback_actions = true
+end
diff --git a/test/dummy/config/initializers/assets.rb b/test/dummy/config/initializers/assets.rb
new file mode 100644
index 0000000..68fd3a0
--- /dev/null
+++ b/test/dummy/config/initializers/assets.rb
@@ -0,0 +1,7 @@
+# Be sure to restart your server when you modify this file.
+
+# Version of your assets, change this if you want to expire all your assets.
+# Rails.application.config.assets.version = "1.0"
+
+# Add additional assets to the asset load path.
+# Rails.application.config.assets.paths << Emoji.images_path
diff --git a/test/dummy/config/initializers/content_security_policy.rb b/test/dummy/config/initializers/content_security_policy.rb
new file mode 100644
index 0000000..b3076b3
--- /dev/null
+++ b/test/dummy/config/initializers/content_security_policy.rb
@@ -0,0 +1,25 @@
+# Be sure to restart your server when you modify this file.
+
+# Define an application-wide content security policy.
+# See the Securing Rails Applications Guide for more information:
+# https://guides.rubyonrails.org/security.html#content-security-policy-header
+
+# Rails.application.configure do
+# config.content_security_policy do |policy|
+# policy.default_src :self, :https
+# policy.font_src :self, :https, :data
+# policy.img_src :self, :https, :data
+# policy.object_src :none
+# policy.script_src :self, :https
+# policy.style_src :self, :https
+# # Specify URI for violation reports
+# # policy.report_uri "/csp-violation-report-endpoint"
+# end
+#
+# # Generate session nonces for permitted importmap, inline scripts, and inline styles.
+# config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s }
+# config.content_security_policy_nonce_directives = %w(script-src style-src)
+#
+# # Report violations without enforcing the policy.
+# # config.content_security_policy_report_only = true
+# end
diff --git a/test/dummy/config/initializers/filter_parameter_logging.rb b/test/dummy/config/initializers/filter_parameter_logging.rb
new file mode 100644
index 0000000..c0b717f
--- /dev/null
+++ b/test/dummy/config/initializers/filter_parameter_logging.rb
@@ -0,0 +1,8 @@
+# Be sure to restart your server when you modify this file.
+
+# Configure parameters to be partially matched (e.g. passw matches password) and filtered from the log file.
+# Use this to limit dissemination of sensitive information.
+# See the ActiveSupport::ParameterFilter documentation for supported notations and behaviors.
+Rails.application.config.filter_parameters += [
+ :passw, :email, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn, :cvv, :cvc
+]
diff --git a/test/dummy/config/initializers/inflections.rb b/test/dummy/config/initializers/inflections.rb
new file mode 100644
index 0000000..3860f65
--- /dev/null
+++ b/test/dummy/config/initializers/inflections.rb
@@ -0,0 +1,16 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new inflection rules using the following format. Inflections
+# are locale specific, and you may define rules for as many different
+# locales as you wish. All of these examples are active by default:
+# ActiveSupport::Inflector.inflections(:en) do |inflect|
+# inflect.plural /^(ox)$/i, "\\1en"
+# inflect.singular /^(ox)en/i, "\\1"
+# inflect.irregular "person", "people"
+# inflect.uncountable %w( fish sheep )
+# end
+
+# These inflection rules are supported but not enabled by default:
+# ActiveSupport::Inflector.inflections(:en) do |inflect|
+# inflect.acronym "RESTful"
+# end
diff --git a/test/dummy/config/locales/en.yml b/test/dummy/config/locales/en.yml
new file mode 100644
index 0000000..6c349ae
--- /dev/null
+++ b/test/dummy/config/locales/en.yml
@@ -0,0 +1,31 @@
+# Files in the config/locales directory are used for internationalization and
+# are automatically loaded by Rails. If you want to use locales other than
+# English, add the necessary files in this directory.
+#
+# To use the locales, use `I18n.t`:
+#
+# I18n.t "hello"
+#
+# In views, this is aliased to just `t`:
+#
+# <%= t("hello") %>
+#
+# To use a different locale, set it with `I18n.locale`:
+#
+# I18n.locale = :es
+#
+# This would use the information in config/locales/es.yml.
+#
+# To learn more about the API, please read the Rails Internationalization guide
+# at https://guides.rubyonrails.org/i18n.html.
+#
+# Be aware that YAML interprets the following case-insensitive strings as
+# booleans: `true`, `false`, `on`, `off`, `yes`, `no`. Therefore, these strings
+# must be quoted to be interpreted as strings. For example:
+#
+# en:
+# "yes": yup
+# enabled: "ON"
+
+en:
+ hello: "Hello world"
diff --git a/test/dummy/config/puma.rb b/test/dummy/config/puma.rb
new file mode 100644
index 0000000..787e4ce
--- /dev/null
+++ b/test/dummy/config/puma.rb
@@ -0,0 +1,38 @@
+# This configuration file will be evaluated by Puma. The top-level methods that
+# are invoked here are part of Puma's configuration DSL. For more information
+# about methods provided by the DSL, see https://puma.io/puma/Puma/DSL.html.
+#
+# Puma starts a configurable number of processes (workers) and each process
+# serves each request in a thread from an internal thread pool.
+#
+# You can control the number of workers using ENV["WEB_CONCURRENCY"]. You
+# should only set this value when you want to run 2 or more workers. The
+# default is already 1.
+#
+# The ideal number of threads per worker depends both on how much time the
+# application spends waiting for IO operations and on how much you wish to
+# prioritize throughput over latency.
+#
+# As a rule of thumb, increasing the number of threads will increase how much
+# traffic a given process can handle (throughput), but due to CRuby's
+# Global VM Lock (GVL) it has diminishing returns and will degrade the
+# response time (latency) of the application.
+#
+# The default is set to 3 threads as it's deemed a decent compromise between
+# throughput and latency for the average Rails application.
+#
+# Any libraries that use a connection pool or another resource pool should
+# be configured to provide at least as many connections as the number of
+# threads. This includes Active Record's `pool` parameter in `database.yml`.
+threads_count = ENV.fetch("RAILS_MAX_THREADS", 3)
+threads threads_count, threads_count
+
+# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
+port ENV.fetch("PORT", 3000)
+
+# Allow puma to be restarted by `bin/rails restart` command.
+plugin :tmp_restart
+
+# Specify the PID file. Defaults to tmp/pids/server.pid in development.
+# In other environments, only set the PID file if requested.
+pidfile ENV["PIDFILE"] if ENV["PIDFILE"]
diff --git a/test/dummy/config/routes.rb b/test/dummy/config/routes.rb
new file mode 100644
index 0000000..7fa9d1e
--- /dev/null
+++ b/test/dummy/config/routes.rb
@@ -0,0 +1,16 @@
+Rails.application.routes.draw do
+ # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
+
+ # Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.
+ # Can be used by load balancers and uptime monitors to verify that the app is live.
+ get "up" => "rails/health#show", :as => :rails_health_check
+
+ # Render dynamic PWA files from app/views/pwa/* (remember to link manifest in application.html.erb)
+ # get "manifest" => "rails/pwa#manifest", as: :pwa_manifest
+ # get "service-worker" => "rails/pwa#service_worker", as: :pwa_service_worker
+
+ # Defines the root path route ("/")
+ # root "posts#index"
+ get ":controller(/:action)"
+ resource :request_id
+end
diff --git a/test/dummy/config/storage.yml b/test/dummy/config/storage.yml
new file mode 100644
index 0000000..4942ab6
--- /dev/null
+++ b/test/dummy/config/storage.yml
@@ -0,0 +1,34 @@
+test:
+ service: Disk
+ root: <%= Rails.root.join("tmp/storage") %>
+
+local:
+ service: Disk
+ root: <%= Rails.root.join("storage") %>
+
+# Use bin/rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
+# amazon:
+# service: S3
+# access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
+# secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
+# region: us-east-1
+# bucket: your_own_bucket-<%= Rails.env %>
+
+# Remember not to checkin your GCS keyfile to a repository
+# google:
+# service: GCS
+# project: your_project
+# credentials: <%= Rails.root.join("path/to/gcs.keyfile") %>
+# bucket: your_own_bucket-<%= Rails.env %>
+
+# Use bin/rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key)
+# microsoft:
+# service: AzureStorage
+# storage_account_name: your_account_name
+# storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %>
+# container: your_container_name-<%= Rails.env %>
+
+# mirror:
+# service: Mirror
+# primary: local
+# mirrors: [ amazon, google, microsoft ]
diff --git a/test/dummy/db/migrate/20250512032735_create_messages.rb b/test/dummy/db/migrate/20250512032735_create_messages.rb
new file mode 100644
index 0000000..0fa4cb4
--- /dev/null
+++ b/test/dummy/db/migrate/20250512032735_create_messages.rb
@@ -0,0 +1,9 @@
+class CreateMessages < ActiveRecord::Migration[7.2]
+ def change
+ create_table :messages do |t|
+ t.text :content
+
+ t.timestamps
+ end
+ end
+end
diff --git a/test/dummy/db/migrate/20250515210853_create_boards.rb b/test/dummy/db/migrate/20250515210853_create_boards.rb
new file mode 100644
index 0000000..481eb31
--- /dev/null
+++ b/test/dummy/db/migrate/20250515210853_create_boards.rb
@@ -0,0 +1,9 @@
+class CreateBoards < ActiveRecord::Migration[7.2]
+ def change
+ create_table :boards do |t|
+ t.string :name
+
+ t.timestamps
+ end
+ end
+end
diff --git a/test/dummy/db/migrate/20250515210952_create_articles.rb b/test/dummy/db/migrate/20250515210952_create_articles.rb
new file mode 100644
index 0000000..4666be9
--- /dev/null
+++ b/test/dummy/db/migrate/20250515210952_create_articles.rb
@@ -0,0 +1,9 @@
+class CreateArticles < ActiveRecord::Migration[7.2]
+ def change
+ create_table :articles do |t|
+ t.text :body, null: false
+
+ t.timestamps
+ end
+ end
+end
diff --git a/test/dummy/db/migrate/20250515211239_create_comments.rb b/test/dummy/db/migrate/20250515211239_create_comments.rb
new file mode 100644
index 0000000..9266c42
--- /dev/null
+++ b/test/dummy/db/migrate/20250515211239_create_comments.rb
@@ -0,0 +1,10 @@
+class CreateComments < ActiveRecord::Migration[7.2]
+ def change
+ create_table :comments do |t|
+ t.text :body, null: false
+ t.references :article, null: false, foreign_key: true
+
+ t.timestamps
+ end
+ end
+end
diff --git a/test/dummy/db/schema.rb b/test/dummy/db/schema.rb
new file mode 100644
index 0000000..c4c3542
--- /dev/null
+++ b/test/dummy/db/schema.rb
@@ -0,0 +1,41 @@
+# This file is auto-generated from the current state of the database. Instead
+# of editing this file, please use the migrations feature of Active Record to
+# incrementally modify your database, and then regenerate this schema definition.
+#
+# This file is the source Rails uses to define your schema when running `bin/rails
+# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
+# be faster and is potentially less error prone than running all of your
+# migrations from scratch. Old migrations may fail to apply correctly if those
+# migrations use external dependencies or application code.
+#
+# It's strongly recommended that you check this file into your version control system.
+
+ActiveRecord::Schema[7.2].define(version: 2025_05_15_211239) do
+ create_table "articles", force: :cascade do |t|
+ t.text "body", null: false
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ end
+
+ create_table "boards", force: :cascade do |t|
+ t.string "name"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ end
+
+ create_table "comments", force: :cascade do |t|
+ t.text "body", null: false
+ t.integer "article_id", null: false
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.index ["article_id"], name: "index_comments_on_article_id"
+ end
+
+ create_table "messages", force: :cascade do |t|
+ t.text "content"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ end
+
+ add_foreign_key "comments", "articles"
+end
diff --git a/test/dummy/public/400.html b/test/dummy/public/400.html
new file mode 100644
index 0000000..282dbc8
--- /dev/null
+++ b/test/dummy/public/400.html
@@ -0,0 +1,114 @@
+
+
+
+
+
+
+ The server cannot process the request due to a client error (400 Bad Request)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
The server cannot process the request due to a client error. Please check the request and try again. If you’re the application owner check the logs for more information.
+
+
+
+
+
+
diff --git a/test/dummy/public/404.html b/test/dummy/public/404.html
new file mode 100644
index 0000000..c0670bc
--- /dev/null
+++ b/test/dummy/public/404.html
@@ -0,0 +1,114 @@
+
+
+
+
+
+
+ The page you were looking for doesn’t exist (404 Not found)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
The page you were looking for doesn’t exist. You may have mistyped the address or the page may have moved. If you’re the application owner check the logs for more information.
+
+
+
+
+
+
diff --git a/test/dummy/public/406-unsupported-browser.html b/test/dummy/public/406-unsupported-browser.html
new file mode 100644
index 0000000..9532a9c
--- /dev/null
+++ b/test/dummy/public/406-unsupported-browser.html
@@ -0,0 +1,114 @@
+
+
+
+
+
+
+ Your browser is not supported (406 Not Acceptable)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Your browser is not supported. Please upgrade your browser to continue.
The change you wanted was rejected. Maybe you tried to change something you didn’t have access to. If you’re the application owner check the logs for more information.