From d7c0042224853eeb65a4a4eb49cc2b3eca08bd91 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 14 Nov 2014 14:18:00 -0800 Subject: [PATCH 01/22] 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/22] 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 5965de8de0e257fe41f441c4ad3ad0b5cb50e2c3 Mon Sep 17 00:00:00 2001 From: Clif Reeder Date: Tue, 28 Feb 2017 15:17:20 -0500 Subject: [PATCH 03/22] First pass at making this rals 5 compatable --- Gemfile.lock | 173 ++++--- lib/action_view/helpers/prototype_helper.rb | 10 +- .../on_load_action_controller.rb | 1 - lib/prototype-rails/selector_assertions.rb | 210 -------- prototype-rails.gemspec | 3 +- test/assert_select_test.rb | 457 ------------------ test/controller/caching_test.rb | 2 +- test/controller/mime_responds_test.rb | 7 +- test/controller/render_js_test.rb | 1 - test/javascript_helper_test.rb | 12 +- test/render_other_test.rb | 1 - test/template/prototype_helper_test.rb | 18 +- 12 files changed, 136 insertions(+), 759 deletions(-) delete mode 100644 lib/prototype-rails/selector_assertions.rb delete mode 100644 test/assert_select_test.rb diff --git a/Gemfile.lock b/Gemfile.lock index 92b8540..8c74d8a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,86 +1,117 @@ PATH remote: . specs: - prototype-rails (4.0.0) - rails (~> 4.0) + prototype-rails (4.0.1) + rails (>= 4.2) GEM remote: https://rubygems.org/ specs: - actionmailer (4.0.0) - actionpack (= 4.0.0) - mail (~> 2.5.3) - actionpack (4.0.0) - activesupport (= 4.0.0) - builder (~> 3.1.0) + actioncable (5.0.1) + actionpack (= 5.0.1) + nio4r (~> 1.2) + websocket-driver (~> 0.6.1) + actionmailer (5.0.1) + actionpack (= 5.0.1) + actionview (= 5.0.1) + activejob (= 5.0.1) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 2.0) + actionpack (5.0.1) + actionview (= 5.0.1) + activesupport (= 5.0.1) + rack (~> 2.0) + rack-test (~> 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + actionview (5.0.1) + activesupport (= 5.0.1) + builder (~> 3.1) erubis (~> 2.7.0) - rack (~> 1.5.2) - rack-test (~> 0.6.2) - activemodel (4.0.0) - activesupport (= 4.0.0) - builder (~> 3.1.0) - activerecord (4.0.0) - activemodel (= 4.0.0) - activerecord-deprecated_finders (~> 1.0.2) - activesupport (= 4.0.0) - arel (~> 4.0.0) - activerecord-deprecated_finders (1.0.3) - activesupport (4.0.0) - i18n (~> 0.6, >= 0.6.4) - minitest (~> 4.2) - multi_json (~> 1.3) - thread_safe (~> 0.1) - tzinfo (~> 0.3.37) - arel (4.0.0) - atomic (1.1.13) - builder (3.1.4) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + activejob (5.0.1) + activesupport (= 5.0.1) + globalid (>= 0.3.6) + activemodel (5.0.1) + activesupport (= 5.0.1) + activerecord (5.0.1) + activemodel (= 5.0.1) + activesupport (= 5.0.1) + arel (~> 7.0) + activesupport (5.0.1) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (~> 0.7) + minitest (~> 5.1) + tzinfo (~> 1.1) + arel (7.1.4) + builder (3.2.3) + concurrent-ruby (1.0.5) erubis (2.7.0) - hike (1.2.3) - i18n (0.6.5) - mail (2.5.4) - mime-types (~> 1.16) - treetop (~> 1.4.8) - metaclass (0.0.1) - mime-types (1.24) - minitest (4.7.5) - mocha (0.10.3) + globalid (0.3.7) + activesupport (>= 4.1.0) + i18n (0.8.1) + loofah (2.0.3) + nokogiri (>= 1.5.9) + mail (2.6.4) + mime-types (>= 1.16, < 4) + metaclass (0.0.4) + method_source (0.8.2) + mime-types (3.1) + mime-types-data (~> 3.2015) + mime-types-data (3.2016.0521) + mini_portile2 (2.1.0) + minitest (5.10.1) + mocha (1.2.1) metaclass (~> 0.0.1) - multi_json (1.7.9) - polyglot (0.3.3) - rack (1.5.2) - rack-test (0.6.2) + nio4r (1.2.1) + nokogiri (1.7.0.1) + mini_portile2 (~> 2.1.0) + rack (2.0.1) + rack-test (0.6.3) rack (>= 1.0) - rails (4.0.0) - actionmailer (= 4.0.0) - actionpack (= 4.0.0) - activerecord (= 4.0.0) - activesupport (= 4.0.0) + rails (5.0.1) + actioncable (= 5.0.1) + actionmailer (= 5.0.1) + actionpack (= 5.0.1) + actionview (= 5.0.1) + activejob (= 5.0.1) + activemodel (= 5.0.1) + activerecord (= 5.0.1) + activesupport (= 5.0.1) bundler (>= 1.3.0, < 2.0) - railties (= 4.0.0) - sprockets-rails (~> 2.0.0) - railties (4.0.0) - actionpack (= 4.0.0) - activesupport (= 4.0.0) + railties (= 5.0.1) + sprockets-rails (>= 2.0.0) + rails-controller-testing (1.0.1) + actionpack (~> 5.x) + actionview (~> 5.x) + activesupport (~> 5.x) + rails-dom-testing (2.0.2) + activesupport (>= 4.2.0, < 6.0) + nokogiri (~> 1.6) + rails-html-sanitizer (1.0.3) + loofah (~> 2.0) + railties (5.0.1) + actionpack (= 5.0.1) + activesupport (= 5.0.1) + method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rake (10.1.0) - sprockets (2.10.0) - hike (~> 1.2) - multi_json (~> 1.0) - rack (~> 1.0) - tilt (~> 1.1, != 1.3.0) - sprockets-rails (2.0.0) - actionpack (>= 3.0) - activesupport (>= 3.0) - sprockets (~> 2.8) - thor (0.18.1) - thread_safe (0.1.2) - atomic - tilt (1.4.1) - treetop (1.4.14) - polyglot - polyglot (>= 0.3.1) - tzinfo (0.3.37) + rake (12.0.0) + sprockets (3.7.1) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (3.2.0) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) + thor (0.19.4) + thread_safe (0.3.6) + tzinfo (1.2.2) + thread_safe (~> 0.1) + websocket-driver (0.6.5) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.2) PLATFORMS ruby @@ -88,3 +119,7 @@ PLATFORMS DEPENDENCIES mocha prototype-rails! + rails-controller-testing + +BUNDLED WITH + 1.13.6 diff --git a/lib/action_view/helpers/prototype_helper.rb b/lib/action_view/helpers/prototype_helper.rb index 6e33385..1b2c7d1 100644 --- a/lib/action_view/helpers/prototype_helper.rb +++ b/lib/action_view/helpers/prototype_helper.rb @@ -532,7 +532,15 @@ def delay(seconds = 1) end def javascript_object_for(object) - ::ActiveSupport::JSON.encode(object) + if object.is_a?(ActionView::JsonLiteral) + result = object.as_json + elsif ActionView::Helpers::JavaScriptVariableProxy + result = object.as_json + else + result = ::ActiveSupport::JSON.encode(object) + end + puts "from #{object.class} to #{result.inspect}" + result end def arguments_for_call(arguments, block = nil) diff --git a/lib/prototype-rails/on_load_action_controller.rb b/lib/prototype-rails/on_load_action_controller.rb index 92302e7..4a8f835 100644 --- a/lib/prototype-rails/on_load_action_controller.rb +++ b/lib/prototype-rails/on_load_action_controller.rb @@ -1,2 +1 @@ -require 'prototype-rails/selector_assertions' require 'prototype-rails/renderers' diff --git a/lib/prototype-rails/selector_assertions.rb b/lib/prototype-rails/selector_assertions.rb deleted file mode 100644 index bdbe918..0000000 --- a/lib/prototype-rails/selector_assertions.rb +++ /dev/null @@ -1,210 +0,0 @@ -require 'active_support/core_ext/module/aliasing' -require 'action_view/vendor/html-scanner' -require 'action_dispatch/testing/assertions' -require 'action_dispatch/testing/assertions/selector' - -#-- -# Copyright (c) 2006 Assaf Arkin (http://labnotes.org) -# Under MIT and/or CC By license. -#++ - -ActionDispatch::Assertions::SelectorAssertions.module_eval do - # Selects content from the RJS response. - # - # === Narrowing down - # - # With no arguments, asserts that one or more elements are updated or - # inserted by RJS statements. - # - # Use the +id+ argument to narrow down the assertion to only statements - # that update or insert an element with that identifier. - # - # Use the first argument to narrow down assertions to only statements - # of that type. Possible values are :replace, :replace_html, - # :show, :hide, :toggle, :remove, - # :insert_html and :redirect. - # - # Use the argument :insert followed by an insertion position to narrow - # down the assertion to only statements that insert elements in that - # position. Possible values are :top, :bottom, :before - # and :after. - # - # Use the argument :redirect followed by a path to check that an statement - # which redirects to the specified path is generated. - # - # Using the :remove statement, you will be able to pass a block, but it will - # be ignored as there is no HTML passed for this statement. - # - # === Using blocks - # - # Without a block, +assert_select_rjs+ merely asserts that the response - # contains one or more RJS statements that replace or update content. - # - # With a block, +assert_select_rjs+ also selects all elements used in - # these statements and passes them to the block. Nested assertions are - # supported. - # - # Calling +assert_select_rjs+ with no arguments and using nested asserts - # asserts that the HTML content is returned by one or more RJS statements. - # Using +assert_select+ directly makes the same assertion on the content, - # but without distinguishing whether the content is returned in an HTML - # or JavaScript. - # - # ==== Examples - # - # # Replacing the element foo. - # # page.replace 'foo', ... - # assert_select_rjs :replace, "foo" - # - # # Replacing with the chained RJS proxy. - # # page[:foo].replace ... - # assert_select_rjs :chained_replace, 'foo' - # - # # Inserting into the element bar, top position. - # assert_select_rjs :insert, :top, "bar" - # - # # Remove the element bar - # assert_select_rjs :remove, "bar" - # - # # Changing the element foo, with an image. - # assert_select_rjs "foo" do - # assert_select "img[src=/images/logo.gif"" - # end - # - # # RJS inserts or updates a list with four items. - # assert_select_rjs do - # assert_select "ol>li", 4 - # end - # - # # The same, but shorter. - # assert_select "ol>li", 4 - # - # # Checking for a redirect. - # assert_select_rjs :redirect, root_path - def assert_select_rjs(*args, &block) - rjs_type = args.first.is_a?(Symbol) ? args.shift : nil - id = args.first.is_a?(String) ? args.shift : nil - - # If the first argument is a symbol, it's the type of RJS statement we're looking - # for (update, replace, insertion, etc). Otherwise, we're looking for just about - # any RJS statement. - if rjs_type - if rjs_type == :insert - position = args.shift - id = args.shift - insertion = "insert_#{position}".to_sym - raise ArgumentError, "Unknown RJS insertion type #{position}" unless RJS_STATEMENTS[insertion] - statement = "(#{RJS_STATEMENTS[insertion]})" - else - raise ArgumentError, "Unknown RJS statement type #{rjs_type}" unless RJS_STATEMENTS[rjs_type] - statement = "(#{RJS_STATEMENTS[rjs_type]})" - end - else - statement = "#{RJS_STATEMENTS[:any]}" - end - - # Next argument we're looking for is the element identifier. If missing, we pick - # any element, otherwise we replace it in the statement. - pattern = Regexp.new( - id ? statement.gsub(RJS_ANY_ID, "\"#{id}\"") : statement - ) - - # Duplicate the body since the next step involves destroying it. - matches = nil - case rjs_type - when :remove, :show, :hide, :toggle - matches = @response.body.match(pattern) - else - @response.body.gsub(pattern) do |match| - html = unescape_rjs(match) - matches ||= [] - matches.concat HTML::Document.new(html).root.children.select { |n| n.tag? } - "" - end - end - - if matches - assert true # to count the assertion - if block_given? && !([:remove, :show, :hide, :toggle].include? rjs_type) - begin - @selected ||= nil - in_scope, @selected = @selected, matches - yield matches - ensure - @selected = in_scope - end - end - matches - else - # RJS statement not found. - case rjs_type - when :remove, :show, :hide, :toggle - flunk_message = "No RJS statement that #{rjs_type.to_s}s '#{id}' was rendered." - else - flunk_message = "No RJS statement that replaces or inserts HTML content." - end - flunk args.shift || flunk_message - end - end - - protected - - RJS_PATTERN_HTML = "\"((\\\\\"|[^\"])*)\"" - RJS_ANY_ID = "\"([^\"])*\"" - RJS_STATEMENTS = { - :chained_replace => "\\$\\(#{RJS_ANY_ID}\\)\\.replace\\(#{RJS_PATTERN_HTML}\\)", - :chained_replace_html => "\\$\\(#{RJS_ANY_ID}\\)\\.update\\(#{RJS_PATTERN_HTML}\\)", - :replace_html => "Element\\.update\\(#{RJS_ANY_ID}, #{RJS_PATTERN_HTML}\\)", - :replace => "Element\\.replace\\(#{RJS_ANY_ID}, #{RJS_PATTERN_HTML}\\)", - :redirect => "window.location.href = #{RJS_ANY_ID}" - } - [:remove, :show, :hide, :toggle].each do |action| - RJS_STATEMENTS[action] = "Element\\.#{action}\\(#{RJS_ANY_ID}\\)" - end - RJS_INSERTIONS = ["top", "bottom", "before", "after"] - RJS_INSERTIONS.each do |insertion| - RJS_STATEMENTS["insert_#{insertion}".to_sym] = "Element.insert\\(#{RJS_ANY_ID}, \\{ #{insertion}: #{RJS_PATTERN_HTML} \\}\\)" - end - RJS_STATEMENTS[:insert_html] = "Element.insert\\(#{RJS_ANY_ID}, \\{ (#{RJS_INSERTIONS.join('|')}): #{RJS_PATTERN_HTML} \\}\\)" - RJS_STATEMENTS[:any] = Regexp.new("(#{RJS_STATEMENTS.values.join('|')})") - RJS_PATTERN_UNICODE_ESCAPED_CHAR = /\\u([0-9a-zA-Z]{4})/ - - # +assert_select+ and +css_select+ call this to obtain the content in the HTML - # page, or from all the RJS statements, depending on the type of response. - def response_from_page_with_rjs - content_type = @response.content_type - - if content_type && Mime::JS =~ content_type - body = @response.body.dup - root = HTML::Node.new(nil) - - while true - next if body.sub!(RJS_STATEMENTS[:any]) do |match| - html = unescape_rjs(match) - matches = HTML::Document.new(html).root.children.select { |n| n.tag? } - root.children.concat matches - "" - end - break - end - - root - else - response_from_page_without_rjs - end - end - alias_method_chain :response_from_page, :rjs - - # Unescapes a RJS string. - def unescape_rjs(rjs_string) - # RJS encodes double quotes and line breaks. - unescaped= rjs_string.gsub('\"', '"') - unescaped.gsub!(/\\\//, '/') - unescaped.gsub!('\n', "\n") - unescaped.gsub!('\076', '>') - unescaped.gsub!('\074', '<') - # RJS encodes non-ascii characters. - unescaped.gsub!(RJS_PATTERN_UNICODE_ESCAPED_CHAR) {|u| [$1.hex].pack('U*')} - unescaped - end -end diff --git a/prototype-rails.gemspec b/prototype-rails.gemspec index 512ae58..48424ff 100644 --- a/prototype-rails.gemspec +++ b/prototype-rails.gemspec @@ -8,7 +8,8 @@ Gem::Specification.new do |spec| spec.files = %w(README.md Rakefile Gemfile MIT-LICENSE) + Dir['lib/**/*', 'vendor/**/*'] - spec.add_dependency('rails', '~> 4.0') + spec.add_dependency('rails', '>= 4.2') spec.add_development_dependency('mocha') + spec.add_development_dependency('rails-controller-testing') spec.license = "MIT" end diff --git a/test/assert_select_test.rb b/test/assert_select_test.rb deleted file mode 100644 index f627f17..0000000 --- a/test/assert_select_test.rb +++ /dev/null @@ -1,457 +0,0 @@ -# coding: utf-8 - -require 'abstract_unit' - -class AssertSelectTest < ActionController::TestCase - Assertion = ActiveSupport::TestCase::Assertion - - class AssertSelectController < ActionController::Base - def response_with=(content) - @content = content - end - - def response_with(&block) - @update = block - end - - def rjs - render :update do |page| - @update.call page - end - @update = nil - end - - def rescue_action(e) - raise e - end - end - - tests AssertSelectController - - def assert_failure(message, &block) - e = assert_raise(Assertion, &block) - assert_match(message, e.message) if Regexp === message - assert_equal(message, e.message) if String === message - end - - # With single result. - def test_assert_select_from_rjs_with_single_result - render_rjs do |page| - page.replace_html "test", "
foo
\n
foo
" - end - assert_select "div" do |elements| - assert elements.size == 2 - assert_select "#1" - assert_select "#2" - end - assert_select "div#?", /\d+/ do |elements| - assert_select "#1" - assert_select "#2" - end - end - - # With multiple results. - def test_assert_select_from_rjs_with_multiple_results - render_rjs do |page| - page.replace_html "test", "
foo
" - page.replace_html "test2", "
foo
" - end - assert_select "div" do |elements| - assert elements.size == 2 - assert_select "#1" - assert_select "#2" - end - end - - # With one result. - def test_css_select_from_rjs_with_single_result - render_rjs do |page| - page.replace_html "test", "
foo
\n
foo
" - end - assert_equal 2, css_select("div").size - assert_equal 1, css_select("#1").size - assert_equal 1, css_select("#2").size - end - - # With multiple results. - def test_css_select_from_rjs_with_multiple_results - render_rjs do |page| - page.replace_html "test", "
foo
" - page.replace_html "test2", "
foo
" - end - - assert_equal 2, css_select("div").size - assert_equal 1, css_select("#1").size - assert_equal 1, css_select("#2").size - end - - # - # Test assert_select_rjs. - # - - def test_assert_select_rjs_for_positioned_insert_should_fail_when_mixing_arguments - render_rjs do |page| - page.insert_html :top, "test1", "
foo
" - page.insert_html :bottom, "test2", "
foo
" - end - assert_raise(Assertion) {assert_select_rjs :insert, :top, "test2"} - end - - # Test that we can pick up all statements in the result. - def test_assert_select_rjs_picks_up_all_statements - render_rjs do |page| - page.replace "test", "
foo
" - page.replace_html "test2", "
foo
" - page.insert_html :top, "test3", "
foo
" - end - - found = false - assert_select_rjs do - assert_select "#1" - assert_select "#2" - assert_select "#3" - found = true - end - assert found - end - - # Test that we fail if there is nothing to pick. - def test_assert_select_rjs_fails_if_nothing_to_pick - render_rjs { } - assert_raise(Assertion) { assert_select_rjs } - end - - def test_assert_select_rjs_with_unicode - # Test that non-ascii characters (which are converted into \uXXXX in RJS) are decoded correctly. - - unicode = "\343\203\201\343\202\261\343\203\203\343\203\210" - render_rjs do |page| - page.replace "test", %(
#{unicode}
) - end - - assert_select_rjs do - str = "#1" - assert_select str, :text => unicode - assert_select str, unicode - if str.respond_to?(:force_encoding) - assert_select str, /\343\203\201..\343\203\210/u - assert_raise(Assertion) { assert_select str, /\343\203\201.\343\203\210/u } - else - assert_select str, Regexp.new("\343\203\201..\343\203\210", 0, 'U') - assert_raise(Assertion) { assert_select str, Regexp.new("\343\203\201.\343\203\210", 0, 'U') } - end - end - end - - def test_assert_select_rjs_with_id - # Test that we can pick up all statements in the result. - render_rjs do |page| - page.replace "test1", "
foo
" - page.replace_html "test2", "
foo
" - page.insert_html :top, "test3", "
foo
" - end - assert_select_rjs "test1" do - assert_select "div", 1 - assert_select "#1" - end - assert_select_rjs "test2" do - assert_select "div", 1 - assert_select "#2" - end - assert_select_rjs "test3" do - assert_select "div", 1 - assert_select "#3" - end - assert_raise(Assertion) { assert_select_rjs "test4" } - end - - def test_assert_select_rjs_for_replace - render_rjs do |page| - page.replace "test1", "
foo
" - page.replace_html "test2", "
foo
" - page.insert_html :top, "test3", "
foo
" - end - # Replace. - assert_select_rjs :replace do - assert_select "div", 1 - assert_select "#1" - end - assert_select_rjs :replace, "test1" do - assert_select "div", 1 - assert_select "#1" - end - assert_raise(Assertion) { assert_select_rjs :replace, "test2" } - # Replace HTML. - assert_select_rjs :replace_html do - assert_select "div", 1 - assert_select "#2" - end - assert_select_rjs :replace_html, "test2" do - assert_select "div", 1 - assert_select "#2" - end - assert_raise(Assertion) { assert_select_rjs :replace_html, "test1" } - end - - def test_assert_select_rjs_for_chained_replace - render_rjs do |page| - page['test1'].replace "
foo
" - page['test2'].replace_html "
foo
" - page.insert_html :top, "test3", "
foo
" - end - # Replace. - assert_select_rjs :chained_replace do - assert_select "div", 1 - assert_select "#1" - end - assert_select_rjs :chained_replace, "test1" do - assert_select "div", 1 - assert_select "#1" - end - assert_raise(Assertion) { assert_select_rjs :chained_replace, "test2" } - # Replace HTML. - assert_select_rjs :chained_replace_html do - assert_select "div", 1 - assert_select "#2" - end - assert_select_rjs :chained_replace_html, "test2" do - assert_select "div", 1 - assert_select "#2" - end - assert_raise(Assertion) { assert_select_rjs :replace_html, "test1" } - end - - # Simple remove - def test_assert_select_rjs_for_remove - render_rjs do |page| - page.remove "test1" - end - - assert_select_rjs :remove, "test1" - end - - def test_assert_select_rjs_for_remove_offers_useful_error_when_assertion_fails - render_rjs do |page| - page.remove "test_with_typo" - end - - assert_select_rjs :remove, "test1" - - rescue Assertion => e - assert_equal "No RJS statement that removes 'test1' was rendered.", e.message - end - - def test_assert_select_rjs_for_remove_ignores_block - render_rjs do |page| - page.remove "test1" - end - - assert_nothing_raised do - assert_select_rjs :remove, "test1" do - assert_select "p" - end - end - end - - # Simple show - def test_assert_select_rjs_for_show - render_rjs do |page| - page.show "test1" - end - - assert_select_rjs :show, "test1" - end - - def test_assert_select_rjs_for_show_offers_useful_error_when_assertion_fails - render_rjs do |page| - page.show "test_with_typo" - end - - assert_select_rjs :show, "test1" - - rescue Assertion => e - assert_equal "No RJS statement that shows 'test1' was rendered.", e.message - end - - def test_assert_select_rjs_for_show_ignores_block - render_rjs do |page| - page.show "test1" - end - - assert_nothing_raised do - assert_select_rjs :show, "test1" do - assert_select "p" - end - end - end - - # Simple hide - def test_assert_select_rjs_for_hide - render_rjs do |page| - page.hide "test1" - end - - assert_select_rjs :hide, "test1" - end - - def test_assert_select_rjs_for_hide_offers_useful_error_when_assertion_fails - render_rjs do |page| - page.hide "test_with_typo" - end - - assert_select_rjs :hide, "test1" - - rescue Assertion => e - assert_equal "No RJS statement that hides 'test1' was rendered.", e.message - end - - def test_assert_select_rjs_for_hide_ignores_block - render_rjs do |page| - page.hide "test1" - end - - assert_nothing_raised do - assert_select_rjs :hide, "test1" do - assert_select "p" - end - end - end - - # Simple toggle - def test_assert_select_rjs_for_toggle - render_rjs do |page| - page.toggle "test1" - end - - assert_select_rjs :toggle, "test1" - end - - def test_assert_select_rjs_for_toggle_offers_useful_error_when_assertion_fails - render_rjs do |page| - page.toggle "test_with_typo" - end - - assert_select_rjs :toggle, "test1" - - rescue Assertion => e - assert_equal "No RJS statement that toggles 'test1' was rendered.", e.message - end - - def test_assert_select_rjs_for_toggle_ignores_block - render_rjs do |page| - page.toggle "test1" - end - - assert_nothing_raised do - assert_select_rjs :toggle, "test1" do - assert_select "p" - end - end - end - - # Non-positioned insert. - def test_assert_select_rjs_for_nonpositioned_insert - render_rjs do |page| - page.replace "test1", "
foo
" - page.replace_html "test2", "
foo
" - page.insert_html :top, "test3", "
foo
" - end - assert_select_rjs :insert_html do - assert_select "div", 1 - assert_select "#3" - end - assert_select_rjs :insert_html, "test3" do - assert_select "div", 1 - assert_select "#3" - end - assert_raise(Assertion) { assert_select_rjs :insert_html, "test1" } - end - - # Positioned insert. - def test_assert_select_rjs_for_positioned_insert - render_rjs do |page| - page.insert_html :top, "test1", "
foo
" - page.insert_html :bottom, "test2", "
foo
" - page.insert_html :before, "test3", "
foo
" - page.insert_html :after, "test4", "
foo
" - end - assert_select_rjs :insert, :top do - assert_select "div", 1 - assert_select "#1" - end - assert_select_rjs :insert, :bottom do - assert_select "div", 1 - assert_select "#2" - end - assert_select_rjs :insert, :before do - assert_select "div", 1 - assert_select "#3" - end - assert_select_rjs :insert, :after do - assert_select "div", 1 - assert_select "#4" - end - assert_select_rjs :insert_html do - assert_select "div", 4 - end - end - - def test_assert_select_rjs_raise_errors - assert_raise(ArgumentError) { assert_select_rjs(:destroy) } - assert_raise(ArgumentError) { assert_select_rjs(:insert, :left) } - end - - # Simple selection from a single result. - def test_nested_assert_select_rjs_with_single_result - render_rjs do |page| - page.replace_html "test", "
foo
\n
foo
" - end - - assert_select_rjs "test" do |elements| - assert_equal 2, elements.size - assert_select "#1" - assert_select "#2" - end - end - - # Deal with two results. - def test_nested_assert_select_rjs_with_two_results - render_rjs do |page| - page.replace_html "test", "
foo
" - page.replace_html "test2", "
foo
" - end - - assert_select_rjs "test" do |elements| - assert_equal 1, elements.size - assert_select "#1" - end - - assert_select_rjs "test2" do |elements| - assert_equal 1, elements.size - assert_select "#2" - end - end - - def test_assert_select_rjs_for_redirect_to - render_rjs do |page| - page.redirect_to '/' - end - assert_select_rjs :redirect, '/' - end - - protected - def render_html(html) - @controller.response_with = html - get :html - end - - def render_rjs(&block) - @controller.response_with(&block) - get :rjs - end - - def render_xml(xml) - @controller.response_with = xml - get :xml - end -end diff --git a/test/controller/caching_test.rb b/test/controller/caching_test.rb index 5bc1617..20ce6c8 100644 --- a/test/controller/caching_test.rb +++ b/test/controller/caching_test.rb @@ -30,7 +30,7 @@ def setup @controller = FunctionalCachingController.new @controller.perform_caching = true @controller.cache_store = @store - @request = ActionController::TestRequest.new + @request = ActionController::TestRequest.create @response = ActionController::TestResponse.new end diff --git a/test/controller/mime_responds_test.rb b/test/controller/mime_responds_test.rb index 280b4b7..4bdb9d7 100644 --- a/test/controller/mime_responds_test.rb +++ b/test/controller/mime_responds_test.rb @@ -184,10 +184,13 @@ def test_xhr end class RespondWithController < ActionController::Base - respond_to :html, :json, :js def using_resource - respond_with(resource) + respond_to do |format| + format.html { render html: resource } + format.json { render json: resource } + format.js { render js: resource } + end end protected diff --git a/test/controller/render_js_test.rb b/test/controller/render_js_test.rb index 5b9c550..59e0a3e 100644 --- a/test/controller/render_js_test.rb +++ b/test/controller/render_js_test.rb @@ -2,7 +2,6 @@ class RenderJSTest < ActionController::TestCase class TestController < ActionController::Base - protect_from_forgery def self.controller_path 'test' diff --git a/test/javascript_helper_test.rb b/test/javascript_helper_test.rb index c79b067..daad92d 100644 --- a/test/javascript_helper_test.rb +++ b/test/javascript_helper_test.rb @@ -26,14 +26,14 @@ def test_link_to_function_with_rjs_block html = link_to_function( "Greet me!" ) do |page| page.replace_html 'header', "

