From d7c0042224853eeb65a4a4eb49cc2b3eca08bd91 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 14 Nov 2014 14:18:00 -0800 Subject: [PATCH 01/10] start on 4.2 support --- lib/prototype-rails/selector_assertions.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/prototype-rails/selector_assertions.rb b/lib/prototype-rails/selector_assertions.rb index bdbe918..c482fce 100644 --- a/lib/prototype-rails/selector_assertions.rb +++ b/lib/prototype-rails/selector_assertions.rb @@ -1,5 +1,4 @@ require 'active_support/core_ext/module/aliasing' -require 'action_view/vendor/html-scanner' require 'action_dispatch/testing/assertions' require 'action_dispatch/testing/assertions/selector' @@ -8,7 +7,8 @@ # Under MIT and/or CC By license. #++ -ActionDispatch::Assertions::SelectorAssertions.module_eval do +module PrototypeRails + module SelectorAssertions # Selects content from the RJS response. # # === Narrowing down @@ -193,7 +193,6 @@ def response_from_page_with_rjs response_from_page_without_rjs end end - alias_method_chain :response_from_page, :rjs # Unescapes a RJS string. def unescape_rjs(rjs_string) @@ -208,3 +207,4 @@ def unescape_rjs(rjs_string) unescaped end end +end From 305fca4ef3276248782b103f83bb616a1ac6f912 Mon Sep 17 00:00:00 2001 From: Ilya Slepov Date: Wed, 11 Mar 2015 19:02:57 +0300 Subject: [PATCH 02/10] Fixed deprecation warning "ActionDispatch::Assertions::SelectorAssertions has been extracted to the rails-dom-testing gem". --- lib/prototype-rails/selector_assertions.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/prototype-rails/selector_assertions.rb b/lib/prototype-rails/selector_assertions.rb index c482fce..457e682 100644 --- a/lib/prototype-rails/selector_assertions.rb +++ b/lib/prototype-rails/selector_assertions.rb @@ -1,6 +1,6 @@ require 'active_support/core_ext/module/aliasing' require 'action_dispatch/testing/assertions' -require 'action_dispatch/testing/assertions/selector' +require 'rails/dom/testing/assertions/selector_assertions' #-- # Copyright (c) 2006 Assaf Arkin (http://labnotes.org) From 286afe5d864f48528329c0a2d101ed298c356318 Mon Sep 17 00:00:00 2001 From: Nowaker Date: Fri, 11 Dec 2020 17:43:44 -0600 Subject: [PATCH 03/10] Add compatibility with Rails 5+ --- prototype-rails.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prototype-rails.gemspec b/prototype-rails.gemspec index 665b1f1..8837978 100644 --- a/prototype-rails.gemspec +++ b/prototype-rails.gemspec @@ -8,7 +8,7 @@ Gem::Specification.new do |spec| spec.files = %w(README.md Rakefile Gemfile MIT-LICENSE) + Dir['lib/**/*', 'vendor/**/*', 'test/**/*'] - spec.add_dependency('rails', '~> 4.0') + spec.add_dependency('rails') spec.add_development_dependency('mocha') spec.license = "MIT" end From 011eaf11815448c8c9e3d7717a0f521d338d3f47 Mon Sep 17 00:00:00 2001 From: Nowaker Date: Fri, 18 Dec 2020 13:24:25 -0600 Subject: [PATCH 04/10] Add compatibility with Rails 5.1+ --- lib/action_view/template/handlers/rjs.rb | 2 +- lib/prototype-rails/renderers.rb | 2 +- lib/prototype-rails/selector_assertions.rb | 2 +- test/controller/content_type_test.rb | 2 +- test/controller/mime_responds_test.rb | 2 +- test/render_other_test.rb | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/action_view/template/handlers/rjs.rb b/lib/action_view/template/handlers/rjs.rb index 0855959..6107102 100644 --- a/lib/action_view/template/handlers/rjs.rb +++ b/lib/action_view/template/handlers/rjs.rb @@ -3,7 +3,7 @@ module Template::Handlers class RJS # Default format used by RJS. class_attribute :default_format - self.default_format = Mime::JS + self.default_format = Mime[:js] def call(template) "update_page do |page|;#{template.source}\nend" diff --git a/lib/prototype-rails/renderers.rb b/lib/prototype-rails/renderers.rb index a514adc..e7c6f03 100644 --- a/lib/prototype-rails/renderers.rb +++ b/lib/prototype-rails/renderers.rb @@ -5,7 +5,7 @@ module Renderers add :update do |proc, options| view_context = self.view_context generator = ActionView::Helpers::PrototypeHelper::JavaScriptGenerator.new(view_context, &proc) - self.content_type = Mime::JS + self.content_type = Mime[:js] self.response_body = generator.to_s end end diff --git a/lib/prototype-rails/selector_assertions.rb b/lib/prototype-rails/selector_assertions.rb index 457e682..c1e2419 100644 --- a/lib/prototype-rails/selector_assertions.rb +++ b/lib/prototype-rails/selector_assertions.rb @@ -174,7 +174,7 @@ def assert_select_rjs(*args, &block) def response_from_page_with_rjs content_type = @response.content_type - if content_type && Mime::JS =~ content_type + if content_type && Mime[:js] =~ content_type body = @response.body.dup root = HTML::Node.new(nil) diff --git a/test/controller/content_type_test.rb b/test/controller/content_type_test.rb index db32e11..ca6a882 100644 --- a/test/controller/content_type_test.rb +++ b/test/controller/content_type_test.rb @@ -10,7 +10,7 @@ class ContentTypeTest < ActionController::TestCase def test_default_for_rjs xhr :post, :render_default_for_rjs - assert_equal Mime::JS, @response.content_type + assert_equal Mime[:js], @response.content_type assert_equal "utf-8", @response.charset end end diff --git a/test/controller/mime_responds_test.rb b/test/controller/mime_responds_test.rb index 280b4b7..3fe53b3 100644 --- a/test/controller/mime_responds_test.rb +++ b/test/controller/mime_responds_test.rb @@ -196,7 +196,7 @@ def resource end def _render_js(js, options) - self.content_type ||= Mime::JS + self.content_type ||= Mime[:js] self.response_body = js.respond_to?(:to_js) ? js.to_js : js end end diff --git a/test/render_other_test.rb b/test/render_other_test.rb index 27a533e..b2ee472 100644 --- a/test/render_other_test.rb +++ b/test/render_other_test.rb @@ -3,7 +3,7 @@ require 'securerandom' ActionController.add_renderer :simon do |says, options| - self.content_type = Mime::TEXT + self.content_type = Mime[:text] self.response_body = "Simon says: #{says}" end From 1e8e4c5fd06d6abb0f8699616e8bd8de3f2685f5 Mon Sep 17 00:00:00 2001 From: Thomas Cannon Date: Thu, 8 Jul 2021 13:19:51 -0400 Subject: [PATCH 05/10] Refactor `rendering.rb` to not use `alias_method_chain` * Rails 5.x has deprecated `alias_method_chain`, in favor of `Module.prepend` --- lib/prototype-rails/rendering.rb | 28 +++++++++++++++++++++------- prototype-rails.gemspec | 2 +- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/lib/prototype-rails/rendering.rb b/lib/prototype-rails/rendering.rb index e2350d8..571d6e8 100644 --- a/lib/prototype-rails/rendering.rb +++ b/lib/prototype-rails/rendering.rb @@ -1,13 +1,27 @@ require 'action_view/helpers/rendering_helper' ActionView::Helpers::RenderingHelper.module_eval do - def render_with_update(options = {}, locals = {}, &block) - if options == :update - update_page(&block) - else - render_without_update(options, locals, &block) + if Rails::VERSION::MAJOR >= 5 && Rails::VERSION::MINOR >= 0 + module RenderWithUpdate + def render(options = {}, locals = {}, &block) + if options == :update + update_page(&block) + else + super(options, locals, &block) + end + end end + + prepend RenderWithUpdate + else + def render_with_update(options = {}, locals = {}, &block) + if options == :update + update_page(&block) + else + render_without_update(options, locals, &block) + end + end + + alias_method_chain :render, :update end - - alias_method_chain :render, :update end \ No newline at end of file diff --git a/prototype-rails.gemspec b/prototype-rails.gemspec index 8837978..048e4cd 100644 --- a/prototype-rails.gemspec +++ b/prototype-rails.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |spec| spec.name = 'prototype-rails' - spec.version = '4.0.0' + spec.version = '4.1.0' spec.summary = 'Prototype, Scriptaculous, and RJS for Ruby on Rails' spec.homepage = 'http://github.com/rails/prototype-rails' spec.author = 'Xavier Noria' From 490b637c989aee1367cb91182ab5385462ec7c60 Mon Sep 17 00:00:00 2001 From: Thomas Cannon Date: Thu, 15 Jul 2021 11:01:40 -0400 Subject: [PATCH 06/10] Patch ActionView template handler for Rails 6+ support --- lib/action_view/template/handlers/rjs.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/action_view/template/handlers/rjs.rb b/lib/action_view/template/handlers/rjs.rb index 6107102..bcc0d77 100644 --- a/lib/action_view/template/handlers/rjs.rb +++ b/lib/action_view/template/handlers/rjs.rb @@ -5,8 +5,16 @@ class RJS class_attribute :default_format self.default_format = Mime[:js] - def call(template) - "update_page do |page|;#{template.source}\nend" + if Rails::VERSION::MAJOR == 6 + def call(template, source) + "update_page do |page|;#{source}\nend" + end + end + + if Rails::VERSION::MAJOR == 5 + def call(template) + "update_page do |page|;#{template.source}\nend" + end end end end From c60d8a7ed3528ddc31d40df140bd107e3905e90f Mon Sep 17 00:00:00 2001 From: Thomas Cannon Date: Fri, 23 Jul 2021 11:45:38 -0400 Subject: [PATCH 07/10] Fix `prototype-rails` initializer to work nicely with `zeitwerk` * Initializers should only be called after the framework has been initialized --- lib/prototype-rails.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/prototype-rails.rb b/lib/prototype-rails.rb index 8f176f5..f984d5a 100644 --- a/lib/prototype-rails.rb +++ b/lib/prototype-rails.rb @@ -3,13 +3,15 @@ module PrototypeRails class Engine < Rails::Engine - initializer 'prototype-rails.initialize' do - ActiveSupport.on_load(:action_controller) do - require 'prototype-rails/on_load_action_controller' - end + config.after_initialize do + initializer 'prototype-rails.initialize' do + ActiveSupport.on_load(:action_controller) do + require 'prototype-rails/on_load_action_controller' + end - ActiveSupport.on_load(:action_view) do - require 'prototype-rails/on_load_action_view' + ActiveSupport.on_load(:action_view) do + require 'prototype-rails/on_load_action_view' + end end end end From 08be41cd052cd4d34442a3a403e488b718c3246c Mon Sep 17 00:00:00 2001 From: Thomas Cannon Date: Fri, 23 Jul 2021 11:46:26 -0400 Subject: [PATCH 08/10] Change version --- prototype-rails.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prototype-rails.gemspec b/prototype-rails.gemspec index 048e4cd..df5bb37 100644 --- a/prototype-rails.gemspec +++ b/prototype-rails.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |spec| spec.name = 'prototype-rails' - spec.version = '4.1.0' + spec.version = '4.2.0' spec.summary = 'Prototype, Scriptaculous, and RJS for Ruby on Rails' spec.homepage = 'http://github.com/rails/prototype-rails' spec.author = 'Xavier Noria' From 8f50b1334ef3034d620db7e0e583db8b50a5b0ce Mon Sep 17 00:00:00 2001 From: Thomas Cannon Date: Fri, 23 Jul 2021 12:41:53 -0400 Subject: [PATCH 09/10] Patching for `zeitwerk` support --- lib/prototype-rails.rb | 10 ++-------- prototype-rails.gemspec | 2 +- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/lib/prototype-rails.rb b/lib/prototype-rails.rb index f984d5a..984708c 100644 --- a/lib/prototype-rails.rb +++ b/lib/prototype-rails.rb @@ -4,15 +4,9 @@ module PrototypeRails class Engine < Rails::Engine config.after_initialize do - initializer 'prototype-rails.initialize' do - ActiveSupport.on_load(:action_controller) do - require 'prototype-rails/on_load_action_controller' - end + require 'prototype-rails/on_load_action_controller' - ActiveSupport.on_load(:action_view) do - require 'prototype-rails/on_load_action_view' - end - end + require 'prototype-rails/on_load_action_view' end end end diff --git a/prototype-rails.gemspec b/prototype-rails.gemspec index df5bb37..b73af25 100644 --- a/prototype-rails.gemspec +++ b/prototype-rails.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |spec| spec.name = 'prototype-rails' - spec.version = '4.2.0' + spec.version = '4.2.1' spec.summary = 'Prototype, Scriptaculous, and RJS for Ruby on Rails' spec.homepage = 'http://github.com/rails/prototype-rails' spec.author = 'Xavier Noria' From 3523e60c1c57176c44d396e4214c0007558a6009 Mon Sep 17 00:00:00 2001 From: Thomas Cannon Date: Tue, 14 Dec 2021 11:05:49 -0500 Subject: [PATCH 10/10] Change RJS handler to check for Rails 6+ --- lib/action_view/template/handlers/rjs.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/action_view/template/handlers/rjs.rb b/lib/action_view/template/handlers/rjs.rb index bcc0d77..bf57a1e 100644 --- a/lib/action_view/template/handlers/rjs.rb +++ b/lib/action_view/template/handlers/rjs.rb @@ -5,7 +5,7 @@ class RJS class_attribute :default_format self.default_format = Mime[:js] - if Rails::VERSION::MAJOR == 6 + if Rails::VERSION::MAJOR >= 6 def call(template, source) "update_page do |page|;#{source}\nend" end