diff options
24 files changed, 174 insertions, 324 deletions
diff --git a/actionpack/Rakefile b/actionpack/Rakefile index d9e3e56fcc..effb6badfc 100755 --- a/actionpack/Rakefile +++ b/actionpack/Rakefile @@ -16,7 +16,7 @@ Rake::TestTask.new(:test_action_pack) do |t| # make sure we include the tests in alphabetical order as on some systems # this will not happen automatically and the tests (as a whole) will error - t.test_files = Dir.glob('test/{abstract,controller,dispatch,template}/**/*_test.rb').sort + t.test_files = Dir.glob('test/{abstract,controller,dispatch,template,assertions}/**/*_test.rb').sort t.warning = true t.verbose = true diff --git a/actionpack/lib/action_controller/metal/request_forgery_protection.rb b/actionpack/lib/action_controller/metal/request_forgery_protection.rb index bc22e39efb..afa9243f02 100644 --- a/actionpack/lib/action_controller/metal/request_forgery_protection.rb +++ b/actionpack/lib/action_controller/metal/request_forgery_protection.rb @@ -74,7 +74,7 @@ module ActionController #:nodoc: # The actual before_filter that is used. Modify this to change how you handle unverified requests. def verify_authenticity_token unless verified_request? - logger.warn "WARNING: Can't verify CSRF token authenticity" if logger + logger.warn "Can't verify CSRF token authenticity" if logger handle_unverified_request end end diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index e96ff82a5a..05e9362463 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -69,15 +69,12 @@ module ActionController # assert_template :partial => '_customer', :locals => { :customer => @customer } # def assert_template(options = {}, message = nil) - validate_request! - case options when NilClass, String, Symbol options = options.to_s if Symbol === options rendered = @templates - msg = build_message(message, - "expecting <?> but rendering with <?>", - options, rendered.keys.join(', ')) + msg = message || sprintf("expecting <%s> but rendering with <%s>", + options, rendered.keys) assert_block(msg) do if options rendered.any? { |t,num| t.match(options) } @@ -87,13 +84,12 @@ module ActionController end when Hash if expected_layout = options[:layout] - msg = build_message(message, - "expecting layout <?> but action rendered <?>", + msg = message || sprintf("expecting layout <%s> but action rendered <%s>", expected_layout, @layouts.keys) case expected_layout when String - assert(@layouts.keys.include?(expected_layout), msg) + assert_includes @layouts.keys, expected_layout, msg when Regexp assert(@layouts.keys.any? {|l| l =~ expected_layout }, msg) when nil @@ -109,15 +105,13 @@ module ActionController end elsif expected_count = options[:count] actual_count = @partials[expected_partial] - msg = build_message(message, - "expecting ? to be rendered ? time(s) but rendered ? time(s)", + msg = message || sprintf("expecting %s to be rendered %s time(s) but rendered %s time(s)", expected_partial, expected_count, actual_count) assert(actual_count == expected_count.to_i, msg) else - msg = build_message(message, - "expecting partial <?> but action rendered <?>", + msg = message || sprintf("expecting partial <%s> but action rendered <%s>", options[:partial], @partials.keys) - assert(@partials.include?(expected_partial), msg) + assert_includes @partials, expected_partial, msg end else assert @partials.empty?, diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 9d0a3e9993..2c21887220 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -533,7 +533,6 @@ module ActionDispatch end def url_for(options) - finalize! options = (options || {}).reverse_merge!(default_url_options) handle_positional_args(options) @@ -559,7 +558,6 @@ module ActionDispatch end def call(env) - finalize! @router.call(env) end diff --git a/actionpack/lib/action_dispatch/testing/assertions/dom.rb b/actionpack/lib/action_dispatch/testing/assertions/dom.rb index 47c84742aa..edea6dab39 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/dom.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/dom.rb @@ -13,9 +13,7 @@ module ActionDispatch def assert_dom_equal(expected, actual, message = "") expected_dom = HTML::Document.new(expected).root actual_dom = HTML::Document.new(actual).root - full_message = build_message(message, "<?> expected to be == to\n<?>.", expected_dom.to_s, actual_dom.to_s) - - assert_block(full_message) { expected_dom == actual_dom } + assert_equal expected_dom, actual_dom end # The negated form of +assert_dom_equivalent+. @@ -28,9 +26,7 @@ module ActionDispatch def assert_dom_not_equal(expected, actual, message = "") expected_dom = HTML::Document.new(expected).root actual_dom = HTML::Document.new(actual).root - full_message = build_message(message, "<?> expected to be != to\n<?>.", expected_dom.to_s, actual_dom.to_s) - - assert_block(full_message) { expected_dom != actual_dom } + refute_equal expected_dom, actual_dom end end end diff --git a/actionpack/lib/action_dispatch/testing/assertions/response.rb b/actionpack/lib/action_dispatch/testing/assertions/response.rb index 7381617dd7..094cfbfc76 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/response.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/response.rb @@ -26,16 +26,17 @@ module ActionDispatch # assert_response 401 # def assert_response(type, message = nil) - validate_request! + message ||= "Expected response to be a <#{type}>, but was <#{@response.response_code}>" - if type.in?([:success, :missing, :redirect, :error]) && @response.send("#{type}?") - assert_block("") { true } # to count the assertion - elsif type.is_a?(Fixnum) && @response.response_code == type - assert_block("") { true } # to count the assertion - elsif type.is_a?(Symbol) && @response.response_code == Rack::Utils::SYMBOL_TO_STATUS_CODE[type] - assert_block("") { true } # to count the assertion + if Symbol === type + if [:success, :missing, :redirect, :error].include?(type) + assert @response.send("#{type}?"), message + else + code = Rack::Utils::SYMBOL_TO_STATUS_CODE[type] + assert_equal @response.response_code, code, message + end else - flunk(build_message(message, "Expected response to be a <?>, but was <?>", type, @response.response_code)) + assert_equal type, @response.response_code, message end end @@ -61,9 +62,8 @@ module ActionDispatch redirect_is = normalize_argument_to_redirection(@response.location) redirect_expected = normalize_argument_to_redirection(options) - if redirect_is != redirect_expected - flunk "Expected response to be a redirect to <#{redirect_expected}> but was a redirect to <#{redirect_is}>" - end + message ||= "Expected response to be a redirect to <#{redirect_expected}> but was a redirect to <#{redirect_is}>" + assert_equal redirect_expected, redirect_is, message end private @@ -85,12 +85,6 @@ module ActionDispatch @controller.url_for(fragment) end.gsub(/[\r\n]/, '') end - - def validate_request! - unless @request.is_a?(ActionDispatch::Request) - raise ArgumentError, "@request must be an ActionDispatch::Request" - end - end end end end diff --git a/actionpack/lib/action_dispatch/testing/assertions/routing.rb b/actionpack/lib/action_dispatch/testing/assertions/routing.rb index b10aab9029..1552676fbb 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/routing.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/routing.rb @@ -45,9 +45,11 @@ module ActionDispatch extras.each_key { |key| expected_options.delete key } unless extras.nil? expected_options.stringify_keys! - msg = build_message(message, "The recognized options <?> did not match <?>, difference: <?>", + + # FIXME: minitest does object diffs, do we need to have our own? + message ||= sprintf("The recognized options <%s> did not match <%s>, difference: <%s>", request.path_parameters, expected_options, expected_options.diff(request.path_parameters)) - assert_equal(expected_options, request.path_parameters, msg) + assert_equal(expected_options, request.path_parameters, message) end # Asserts that the provided options can be used to generate the provided path. This is the inverse of +assert_recognizes+. @@ -84,10 +86,10 @@ module ActionDispatch generated_path, extra_keys = @routes.generate_extras(options, defaults) found_extras = options.reject {|k, v| ! extra_keys.include? k} - msg = build_message(message, "found extras <?>, not <?>", found_extras, extras) + msg = message || sprintf("found extras <%s>, not <%s>", found_extras, extras) assert_equal(extras, found_extras, msg) - msg = build_message(message, "The generated path <?> did not match <?>", generated_path, + msg = message || sprintf("The generated path <%s> did not match <%s>", generated_path, expected_path) assert_equal(expected_path, generated_path, msg) end diff --git a/actionpack/lib/action_dispatch/testing/assertions/selector.rb b/actionpack/lib/action_dispatch/testing/assertions/selector.rb index b4555f4f59..4d963803e6 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/selector.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/selector.rb @@ -270,7 +270,7 @@ module ActionDispatch end text.strip! unless NO_STRIP.include?(match.name) unless match_with.is_a?(Regexp) ? (text =~ match_with) : (text == match_with.to_s) - content_mismatch ||= build_message(message, "<?> expected but was\n<?>.", match_with, text) + content_mismatch ||= sprintf("<%s> expected but was\n<%s>.", match_with, text) true end end @@ -279,7 +279,7 @@ module ActionDispatch html = match.children.map(&:to_s).join html.strip! unless NO_STRIP.include?(match.name) unless match_with.is_a?(Regexp) ? (html =~ match_with) : (html == match_with.to_s) - content_mismatch ||= build_message(message, "<?> expected but was\n<?>.", match_with, html) + content_mismatch ||= sprintf("<%s> expected but was\n<%s>.", match_with, html) true end end @@ -289,12 +289,15 @@ module ActionDispatch message ||= content_mismatch if matches.empty? # Test minimum/maximum occurrence. min, max, count = equals[:minimum], equals[:maximum], equals[:count] + + # FIXME: minitest provides messaging when we use assert_operator, + # so is this custom message really needed? message = message || %(Expected #{count_description(min, max, count)} matching "#{selector.to_s}", found #{matches.size}.) if count - assert matches.size == count, message + assert_equal matches.size, count, message else - assert matches.size >= min, message if min - assert matches.size <= max, message if max + assert_operator matches.size, :>=, min, message if min + assert_operator matches.size, :<=, max, message if max end # If a block is given call that block. Set @selected to allow diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 08c7fbc281..fdddb33c31 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -1091,7 +1091,7 @@ module ActionView else add_default_name_and_id(options) end - hidden = tag("input", "name" => options["name"], "type" => "hidden", "value" => unchecked_value, "disabled" => options["disabled"]) + hidden = unchecked_value ? tag("input", "name" => options["name"], "type" => "hidden", "value" => unchecked_value, "disabled" => options["disabled"]) : "" checkbox = tag("input", options) hidden + checkbox end diff --git a/actionpack/lib/sprockets/assets.rake b/actionpack/lib/sprockets/assets.rake index a61a121d55..43405f3db9 100644 --- a/actionpack/lib/sprockets/assets.rake +++ b/actionpack/lib/sprockets/assets.rake @@ -1,12 +1,12 @@ require "fileutils" namespace :assets do - def ruby_rake_task(task) + def ruby_rake_task(task, fork = true) env = ENV['RAILS_ENV'] || 'production' groups = ENV['RAILS_GROUPS'] || 'assets' args = [$0, task,"RAILS_ENV=#{env}","RAILS_GROUPS=#{groups}"] args << "--trace" if Rake.application.options.trace - ruby(*args) + fork ? ruby(*args) : Kernel.exec(FileUtils::RUBY, *args) end # We are currently running with no explicit bundler group @@ -59,7 +59,7 @@ namespace :assets do # required in order to compile digestless assets as the # environment has already cached the assets on the primary # run. - ruby_rake_task "assets:precompile:nondigest" if Rails.application.config.assets.digest + ruby_rake_task("assets:precompile:nondigest", false) if Rails.application.config.assets.digest end task :primary => ["assets:environment", "tmp:cache:clear"] do diff --git a/actionpack/test/assertions/response_assertions_test.rb b/actionpack/test/assertions/response_assertions_test.rb new file mode 100644 index 0000000000..ca1d58765d --- /dev/null +++ b/actionpack/test/assertions/response_assertions_test.rb @@ -0,0 +1,55 @@ +require 'abstract_unit' +require 'action_dispatch/testing/assertions/response' + +module ActionDispatch + module Assertions + class ResponseAssertionsTest < ActiveSupport::TestCase + include ResponseAssertions + + FakeResponse = Struct.new(:response_code) do + [:success, :missing, :redirect, :error].each do |sym| + define_method("#{sym}?") do + sym == response_code + end + end + end + + def test_assert_response_predicate_methods + [:success, :missing, :redirect, :error].each do |sym| + @response = FakeResponse.new sym + assert_response sym + + assert_raises(MiniTest::Assertion) { + assert_response :unauthorized + } + end + end + + def test_assert_response_fixnum + @response = FakeResponse.new 400 + assert_response 400 + + assert_raises(MiniTest::Assertion) { + assert_response :unauthorized + } + + assert_raises(MiniTest::Assertion) { + assert_response 500 + } + end + + def test_assert_response_sym_status + @response = FakeResponse.new 401 + assert_response :unauthorized + + assert_raises(MiniTest::Assertion) { + assert_response :ok + } + + assert_raises(MiniTest::Assertion) { + assert_response :success + } + end + end + end +end diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index a36b1f713f..ad0cc41d69 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -65,7 +65,7 @@ class FormHelperTest < ActionView::TestCase def full_messages() [ "Author name can't be empty" ] end }.new end - def @post.id; 123; end + def @post.to_key; [123]; end def @post.id_before_type_cast; 123; end def @post.to_param; '123'; end @@ -374,6 +374,14 @@ class FormHelperTest < ActionView::TestCase ) end + def test_check_box_with_nil_unchecked_value + @post.secret = "on" + assert_dom_equal( + '<input checked="checked" id="post_secret" name="post[secret]" type="checkbox" value="on" />', + check_box("post", "secret", {}, "on", nil) + ) + end + def test_check_box_with_multiple_behavior @post.comment_ids = [2,3] assert_dom_equal( @@ -628,7 +636,7 @@ class FormHelperTest < ActionView::TestCase end def test_auto_index - pid = @post.id + pid = 123 assert_dom_equal( "<label for=\"post_#{pid}_title\">Title</label>", label("post[]", "title") @@ -654,7 +662,7 @@ class FormHelperTest < ActionView::TestCase end def test_auto_index_with_nil_id - pid = @post.id + pid = 123 assert_dom_equal( "<input name=\"post[#{pid}][title]\" size=\"30\" type=\"text\" value=\"Hello World\" />", text_field("post[]","title", :id => nil) @@ -867,7 +875,7 @@ class FormHelperTest < ActionView::TestCase def test_form_for_with_remote_without_html @post.persisted = false - def @post.id; nil; end + def @post.to_key; nil; end form_for(@post, :remote => true) do |f| concat f.text_field(:title) concat f.text_area(:body) @@ -1017,7 +1025,7 @@ class FormHelperTest < ActionView::TestCase old_locale, I18n.locale = I18n.locale, :submit @post.persisted = false - def @post.id; nil; end + def @post.to_key; nil; end form_for(@post) do |f| concat f.submit end @@ -2089,7 +2097,7 @@ class FormHelperTest < ActionView::TestCase def test_form_for_with_new_object post = Post.new post.persisted = false - def post.id() nil end + def post.to_key; nil; end form_for(post) do |f| end diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb index aafd1c8a74..025915fe6f 100644 --- a/activemodel/lib/active_model/errors.rb +++ b/activemodel/lib/active_model/errors.rb @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- -require 'active_support/core_ext/array/wrap' require 'active_support/core_ext/array/conversions' require 'active_support/core_ext/string/inflections' require 'active_support/core_ext/object/blank' diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 0efa111d12..58725246c8 100644 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1,4 +1,3 @@ -require 'active_support/core_ext/array/wrap' require 'active_support/core_ext/enumerable' require 'active_support/core_ext/module/delegation' require 'active_support/core_ext/object/blank' diff --git a/activesupport/lib/active_support/core_ext/date_time/calculations.rb b/activesupport/lib/active_support/core_ext/date_time/calculations.rb index 1a3cf66a1b..6dd321ecf9 100644 --- a/activesupport/lib/active_support/core_ext/date_time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/date_time/calculations.rb @@ -79,29 +79,6 @@ class DateTime change(:hour => 23, :min => 59, :sec => 59) end - # 1.9.3 defines + and - on DateTime, < 1.9.3 do not. - if DateTime.public_instance_methods(false).include?(:+) - def plus_with_duration(other) #:nodoc: - if ActiveSupport::Duration === other - other.since(self) - else - plus_without_duration(other) - end - end - alias_method :plus_without_duration, :+ - alias_method :+, :plus_with_duration - - def minus_with_duration(other) #:nodoc: - if ActiveSupport::Duration === other - plus_with_duration(-other) - else - minus_without_duration(other) - end - end - alias_method :minus_without_duration, :- - alias_method :-, :minus_with_duration - end - # Adjusts DateTime to UTC by adding its offset value; offset is set to 0 # # Example: diff --git a/activesupport/lib/active_support/multibyte/chars.rb b/activesupport/lib/active_support/multibyte/chars.rb index 99b974e4a7..ac61870871 100644 --- a/activesupport/lib/active_support/multibyte/chars.rb +++ b/activesupport/lib/active_support/multibyte/chars.rb @@ -93,7 +93,7 @@ module ActiveSupport #:nodoc: chars(Unicode.unpack_graphemes(@wrapped_string).reverse.flatten.pack('U*')) end - # Limit the byte size of the string to a number of bytes without breaking characters. Usable + # Limits the byte size of the string to a number of bytes without breaking characters. Usable # when the storage for a string is limited for some reason. # # Example: @@ -102,7 +102,7 @@ module ActiveSupport #:nodoc: slice(0...translate_offset(limit)) end - # Convert characters in the string to uppercase. + # Converts characters in the string to uppercase. # # Example: # 'Laurent, où sont les tests ?'.mb_chars.upcase.to_s # => "LAURENT, OÙ SONT LES TESTS ?" @@ -110,7 +110,7 @@ module ActiveSupport #:nodoc: chars Unicode.upcase(@wrapped_string) end - # Convert characters in the string to lowercase. + # Converts characters in the string to lowercase. # # Example: # 'VĚDA A VÝZKUM'.mb_chars.downcase.to_s # => "věda a výzkum" @@ -118,6 +118,14 @@ module ActiveSupport #:nodoc: chars Unicode.downcase(@wrapped_string) end + # Converts characters in the string to the opposite case. + # + # Example: + # 'El Cañón".mb_chars.swapcase.to_s # => "eL cAÑÓN" + def swapcase + chars Unicode.swapcase(@wrapped_string) + end + # Converts the first character to uppercase and the remainder to lowercase. # # Example: diff --git a/activesupport/lib/active_support/multibyte/unicode.rb b/activesupport/lib/active_support/multibyte/unicode.rb index 94fb0a48aa..a0a8f3c97e 100644 --- a/activesupport/lib/active_support/multibyte/unicode.rb +++ b/activesupport/lib/active_support/multibyte/unicode.rb @@ -293,9 +293,17 @@ module ActiveSupport apply_mapping string, :uppercase_mapping end + def swapcase(string) + apply_mapping string, :swapcase_mapping + end + # Holds data about a codepoint in the Unicode database class Codepoint attr_accessor :code, :combining_class, :decomp_type, :decomp_mapping, :uppercase_mapping, :lowercase_mapping + + def swapcase_mapping + uppercase_mapping > 0 ? uppercase_mapping : lowercase_mapping + end end # Holds static data from the Unicode database diff --git a/activesupport/lib/active_support/testing/deprecation.rb b/activesupport/lib/active_support/testing/deprecation.rb index 0135185a47..a8342904dc 100644 --- a/activesupport/lib/active_support/testing/deprecation.rb +++ b/activesupport/lib/active_support/testing/deprecation.rb @@ -34,22 +34,3 @@ module ActiveSupport end end end - -begin - require 'test/unit/error' -rescue LoadError - # Using miniunit, ignore. -else - module Test - module Unit - class Error #:nodoc: - # Silence warnings when reporting test errors. - def message_with_silenced_deprecation - ActiveSupport::Deprecation.silence { message_without_silenced_deprecation } - end - alias_method :message_without_silenced_deprecation, :message - alias_method :message, :message_with_silenced_deprecation - end - end - end -end diff --git a/activesupport/test/deprecation_test.rb b/activesupport/test/deprecation_test.rb index d77a62f108..e821a285d7 100644 --- a/activesupport/test/deprecation_test.rb +++ b/activesupport/test/deprecation_test.rb @@ -120,7 +120,7 @@ class DeprecationTest < ActiveSupport::TestCase ActiveSupport::Deprecation.warn 'abc' ActiveSupport::Deprecation.warn 'def' end - rescue Test::Unit::AssertionFailedError + rescue MiniTest::Assertion flunk 'assert_deprecated should match any warning in block, not just the last one' end @@ -166,22 +166,4 @@ class DeprecationTest < ActiveSupport::TestCase def test_deprecation_with_explicit_message assert_deprecated(/you now need to do something extra for this one/) { @dtc.d } end - - unless defined?(::MiniTest) - def test_assertion_failed_error_doesnt_spout_deprecation_warnings - error_class = Class.new(StandardError) do - def message - ActiveSupport::Deprecation.warn 'warning in error message' - super - end - end - - raise error_class.new('hmm') - - rescue => e - error = Test::Unit::Error.new('testing ur doodz', e) - assert_not_deprecated { error.message } - assert_nil @last_message - end - end end diff --git a/activesupport/test/isolation_test.rb b/activesupport/test/isolation_test.rb deleted file mode 100644 index c1932d73d9..0000000000 --- a/activesupport/test/isolation_test.rb +++ /dev/null @@ -1,162 +0,0 @@ -require 'abstract_unit' -require 'rbconfig' - -if defined?(MiniTest) || defined?(Test::Unit::TestResultFailureSupport) - $stderr.puts "Isolation tests can test test-unit 1 only" - -elsif ENV['CHILD'] - class ChildIsolationTest < ActiveSupport::TestCase - include ActiveSupport::Testing::Isolation - - def self.setup - File.open(File.join(File.dirname(__FILE__), "fixtures", "isolation_test"), "a") do |f| - f.puts "hello" - end - end - - def setup - @instance = "HELLO" - end - - def teardown - raise if @boom - end - - test "runs the test" do - assert true - end - - test "captures errors" do - raise - end - - test "captures failures" do - assert false - end - - test "first runs in isolation" do - assert_nil $x - $x = 1 - end - - test "second runs in isolation" do - assert_nil $x - $x = 2 - end - - test "runs with slow tests" do - sleep 0.3 - assert true - sleep 0.2 - end - - test "runs setup" do - assert "HELLO", @instance - end - - test "runs teardown" do - @boom = true - end - - test "resets requires one" do - assert !defined?(Custom) - assert_equal 0, $LOADED_FEATURES.grep(/fixtures\/custom/).size - require File.expand_path(File.join(File.dirname(__FILE__), "fixtures", "custom")) - end - - test "resets requires two" do - assert !defined?(Custom) - assert_equal 0, $LOADED_FEATURES.grep(/fixtures\/custom/).size - require File.expand_path(File.join(File.dirname(__FILE__), "fixtures", "custom")) - end - end -else - class ParentIsolationTest < ActiveSupport::TestCase - - File.open(File.join(File.dirname(__FILE__), "fixtures", "isolation_test"), "w") {} - - ENV["CHILD"] = "1" - OUTPUT = `#{RbConfig::CONFIG["bindir"]}/#{RbConfig::CONFIG["ruby_install_name"]} -I#{File.dirname(__FILE__)} "#{File.expand_path(__FILE__)}" -v` - ENV.delete("CHILD") - - def setup - @results = {} - OUTPUT[/Started\n\s*(.*)\s*\nFinished/mi, 1].to_s.split(/\s*\n\s*/).each do |result| - result =~ %r'^\w+#(\w+):.*:\s*(.*Assertion.*|.*RuntimeError.*|\.\s*)$' - val = :success - val = :error if $2.include?('RuntimeError') - val = :failure if $2.include?('Assertion') - - @results[$1] = val - end - - # Extract the backtraces - @backtraces = {} - OUTPUT.scan(/^\s*\d+\).*?\n\n/m).each do |backtrace| - # \n 1) Error:\ntest_captures_errors(ChildIsolationTest): - backtrace =~ %r'\s*\d+\)\s*(Error|Failure):\n(\w+)'i - @backtraces[$2] = {:type => $1, :output => backtrace} - end - end - - def assert_failing(name) - assert_equal :failure, @results[name.to_s], "Test #{name} failed" - end - - def assert_passing(name) - assert_equal :success, @results[name.to_s], "Test #{name} passed" - end - - def assert_erroring(name) - assert_equal :error, @results[name.to_s], "Test #{name} errored" - end - - test "has all tests" do - assert_equal 10, @results.length - end - - test "passing tests are still reported" do - assert_passing :test_runs_the_test - assert_passing :test_runs_with_slow_tests - end - - test "resets global variables" do - assert_passing :test_first_runs_in_isolation - assert_passing :test_second_runs_in_isolation - end - - test "resets requires" do - assert_passing :test_resets_requires_one - assert_passing :test_resets_requires_two - end - - test "erroring tests are still reported" do - assert_erroring :test_captures_errors - end - - test "runs setup and teardown methods" do - assert_passing :test_runs_setup - assert_erroring :test_runs_teardown - end - - test "correct tests fail" do - assert_failing :test_captures_failures - end - - test "backtrace is printed for errors" do - assert_equal 'Error', @backtraces["test_captures_errors"][:type] - assert_match %r{isolation_test.rb:\d+}, @backtraces["test_captures_errors"][:output] - end - - test "backtrace is printed for failures" do - assert_equal 'Failure', @backtraces["test_captures_failures"][:type] - assert_match %r{isolation_test.rb:\d+}, @backtraces["test_captures_failures"][:output] - end - - test "self.setup is run only once" do - text = File.read(File.join(File.dirname(__FILE__), "fixtures", "isolation_test")) - assert_equal "hello\n", text - end - - end -end diff --git a/activesupport/test/multibyte_chars_test.rb b/activesupport/test/multibyte_chars_test.rb index 971bd30781..63e7a35c01 100644 --- a/activesupport/test/multibyte_chars_test.rb +++ b/activesupport/test/multibyte_chars_test.rb @@ -106,7 +106,7 @@ class MultibyteCharsUTF8BehaviourTest < ActiveSupport::TestCase end end - %w{capitalize downcase lstrip reverse rstrip upcase}.each do |method| + %w{capitalize downcase lstrip reverse rstrip swapcase upcase}.each do |method| class_eval(<<-EOTESTS) def test_#{method}_bang_should_return_self_when_modifying_wrapped_string chars = ' él piDió Un bUen café ' @@ -161,6 +161,7 @@ class MultibyteCharsUTF8BehaviourTest < ActiveSupport::TestCase assert chars('').decompose.kind_of?(ActiveSupport::Multibyte.proxy_class) assert chars('').compose.kind_of?(ActiveSupport::Multibyte.proxy_class) assert chars('').tidy_bytes.kind_of?(ActiveSupport::Multibyte.proxy_class) + assert chars('').swapcase.kind_of?(ActiveSupport::Multibyte.proxy_class) end def test_should_be_equal_to_the_wrapped_string @@ -432,6 +433,11 @@ class MultibyteCharsUTF8BehaviourTest < ActiveSupport::TestCase assert_equal 'abc', 'aBc'.mb_chars.downcase end + def test_swapcase_should_swap_ascii_characters + assert_equal '', ''.mb_chars.swapcase + assert_equal 'AbC', 'aBc'.mb_chars.swapcase + end + def test_capitalize_should_work_on_ascii_characters assert_equal '', ''.mb_chars.capitalize assert_equal 'Abc', 'abc'.mb_chars.capitalize @@ -466,10 +472,15 @@ class MultibyteCharsExtrasTest < ActiveSupport::TestCase end def test_downcase_should_be_unicode_aware - assert_equal "абвгд\0f", chars("аБвгд\0f").downcase + assert_equal "абвгд\0f", chars("аБвгд\0F").downcase assert_equal 'こにちわ', chars('こにちわ').downcase end + def test_swapcase_should_be_unicode_aware + assert_equal "аaéÜ\0f", chars("АAÉü\0F").swapcase + assert_equal 'こにちわ', chars('こにちわ').swapcase + end + def test_capitalize_should_be_unicode_aware { 'аБвг аБвг' => 'Абвг абвг', 'аБвг АБВГ' => 'Абвг абвг', diff --git a/activesupport/test/test_case_test.rb b/activesupport/test/test_case_test.rb index 756d21b3e4..20982d089d 100644 --- a/activesupport/test/test_case_test.rb +++ b/activesupport/test/test_case_test.rb @@ -18,44 +18,42 @@ module ActiveSupport end end - if defined?(MiniTest::Assertions) && TestCase < MiniTest::Assertions - def test_callback_with_exception - tc = Class.new(TestCase) do - setup :bad_callback - def bad_callback; raise 'oh noes' end - def test_true; assert true end - end - - test_name = 'test_true' - fr = FakeRunner.new - - test = tc.new test_name - test.run fr - klass, name, exception = *fr.puked.first - - assert_equal tc, klass - assert_equal test_name, name - assert_equal 'oh noes', exception.message + def test_callback_with_exception + tc = Class.new(TestCase) do + setup :bad_callback + def bad_callback; raise 'oh noes' end + def test_true; assert true end end - def test_teardown_callback_with_exception - tc = Class.new(TestCase) do - teardown :bad_callback - def bad_callback; raise 'oh noes' end - def test_true; assert true end - end + test_name = 'test_true' + fr = FakeRunner.new - test_name = 'test_true' - fr = FakeRunner.new + test = tc.new test_name + test.run fr + klass, name, exception = *fr.puked.first - test = tc.new test_name - test.run fr - klass, name, exception = *fr.puked.first + assert_equal tc, klass + assert_equal test_name, name + assert_equal 'oh noes', exception.message + end - assert_equal tc, klass - assert_equal test_name, name - assert_equal 'oh noes', exception.message + def test_teardown_callback_with_exception + tc = Class.new(TestCase) do + teardown :bad_callback + def bad_callback; raise 'oh noes' end + def test_true; assert true end end + + test_name = 'test_true' + fr = FakeRunner.new + + test = tc.new test_name + test.run fr + klass, name, exception = *fr.puked.first + + assert_equal tc, klass + assert_equal test_name, name + assert_equal 'oh noes', exception.message end end end diff --git a/railties/lib/rails/application/routes_reloader.rb b/railties/lib/rails/application/routes_reloader.rb index ef7e733ce4..6f9a200aa9 100644 --- a/railties/lib/rails/application/routes_reloader.rb +++ b/railties/lib/rails/application/routes_reloader.rb @@ -42,7 +42,7 @@ module Rails def finalize! route_sets.each do |routes| - ActiveSupport.on_load(:action_controller) { routes.finalize! } + routes.finalize! end end diff --git a/railties/lib/rails/generators/actions.rb b/railties/lib/rails/generators/actions.rb index ce62ea463d..7e7d54e6ed 100644 --- a/railties/lib/rails/generators/actions.rb +++ b/railties/lib/rails/generators/actions.rb @@ -1,6 +1,5 @@ require 'open-uri' require 'rbconfig' -require 'active_support/core_ext/array/wrap' module Rails module Generators @@ -92,7 +91,7 @@ module Rails if options[:env].nil? inject_into_file 'config/application.rb', "\n #{data}", :after => sentinel, :verbose => false else - Array.wrap(options[:env]).each do |env| + Array(options[:env]).each do |env| inject_into_file "config/environments/#{env}.rb", "\n #{data}", :after => env_file_sentinel, :verbose => false end end |