Greetings

" end - assert_dom_equal %(Greet me!), html + assert_dom_equal %(Greet me!), html end def test_link_to_function_with_rjs_block_and_options html = link_to_function( "Greet me!", :class => "updater" ) do |page| page.replace_html 'header', "

Greetings

" end - assert_dom_equal %(Greet me!), html + assert_dom_equal %(Greet me!), html end def test_link_to_function_with_inner_block_does_not_raise_exception @@ -42,20 +42,20 @@ def test_link_to_function_with_inner_block_does_not_raise_exception 'Greetings' end) end - assert_dom_equal %(Greet me!), html + assert_dom_equal %(Greet me!), html end def test_button_to_function_with_rjs_block html = button_to_function( "Greet me!" ) do |page| page.replace_html 'header', "

Greetings

" end - assert_dom_equal %(), html + assert_dom_equal %(), html end def test_button_to_function_with_rjs_block_and_options html = button_to_function( "Greet me!", :class => "greeter" ) do |page| page.replace_html 'header', "

Greetings

" end - assert_dom_equal %(), html + assert_dom_equal %(), html end -end \ No newline at end of file +end diff --git a/test/render_other_test.rb b/test/render_other_test.rb index 27a533e..e573eb7 100644 --- a/test/render_other_test.rb +++ b/test/render_other_test.rb @@ -9,7 +9,6 @@ class RenderOtherTest < ActionController::TestCase class TestController < ActionController::Base - protect_from_forgery def self.controller_path 'test' diff --git a/test/template/prototype_helper_test.rb b/test/template/prototype_helper_test.rb index a6aa848..685bb67 100644 --- a/test/template/prototype_helper_test.rb +++ b/test/template/prototype_helper_test.rb @@ -142,23 +142,23 @@ def teardown def _evaluate_assigns_and_ivars() end def test_insert_html_with_string - assert_equal 'Element.insert("element", { top: "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E" });', + assert_equal 'Element.insert("element", { top: "\\u003cp\\u003eThis is a test\\u003c/p\\u003e" });', @generator.insert_html(:top, 'element', '

