diff --git a/lib/action_view/template/handlers/rjs.rb b/lib/action_view/template/handlers/rjs.rb index 0855959..bf57a1e 100644 --- a/lib/action_view/template/handlers/rjs.rb +++ b/lib/action_view/template/handlers/rjs.rb @@ -3,10 +3,18 @@ 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" + 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 diff --git a/lib/prototype-rails.rb b/lib/prototype-rails.rb index 8f176f5..984708c 100644 --- a/lib/prototype-rails.rb +++ b/lib/prototype-rails.rb @@ -3,14 +3,10 @@ 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 + require 'prototype-rails/on_load_action_controller' - ActiveSupport.on_load(:action_view) do - require 'prototype-rails/on_load_action_view' - end + require 'prototype-rails/on_load_action_view' end end end 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/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/lib/prototype-rails/selector_assertions.rb b/lib/prototype-rails/selector_assertions.rb index bdbe918..c1e2419 100644 --- a/lib/prototype-rails/selector_assertions.rb +++ b/lib/prototype-rails/selector_assertions.rb @@ -1,14 +1,14 @@ require 'active_support/core_ext/module/aliasing' -require 'action_view/vendor/html-scanner' 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) # 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 @@ -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) @@ -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 diff --git a/prototype-rails.gemspec b/prototype-rails.gemspec index 665b1f1..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.0.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' @@ -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 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