From cad28c0ef34e23550d0ffbf39a8032dbd34e6417 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Tue, 25 Jun 2013 03:58:14 +0200 Subject: [PATCH] simpler FakeSafeBuffer implementation for testing references #93 --- test/helper.rb | 21 --------------------- test/utils_test.rb | 11 +++++++++++ 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/test/helper.rb b/test/helper.rb index 85efc5cb..a4821ea9 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -81,24 +81,3 @@ module Faraday end end end - -# The essential part of ActiveSupport::SafeBuffer to demonstrate -# how it blows up when passed to Faraday::Utils.escape -# rails/rails@ed738f7 -class FakeSafeBuffer < String - UNSAFE_STRING_METHODS = %w(gsub) - - def to_s - self - end - - UNSAFE_STRING_METHODS.each do |unsafe_method| - if 'String'.respond_to?(unsafe_method) - class_eval <<-EOT, __FILE__, __LINE__ + 1 - def #{unsafe_method}(*args, &block) # def capitalize(*args, &block) - to_str.#{unsafe_method}(*args, &block) # to_str.capitalize(*args, &block) - end # end - EOT - end - end -end diff --git a/test/utils_test.rb b/test/utils_test.rb index dbd529d6..2f035bd7 100644 --- a/test/utils_test.rb +++ b/test/utils_test.rb @@ -9,6 +9,17 @@ class TestUtils < Faraday::TestCase Faraday::Utils.default_uri_parser = nil end + # emulates ActiveSupport::SafeBuffer#gsub + FakeSafeBuffer = Struct.new(:string) do + def to_s() self end + def gsub(regex) + string.gsub(regex) { + match, = $&, '' =~ /a/ + yield match + } + end + end + def test_escaping_safe_buffer str = FakeSafeBuffer.new('$32,000.00') assert_equal '%2432%2C000.00', Faraday::Utils.escape(str)