This is a test

') - assert_equal 'Element.insert("element", { bottom: "\\u003Cp\u003EThis is a test\\u003C/p\u003E" });', + assert_equal 'Element.insert("element", { bottom: "\\u003cp\u003eThis is a test\\u003c/p\u003e" });', @generator.insert_html(:bottom, 'element', '

This is a test

') - assert_equal 'Element.insert("element", { before: "\\u003Cp\u003EThis is a test\\u003C/p\u003E" });', + assert_equal 'Element.insert("element", { before: "\\u003cp\u003eThis is a test\\u003c/p\u003e" });', @generator.insert_html(:before, 'element', '

This is a test

') - assert_equal 'Element.insert("element", { after: "\\u003Cp\u003EThis is a test\\u003C/p\u003E" });', + assert_equal 'Element.insert("element", { after: "\\u003cp\u003eThis is a test\\u003c/p\u003e" });', @generator.insert_html(:after, 'element', '

This is a test

') end def test_replace_html_with_string - assert_equal 'Element.update("element", "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E");', + assert_equal 'Element.update("element", "\\u003cp\\u003eThis is a test\\u003c/p\\u003e");', @generator.replace_html('element', '

This is a test

') end def test_replace_element_with_string - assert_equal 'Element.replace("element", "\\u003Cdiv id=\"element\"\\u003E\\u003Cp\\u003EThis is a test\\u003C/p\\u003E\\u003C/div\\u003E");', + assert_equal 'Element.replace("element", "\\u003cdiv id=\"element\"\\u003e\\u003cp\\u003eThis is a test\\u003c/p\\u003e\\u003c/div\\u003e");', @generator.replace('element', '

This is a test

') end @@ -221,10 +221,10 @@ def test_to_s @generator.replace_html('baz', '

This is a test

') assert_equal <<-EOS.chomp, @generator.to_s -Element.insert("element", { top: "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E" }); -Element.insert("element", { bottom: "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E" }); +Element.insert("element", { top: "\\u003cp\\u003eThis is a test\\u003c/p\\u003e" }); +Element.insert("element", { bottom: "\\u003cp\\u003eThis is a test\\u003c/p\\u003e" }); ["foo","bar"].each(Element.remove); -Element.update("baz", "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E"); +Element.update("baz", "\\u003cp\\u003eThis is a test\\u003c/p\\u003e"); EOS end From cb082ceb5f4347ddb5df1b4aec1458aa8a512c35 Mon Sep 17 00:00:00 2001 From: Clif Reeder Date: Wed, 1 Mar 2017 11:30:23 -0500 Subject: [PATCH 04/22] back to how this was --- lib/action_view/helpers/prototype_helper.rb | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/lib/action_view/helpers/prototype_helper.rb b/lib/action_view/helpers/prototype_helper.rb index 1b2c7d1..5fdd762 100644 --- a/lib/action_view/helpers/prototype_helper.rb +++ b/lib/action_view/helpers/prototype_helper.rb @@ -532,15 +532,7 @@ def delay(seconds = 1) end def javascript_object_for(object) - if object.is_a?(ActionView::JsonLiteral) - result = object.as_json - elsif ActionView::Helpers::JavaScriptVariableProxy - result = object.as_json - else - result = ::ActiveSupport::JSON.encode(object) - end - puts "from #{object.class} to #{result.inspect}" - result + ActiveSupport::JSON.encode(object) end def arguments_for_call(arguments, block = nil) From 6c89a20624b5b4b5032a80d2d175bea27c68e3d7 Mon Sep 17 00:00:00 2001 From: Clif Reeder Date: Wed, 1 Mar 2017 11:43:21 -0500 Subject: [PATCH 05/22] bump version --- prototype-rails.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prototype-rails.gemspec b/prototype-rails.gemspec index 48424ff..69829a1 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.1' + spec.version = '4.0.2' spec.summary = 'Prototype, Scriptaculous, and RJS for Ruby on Rails' spec.homepage = 'http://github.com/rails/prototype-rails' spec.author = 'Xavier Noria' From 2e7622846858b85d1e7d06e0189c02990e37fca2 Mon Sep 17 00:00:00 2001 From: Clif Reeder Date: Wed, 1 Mar 2017 11:44:23 -0500 Subject: [PATCH 06/22] top level reference --- lib/action_view/helpers/prototype_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/action_view/helpers/prototype_helper.rb b/lib/action_view/helpers/prototype_helper.rb index 5fdd762..6e33385 100644 --- a/lib/action_view/helpers/prototype_helper.rb +++ b/lib/action_view/helpers/prototype_helper.rb @@ -532,7 +532,7 @@ def delay(seconds = 1) end def javascript_object_for(object) - ActiveSupport::JSON.encode(object) + ::ActiveSupport::JSON.encode(object) end def arguments_for_call(arguments, block = nil) From 55ccc0463545e7b30b7012c0a856c411080913e5 Mon Sep 17 00:00:00 2001 From: Clif Reeder Date: Wed, 1 Mar 2017 11:56:17 -0500 Subject: [PATCH 07/22] no need to delete anymore --- lib/prototype-rails/on_load_action_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/prototype-rails/on_load_action_controller.rb b/lib/prototype-rails/on_load_action_controller.rb index 4a8f835..92302e7 100644 --- a/lib/prototype-rails/on_load_action_controller.rb +++ b/lib/prototype-rails/on_load_action_controller.rb @@ -1 +1,2 @@ +require 'prototype-rails/selector_assertions' require 'prototype-rails/renderers' From 9b57f620c9474c62eae41c8c4e60bb7007c759bd Mon Sep 17 00:00:00 2001 From: Clif Reeder Date: Wed, 1 Mar 2017 11:57:56 -0500 Subject: [PATCH 08/22] versyion bump --- README.md | 30 +----------------------------- prototype-rails.gemspec | 2 +- 2 files changed, 2 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 03ad553..a1a6bd7 100644 --- a/README.md +++ b/README.md @@ -1,29 +1 @@ -prototype-rails provides Prototype, Scriptaculous, and RJS on Rails 3.1 -and later. - -Prototype and Scriptaculous are pulled in by the asset pipeline, so you don't -need to copy the source files into your app. You may reference them in your -s app/assets/javascripts/application.js: - - //= require prototype - //= require prototype_ujs - //= require effects - //= require dragdrop - //= require controls - -prototype-rails supports RJS debugging. RJS responses are wrapped to catch -exceptions, alert() them, and re-raise the exception. Debugging is disabled by -default. To enable in development, set `config.action_view.debug_rjs = true` -in config/environments/development.rb. - ---- - -## Support for Rails 4.1 and above - -Unfortunately, due to limited manpower and resources, the Rails core team has -not been able to confirm if this gem currently works with Rails 4.1 and above. -If you have found any problems while upgrading your application, please report -them at the [issue tracker](https://github.com/rails/prototype-rails/issues), -or better yet, submit patches by sending a [pull request](https://github.com/rails/prototype-rails/pulls). - -In any case, this gem will *NOT* be officially supported on Rails 5.0 and above. +This fork provides thoroughly untested and unsupport Rails 5 compatability for `prototype-rails`. diff --git a/prototype-rails.gemspec b/prototype-rails.gemspec index 69829a1..1d2c7dd 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.2' + 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 af970e99aeab60ccb60d0a1387732479c486369f Mon Sep 17 00:00:00 2001 From: Clif Reeder Date: Wed, 15 Mar 2017 11:20:16 -0400 Subject: [PATCH 09/22] Replace alias_method_chain to quiet Rails deperecations --- lib/prototype-rails/rendering.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/prototype-rails/rendering.rb b/lib/prototype-rails/rendering.rb index e2350d8..8ab58ed 100644 --- a/lib/prototype-rails/rendering.rb +++ b/lib/prototype-rails/rendering.rb @@ -8,6 +8,7 @@ def render_with_update(options = {}, locals = {}, &block) render_without_update(options, locals, &block) end end - - alias_method_chain :render, :update -end \ No newline at end of file + + alias_method :render_without_update, :render + alias_method_chain :render, :render_with_update +end From 7c4bfb9a344c12da212948b89414024aefa5e8fb Mon Sep 17 00:00:00 2001 From: Clif Reeder Date: Wed, 15 Mar 2017 11:20:44 -0400 Subject: [PATCH 10/22] Version bump --- prototype-rails.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prototype-rails.gemspec b/prototype-rails.gemspec index 1d2c7dd..8e3f183 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.1.1' spec.summary = 'Prototype, Scriptaculous, and RJS for Ruby on Rails' spec.homepage = 'http://github.com/rails/prototype-rails' spec.author = 'Xavier Noria' From 6604edbb603792ad8ff6caac8e8085e4b9e52edb Mon Sep 17 00:00:00 2001 From: Clif Reeder Date: Wed, 15 Mar 2017 11:27:13 -0400 Subject: [PATCH 11/22] I am not very smart --- lib/prototype-rails/rendering.rb | 2 +- prototype-rails.gemspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/prototype-rails/rendering.rb b/lib/prototype-rails/rendering.rb index 8ab58ed..0b42a74 100644 --- a/lib/prototype-rails/rendering.rb +++ b/lib/prototype-rails/rendering.rb @@ -10,5 +10,5 @@ def render_with_update(options = {}, locals = {}, &block) end alias_method :render_without_update, :render - alias_method_chain :render, :render_with_update + alias_method :render, :render_with_update end diff --git a/prototype-rails.gemspec b/prototype-rails.gemspec index 8e3f183..b2fd2f9 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.1' + spec.version = '4.1.2' spec.summary = 'Prototype, Scriptaculous, and RJS for Ruby on Rails' spec.homepage = 'http://github.com/rails/prototype-rails' spec.author = 'Xavier Noria' From e385756cbabb5608d1eab47b6416cdd49613c73b Mon Sep 17 00:00:00 2001 From: Clif Reeder Date: Wed, 15 Mar 2017 11:33:41 -0400 Subject: [PATCH 12/22] Don't access MIME types as constants - it is deprecated --- lib/action_view/template/handlers/rjs.rb | 2 +- lib/prototype-rails/renderers.rb | 4 ++-- lib/prototype-rails/selector_assertions.rb | 2 +- prototype-rails.gemspec | 2 +- test/controller/content_type_test.rb | 2 +- test/controller/mime_responds_test.rb | 2 +- test/render_other_test.rb | 2 +- 7 files changed, 8 insertions(+), 8 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..e03347e 100644 --- a/lib/prototype-rails/renderers.rb +++ b/lib/prototype-rails/renderers.rb @@ -5,8 +5,8 @@ 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 -end \ No newline at end of file +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/prototype-rails.gemspec b/prototype-rails.gemspec index b2fd2f9..95544cd 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.2' + spec.version = '4.1.3' spec.summary = 'Prototype, Scriptaculous, and RJS for Ruby on Rails' spec.homepage = 'http://github.com/rails/prototype-rails' spec.author = 'Xavier Noria' 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 4bdb9d7..262e45c 100644 --- a/test/controller/mime_responds_test.rb +++ b/test/controller/mime_responds_test.rb @@ -199,7 +199,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 e573eb7..e72ba43 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 7547c6fa2562b2afd967383bc9b16bb6fc1ec83c Mon Sep 17 00:00:00 2001 From: Curtis Schiewek Date: Wed, 20 Jan 2021 10:51:26 -0500 Subject: [PATCH 13/22] update default fomat to use a symbol --- 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 6107102..a5e50c9 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 = :js def call(template) "update_page do |page|;#{template.source}\nend" From e2e9ae2d226527539ee486a6f04a25da9ed47bc4 Mon Sep 17 00:00:00 2001 From: Curtis Schiewek Date: Wed, 20 Jan 2021 10:53:20 -0500 Subject: [PATCH 14/22] update lock file --- Gemfile.lock | 208 +++++++++++++++++++++++++++++---------------------- 1 file changed, 117 insertions(+), 91 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 8c74d8a..3aab74d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,120 +1,146 @@ PATH remote: . specs: - prototype-rails (4.0.1) + prototype-rails (4.1.3) rails (>= 4.2) GEM remote: https://rubygems.org/ specs: - actioncable (5.0.1) - actionpack (= 5.0.1) - nio4r (~> 1.2) - websocket-driver (~> 0.6.1) - actionmailer (5.0.1) - actionpack (= 5.0.1) - actionview (= 5.0.1) - activejob (= 5.0.1) + actioncable (6.1.1) + actionpack (= 6.1.1) + activesupport (= 6.1.1) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + actionmailbox (6.1.1) + actionpack (= 6.1.1) + activejob (= 6.1.1) + activerecord (= 6.1.1) + activestorage (= 6.1.1) + activesupport (= 6.1.1) + mail (>= 2.7.1) + actionmailer (6.1.1) + actionpack (= 6.1.1) + actionview (= 6.1.1) + activejob (= 6.1.1) + activesupport (= 6.1.1) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.0.1) - actionview (= 5.0.1) - activesupport (= 5.0.1) - rack (~> 2.0) - rack-test (~> 0.6.3) + actionpack (6.1.1) + actionview (= 6.1.1) + activesupport (= 6.1.1) + rack (~> 2.0, >= 2.0.9) + rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.0.1) - activesupport (= 5.0.1) + rails-html-sanitizer (~> 1.0, >= 1.2.0) + actiontext (6.1.1) + actionpack (= 6.1.1) + activerecord (= 6.1.1) + activestorage (= 6.1.1) + activesupport (= 6.1.1) + nokogiri (>= 1.8.5) + actionview (6.1.1) + activesupport (= 6.1.1) builder (~> 3.1) - erubis (~> 2.7.0) + erubi (~> 1.4) rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - activejob (5.0.1) - activesupport (= 5.0.1) + rails-html-sanitizer (~> 1.1, >= 1.2.0) + activejob (6.1.1) + activesupport (= 6.1.1) globalid (>= 0.3.6) - activemodel (5.0.1) - activesupport (= 5.0.1) - activerecord (5.0.1) - activemodel (= 5.0.1) - activesupport (= 5.0.1) - arel (~> 7.0) - activesupport (5.0.1) + activemodel (6.1.1) + activesupport (= 6.1.1) + activerecord (6.1.1) + activemodel (= 6.1.1) + activesupport (= 6.1.1) + activestorage (6.1.1) + actionpack (= 6.1.1) + activejob (= 6.1.1) + activerecord (= 6.1.1) + activesupport (= 6.1.1) + marcel (~> 0.3.1) + mimemagic (~> 0.3.2) + activesupport (6.1.1) concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (~> 0.7) - minitest (~> 5.1) - tzinfo (~> 1.1) - arel (7.1.4) - builder (3.2.3) - concurrent-ruby (1.0.5) - erubis (2.7.0) - globalid (0.3.7) - activesupport (>= 4.1.0) - i18n (0.8.1) - loofah (2.0.3) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + zeitwerk (~> 2.3) + builder (3.2.4) + concurrent-ruby (1.1.8) + crass (1.0.6) + erubi (1.10.0) + globalid (0.4.2) + activesupport (>= 4.2.0) + i18n (1.8.7) + concurrent-ruby (~> 1.0) + loofah (2.9.0) + crass (~> 1.0.2) nokogiri (>= 1.5.9) - mail (2.6.4) - mime-types (>= 1.16, < 4) - metaclass (0.0.4) - method_source (0.8.2) - mime-types (3.1) - mime-types-data (~> 3.2015) - mime-types-data (3.2016.0521) - mini_portile2 (2.1.0) - minitest (5.10.1) - mocha (1.2.1) - metaclass (~> 0.0.1) - nio4r (1.2.1) - nokogiri (1.7.0.1) - mini_portile2 (~> 2.1.0) - rack (2.0.1) - rack-test (0.6.3) - rack (>= 1.0) - rails (5.0.1) - actioncable (= 5.0.1) - actionmailer (= 5.0.1) - actionpack (= 5.0.1) - actionview (= 5.0.1) - activejob (= 5.0.1) - activemodel (= 5.0.1) - activerecord (= 5.0.1) - activesupport (= 5.0.1) - bundler (>= 1.3.0, < 2.0) - railties (= 5.0.1) + mail (2.7.1) + mini_mime (>= 0.1.1) + marcel (0.3.3) + mimemagic (~> 0.3.2) + method_source (1.0.0) + mimemagic (0.3.5) + mini_mime (1.0.2) + minitest (5.14.3) + mocha (1.12.0) + nio4r (2.5.4) + nokogiri (1.11.1-x86_64-linux) + racc (~> 1.4) + racc (1.5.2) + rack (2.2.3) + rack-test (1.1.0) + rack (>= 1.0, < 3) + rails (6.1.1) + actioncable (= 6.1.1) + actionmailbox (= 6.1.1) + actionmailer (= 6.1.1) + actionpack (= 6.1.1) + actiontext (= 6.1.1) + actionview (= 6.1.1) + activejob (= 6.1.1) + activemodel (= 6.1.1) + activerecord (= 6.1.1) + activestorage (= 6.1.1) + activesupport (= 6.1.1) + bundler (>= 1.15.0) + railties (= 6.1.1) sprockets-rails (>= 2.0.0) - rails-controller-testing (1.0.1) - actionpack (~> 5.x) - actionview (~> 5.x) - activesupport (~> 5.x) - rails-dom-testing (2.0.2) - activesupport (>= 4.2.0, < 6.0) - nokogiri (~> 1.6) - rails-html-sanitizer (1.0.3) - loofah (~> 2.0) - railties (5.0.1) - actionpack (= 5.0.1) - activesupport (= 5.0.1) + rails-controller-testing (1.0.5) + actionpack (>= 5.0.1.rc1) + actionview (>= 5.0.1.rc1) + activesupport (>= 5.0.1.rc1) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) + rails-html-sanitizer (1.3.0) + loofah (~> 2.3) + railties (6.1.1) + actionpack (= 6.1.1) + activesupport (= 6.1.1) method_source rake (>= 0.8.7) - thor (>= 0.18.1, < 2.0) - rake (12.0.0) - sprockets (3.7.1) + thor (~> 1.0) + rake (13.0.3) + sprockets (4.0.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) - sprockets-rails (3.2.0) + sprockets-rails (3.2.2) actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) - thor (0.19.4) - thread_safe (0.3.6) - tzinfo (1.2.2) - thread_safe (~> 0.1) - websocket-driver (0.6.5) + thor (1.0.1) + tzinfo (2.0.4) + concurrent-ruby (~> 1.0) + websocket-driver (0.7.3) websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.2) + websocket-extensions (0.1.5) + zeitwerk (2.4.2) PLATFORMS - ruby + x86_64-linux DEPENDENCIES mocha @@ -122,4 +148,4 @@ DEPENDENCIES rails-controller-testing BUNDLED WITH - 1.13.6 + 2.2.3 From b0484e8669937e55044c6d5db6f5cd50a4565569 Mon Sep 17 00:00:00 2001 From: Curtis Schiewek Date: Wed, 20 Jan 2021 10:55:11 -0500 Subject: [PATCH 15/22] bump version --- prototype-rails.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prototype-rails.gemspec b/prototype-rails.gemspec index 95544cd..5f41537 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.3' + spec.version = '4.1.4' spec.summary = 'Prototype, Scriptaculous, and RJS for Ruby on Rails' spec.homepage = 'http://github.com/rails/prototype-rails' spec.author = 'Xavier Noria' From 0d1dae76e0165baaf3bdca4ffdaae85fcb588974 Mon Sep 17 00:00:00 2001 From: Eric Binmore Date: Thu, 20 May 2021 12:28:49 -0400 Subject: [PATCH 16/22] Update template to Rails 6 format --- lib/action_view/template/handlers/rjs.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/action_view/template/handlers/rjs.rb b/lib/action_view/template/handlers/rjs.rb index a5e50c9..233d10d 100644 --- a/lib/action_view/template/handlers/rjs.rb +++ b/lib/action_view/template/handlers/rjs.rb @@ -5,8 +5,8 @@ class RJS class_attribute :default_format self.default_format = :js - def call(template) - "update_page do |page|;#{template.source}\nend" + def call(template, source) + "update_page do |page|;#{source}\nend" end end end From 7c5acd2ab66d47259df86c5f76c69eb3a95cfdd3 Mon Sep 17 00:00:00 2001 From: Eric Binmore Date: Thu, 20 May 2021 12:29:06 -0400 Subject: [PATCH 17/22] Update version --- prototype-rails.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prototype-rails.gemspec b/prototype-rails.gemspec index 5f41537..cf4e2be 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.4' + 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 9d69583b0ad343bbcfc13bde67abe3b1a2e018ba Mon Sep 17 00:00:00 2001 From: Jamie McCarthy Date: Tue, 26 Jul 2022 10:03:15 -0500 Subject: [PATCH 18/22] This version is not rails 6 compatible --- prototype-rails.gemspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/prototype-rails.gemspec b/prototype-rails.gemspec index 5f41537..9581d14 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.4' + spec.version = '4.1.5' 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/**/*'] - spec.add_dependency('rails', '>= 4.2') + spec.add_dependency('rails', '>= 4.2', '< 6.0') spec.add_development_dependency('mocha') spec.add_development_dependency('rails-controller-testing') spec.license = "MIT" From 0570892c331331aa1d39e0426193847107096497 Mon Sep 17 00:00:00 2001 From: Jamie McCarthy Date: Tue, 26 Jul 2022 09:18:34 -0500 Subject: [PATCH 19/22] Allow #call to be invoked differently in Rails 6 --- Gemfile.lock | 2 +- lib/action_view/template/handlers/rjs.rb | 5 +++-- prototype-rails.gemspec | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 3aab74d..907d0d8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -148,4 +148,4 @@ DEPENDENCIES rails-controller-testing BUNDLED WITH - 2.2.3 + 2.3.6 diff --git a/lib/action_view/template/handlers/rjs.rb b/lib/action_view/template/handlers/rjs.rb index 233d10d..89f415a 100644 --- a/lib/action_view/template/handlers/rjs.rb +++ b/lib/action_view/template/handlers/rjs.rb @@ -5,8 +5,9 @@ class RJS class_attribute :default_format self.default_format = :js - def call(template, source) - "update_page do |page|;#{source}\nend" + def call(template, source=nil) + block_source = Rails.version >= "6" ? source : template.source + "update_page do |page|;#{block_source}\nend" end end end diff --git a/prototype-rails.gemspec b/prototype-rails.gemspec index 99bfaea..818eb6d 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 9ace425b5437730f9e1e9977717fe3ef6808cee0 Mon Sep 17 00:00:00 2001 From: Jamie McCarthy Date: Tue, 26 Jul 2022 10:05:09 -0500 Subject: [PATCH 20/22] Note this version is now rails 6 compatible --- prototype-rails.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prototype-rails.gemspec b/prototype-rails.gemspec index 818eb6d..05938f3 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/**/*'] - spec.add_dependency('rails', '>= 4.2', '< 6.0') + spec.add_dependency('rails', '>= 4.2') spec.add_development_dependency('mocha') spec.add_development_dependency('rails-controller-testing') spec.license = "MIT" From 5b108206010111988dda39fa8f2f5884c6098027 Mon Sep 17 00:00:00 2001 From: William Wu Date: Sat, 23 Nov 2024 13:39:31 -0800 Subject: [PATCH 21/22] added back render :update with a block to rails 7 --- lib/prototype-rails/on_load_action_controller.rb | 1 + lib/prototype-rails/update_rendering.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 lib/prototype-rails/update_rendering.rb diff --git a/lib/prototype-rails/on_load_action_controller.rb b/lib/prototype-rails/on_load_action_controller.rb index 92302e7..d5542c7 100644 --- a/lib/prototype-rails/on_load_action_controller.rb +++ b/lib/prototype-rails/on_load_action_controller.rb @@ -1,2 +1,3 @@ require 'prototype-rails/selector_assertions' require 'prototype-rails/renderers' +require 'prototype-rails/update_rendering' diff --git a/lib/prototype-rails/update_rendering.rb b/lib/prototype-rails/update_rendering.rb new file mode 100644 index 0000000..5cdea94 --- /dev/null +++ b/lib/prototype-rails/update_rendering.rb @@ -0,0 +1,16 @@ +require 'action_controller/metal/rendering' + +module ActionController::Rendering::UpdateRendering + + private + + # Normalize arguments by catching blocks and setting them on :update. + # Copied from rails 6 + def _normalize_args(action = nil, options = {}, &blk) + options = super + options[:update] = blk if block_given? + options + end +end + +ActionController::Rendering.include ActionController::Rendering::UpdateRendering From 333ccc92ddd29e8a725d5b985ea2d5cb32d568ff Mon Sep 17 00:00:00 2001 From: William Wu Date: Sat, 23 Nov 2024 13:56:34 -0800 Subject: [PATCH 22/22] update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a1a6bd7..a6b1637 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -This fork provides thoroughly untested and unsupport Rails 5 compatability for `prototype-rails`. +This fork provides thoroughly untested and unsupport Rails 7 compatability for `prototype-rails`.