diff options
51 files changed, 252 insertions, 168 deletions
diff --git a/.travis.yml b/.travis.yml index 3130ee1b32..0038668ae7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,15 +13,14 @@ env: matrix: - "GEM=railties" - "GEM=ap" - - "GEM=aj" - - "GEM=am,amo,as,av" + - "GEM=am,amo,as,av,aj" - "GEM=ar:mysql" - "GEM=ar:mysql2" - "GEM=ar:sqlite3" - "GEM=ar:postgresql" - "GEM=aj:integration" rvm: - - 2.2 + - 2.2.1 - ruby-head - rbx-2 - jruby-head @@ -31,8 +30,6 @@ matrix: - rvm: ruby-head - rvm: rbx-2 - rvm: jruby-head - - env: "GEM=aj" - - env: "GEM=aj:integration" fast_finish: true notifications: email: false @@ -49,7 +49,7 @@ group :job do gem 'backburner', require: false gem 'qu-rails', github: "bkeepers/qu", branch: "master", require: false gem 'qu-redis', require: false - # gem 'delayed_job_active_record', require: false + gem 'delayed_job_active_record', require: false gem 'sequel', require: false end diff --git a/Gemfile.lock b/Gemfile.lock index e34449a7b0..0dc7559d9e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -117,6 +117,9 @@ GEM dante (0.1.5) delayed_job (4.0.6) activesupport (>= 3.0, < 5.0) + delayed_job_active_record (4.0.3) + activerecord (>= 3.0, < 5.0) + delayed_job (>= 3.0, < 4.1) erubis (2.7.0) execjs (2.3.0) globalid (0.3.3) @@ -252,6 +255,7 @@ DEPENDENCIES coffee-rails (~> 4.1.0) dalli (>= 2.2.1) delayed_job + delayed_job_active_record jquery-rails! json kindlerb (= 0.1.1) diff --git a/actionmailer/test/abstract_unit.rb b/actionmailer/test/abstract_unit.rb index c4d5cb8c33..ae91903c95 100644 --- a/actionmailer/test/abstract_unit.rb +++ b/actionmailer/test/abstract_unit.rb @@ -42,8 +42,3 @@ def jruby_skip(message = '') end require 'mocha/setup' # FIXME: stop using mocha - -# FIXME: we have tests that depend on run order, we should fix that and -# remove this method call. -require 'active_support/test_case' -ActiveSupport::TestCase.test_order = :sorted diff --git a/actionpack/Rakefile b/actionpack/Rakefile index 4b60b77759..3bd27f8d64 100644 --- a/actionpack/Rakefile +++ b/actionpack/Rakefile @@ -9,10 +9,7 @@ task :default => :test # Run the unit tests Rake::TestTask.new do |t| t.libs << 'test' - - # 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 = test_files.sort + t.test_files = test_files t.warning = true t.verbose = true diff --git a/actionpack/lib/action_controller/metal/url_for.rb b/actionpack/lib/action_controller/metal/url_for.rb index 572d1770f7..fbaa90d521 100644 --- a/actionpack/lib/action_controller/metal/url_for.rb +++ b/actionpack/lib/action_controller/metal/url_for.rb @@ -4,7 +4,10 @@ module ActionController # # In addition to <tt>AbstractController::UrlFor</tt>, this module accesses the HTTP layer to define # url options like the +host+. In order to do so, this module requires the host class - # to implement +env+ and +request+, which need to be a Rack-compatible. + # to implement +env+ which needs to be Rack-compatible and +request+ + # which is either instance of +ActionDispatch::Request+ or an object + # that responds to <tt>host</tt>, <tt>optional_port</tt>, <tt>protocol</tt> and + # <tt>symbolized_path_parameter</tt> methods. # # class RootUrl # include ActionController::UrlFor diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb index 5fe544c60c..a895d1ab18 100644 --- a/actionpack/lib/action_dispatch/http/response.rb +++ b/actionpack/lib/action_dispatch/http/response.rb @@ -113,9 +113,7 @@ module ActionDispatch # :nodoc: # The underlying body, as a streamable object. attr_reader :stream - # Ruby 2.2 bug https://bugs.ruby-lang.org/issues/10685 prevents - # default_headers from being a keyword argument. - def initialize(status = 200, header = {}, body = [], default_headers = self.class.default_headers) + def initialize(status = 200, header = {}, body = [], default_headers: self.class.default_headers) super() header = merge_default_headers(header, default_headers) diff --git a/actionpack/lib/action_dispatch/railtie.rb b/actionpack/lib/action_dispatch/railtie.rb index 8cde5eb6f7..ddeea24bb3 100644 --- a/actionpack/lib/action_dispatch/railtie.rb +++ b/actionpack/lib/action_dispatch/railtie.rb @@ -40,8 +40,6 @@ module ActionDispatch ActionDispatch::Cookies::CookieJar.always_write_cookie = config.action_dispatch.always_write_cookie ActionDispatch.test_app = app - - ActionDispatch::Routing::RouteSet.relative_url_root = app.config.relative_url_root end end end diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 6d964c2cbf..0f3734dd74 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -20,8 +20,6 @@ module ActionDispatch # alias inspect to to_s. alias inspect to_s - mattr_accessor :relative_url_root - class Dispatcher < Routing::Endpoint def initialize(defaults) @defaults = defaults @@ -320,11 +318,25 @@ module ActionDispatch { :new => 'new', :edit => 'edit' } end - def initialize + def self.new_with_config(config) + if config.respond_to? :relative_url_root + new Config.new config.relative_url_root + else + # engines apparently don't have this set + new + end + end + + Config = Struct.new :relative_url_root + + DEFAULT_CONFIG = Config.new(nil) + + def initialize(config = DEFAULT_CONFIG) self.named_routes = NamedRouteCollection.new self.resources_path_names = self.class.default_resources_path_names self.default_url_options = {} + @config = config @append = [] @prepend = [] @disable_clear_and_finalize = false @@ -336,6 +348,10 @@ module ActionDispatch @formatter = Journey::Formatter.new @set end + def relative_url_root + @config.relative_url_root + end + def request_class ActionDispatch::Request end diff --git a/actionpack/lib/action_dispatch/testing/test_response.rb b/actionpack/lib/action_dispatch/testing/test_response.rb index 527784885c..a9b88ac5fd 100644 --- a/actionpack/lib/action_dispatch/testing/test_response.rb +++ b/actionpack/lib/action_dispatch/testing/test_response.rb @@ -7,7 +7,7 @@ module ActionDispatch # See Response for more information on controller response objects. class TestResponse < Response def self.from_response(response) - new response.status, response.headers, response.body, nil + new response.status, response.headers, response.body, default_headers: nil end # Was the response successful? diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index f5dd9d76af..62ff1be5c9 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -483,8 +483,3 @@ if RUBY_ENGINE == "ruby" && PROCESS_COUNT > 0 # Use N processes (N defaults to 4) Minitest.parallel_executor = ForkingExecutor.new(PROCESS_COUNT) end - -# FIXME: we have tests that depend on run order, we should fix that and -# remove this method call. -require 'active_support/test_case' -ActiveSupport::TestCase.test_order = :sorted diff --git a/actionpack/test/controller/url_for_test.rb b/actionpack/test/controller/url_for_test.rb index cd63493b32..31677f202d 100644 --- a/actionpack/test/controller/url_for_test.rb +++ b/actionpack/test/controller/url_for_test.rb @@ -30,8 +30,8 @@ module AbstractController assert_equal '/foo/zot', path end - def add_host! - W.default_url_options[:host] = 'www.basecamphq.com' + def add_host!(app = W) + app.default_url_options[:host] = 'www.basecamphq.com' end def add_port! @@ -257,12 +257,16 @@ module AbstractController def test_relative_url_root_is_respected_with_environment_variable # `config.relative_url_root` is set by ENV['RAILS_RELATIVE_URL_ROOT'] - ActionDispatch::Routing::RouteSet.relative_url_root = '/subdir' - add_host! + w = Class.new { + config = ActionDispatch::Routing::RouteSet::Config.new '/subdir' + r = ActionDispatch::Routing::RouteSet.new(config) + r.draw { get ':controller(/:action(/:id(.:format)))' } + include r.url_helpers + } + add_host!(w) assert_equal('https://www.basecamphq.com/subdir/c/a/i', - W.new.url_for(:controller => 'c', :action => 'a', :id => 'i', :protocol => 'https') + w.new.url_for(:controller => 'c', :action => 'a', :id => 'i', :protocol => 'https') ) - ActionDispatch::Routing::RouteSet.relative_url_root = nil end def test_named_routes diff --git a/actionview/CHANGELOG.md b/actionview/CHANGELOG.md index 101f1263d9..82a636315a 100644 --- a/actionview/CHANGELOG.md +++ b/actionview/CHANGELOG.md @@ -1,3 +1,10 @@ +* `number_to_percentage` does not crash with `Float::NAN` or `Float::INFINITY` + as input when `precision: 0` is used. + + Fixes #19227. + + *Yves Senn* + * Fixed the translation helper method to accept different default values types besides String. diff --git a/actionview/Rakefile b/actionview/Rakefile index 1b71435948..2b752b83df 100644 --- a/actionview/Rakefile +++ b/actionview/Rakefile @@ -18,7 +18,7 @@ namespace :test do Rake::TestTask.new(:template) do |t| t.libs << 'test' - t.test_files = Dir.glob('test/template/**/*_test.rb').sort + t.test_files = Dir.glob('test/template/**/*_test.rb') t.warning = true t.verbose = true t.ruby_opts = ["--dev"] if defined?(JRUBY_VERSION) diff --git a/actionview/lib/action_view/helpers/debug_helper.rb b/actionview/lib/action_view/helpers/debug_helper.rb index ba47eee9ba..e9dccbad1c 100644 --- a/actionview/lib/action_view/helpers/debug_helper.rb +++ b/actionview/lib/action_view/helpers/debug_helper.rb @@ -26,7 +26,7 @@ module ActionView Marshal::dump(object) object = ERB::Util.html_escape(object.to_yaml) content_tag(:pre, object, :class => "debug_dump") - rescue Exception # errors from Marshal or YAML + rescue # errors from Marshal or YAML # Object couldn't be dumped, perhaps because of singleton methods -- this is the fallback content_tag(:code, object.inspect, :class => "debug_dump") end diff --git a/actionview/lib/action_view/helpers/text_helper.rb b/actionview/lib/action_view/helpers/text_helper.rb index 2c40ed1832..c216d4401f 100644 --- a/actionview/lib/action_view/helpers/text_helper.rb +++ b/actionview/lib/action_view/helpers/text_helper.rb @@ -103,7 +103,9 @@ module ActionView # Highlights one or more +phrases+ everywhere in +text+ by inserting it into # a <tt>:highlighter</tt> string. The highlighter can be specialized by passing <tt>:highlighter</tt> # as a single-quoted string with <tt>\1</tt> where the phrase is to be inserted (defaults to - # '<mark>\1</mark>') or passing a block that receives each matched term. + # '<mark>\1</mark>') or passing a block that receives each matched term. By default +text+ + # is sanitized to prevent possible XSS attacks. If the input is trustworthy, passing false + # for <tt>:sanitize</tt> will turn sanitizing off. # # highlight('You searched for: rails', 'rails') # # => You searched for: <mark>rails</mark> @@ -122,6 +124,9 @@ module ActionView # # highlight('You searched for: rails', 'rails') { |match| link_to(search_path(q: match, match)) } # # => You searched for: <a href="search?q=rails">rails</a> + # + # highlight('<a href="javascript:alert(\'no!\')">ruby</a> on rails', 'rails', sanitize: false) + # # => "<a>ruby</a> on <mark>rails</mark>" def highlight(text, phrases, options = {}) text = sanitize(text) if options.fetch(:sanitize, true) diff --git a/actionview/lib/action_view/layouts.rb b/actionview/lib/action_view/layouts.rb index 0b5c0b9991..9d636c8c9e 100644 --- a/actionview/lib/action_view/layouts.rb +++ b/actionview/lib/action_view/layouts.rb @@ -228,7 +228,7 @@ module ActionView # set by the <tt>layout</tt> method. # # ==== Returns - # * <tt> Boolean</tt> - True if the action has a layout definition, false otherwise. + # * <tt>Boolean</tt> - True if the action has a layout definition, false otherwise. def _conditional_layout? return unless super diff --git a/actionview/test/abstract_unit.rb b/actionview/test/abstract_unit.rb index fc1ca9efdf..3eded74f1b 100644 --- a/actionview/test/abstract_unit.rb +++ b/actionview/test/abstract_unit.rb @@ -338,8 +338,3 @@ def jruby_skip(message = '') end require 'mocha/setup' # FIXME: stop using mocha - -# FIXME: we have tests that depend on run order, we should fix that and -# remove this method call. -require 'active_support/test_case' -ActiveSupport::TestCase.test_order = :sorted diff --git a/actionview/test/activerecord/debug_helper_test.rb b/actionview/test/activerecord/debug_helper_test.rb index 5609694cd5..03cb1d5a91 100644 --- a/actionview/test/activerecord/debug_helper_test.rb +++ b/actionview/test/activerecord/debug_helper_test.rb @@ -1,8 +1,14 @@ require 'active_record_unit' +require 'nokogiri' class DebugHelperTest < ActionView::TestCase def test_debug company = Company.new(name: "firebase") assert_match "name: firebase", debug(company) end + + def test_debug_with_marshal_error + obj = -> { } + assert_match obj.inspect, Nokogiri.XML(debug(obj)).content + end end diff --git a/actionview/test/template/number_helper_test.rb b/actionview/test/template/number_helper_test.rb index b59883b760..b70b750869 100644 --- a/actionview/test/template/number_helper_test.rb +++ b/actionview/test/template/number_helper_test.rb @@ -35,6 +35,10 @@ class NumberHelperTest < ActionView::TestCase assert_equal "98a%", number_to_percentage("98a") assert_equal "NaN%", number_to_percentage(Float::NAN) assert_equal "Inf%", number_to_percentage(Float::INFINITY) + assert_equal "NaN%", number_to_percentage(Float::NAN, precision: 0) + assert_equal "Inf%", number_to_percentage(Float::INFINITY, precision: 0) + assert_equal "NaN%", number_to_percentage(Float::NAN, precision: 1) + assert_equal "Inf%", number_to_percentage(Float::INFINITY, precision: 1) end def test_number_with_delimiter diff --git a/activejob/lib/active_job/test_helper.rb b/activejob/lib/active_job/test_helper.rb index 66508114d1..bb8b267c31 100644 --- a/activejob/lib/active_job/test_helper.rb +++ b/activejob/lib/active_job/test_helper.rb @@ -13,6 +13,7 @@ module ActiveJob clear_performed_jobs queue_adapter.perform_enqueued_jobs = false queue_adapter.perform_enqueued_at_jobs = false + queue_adapter.filter = nil super end @@ -253,15 +254,20 @@ module ActiveJob end def perform_enqueued_jobs(only: nil) - @old_perform_enqueued_jobs = queue_adapter.perform_enqueued_jobs - @old_perform_enqueued_at_jobs = queue_adapter.perform_enqueued_at_jobs - queue_adapter.perform_enqueued_jobs = true - queue_adapter.perform_enqueued_at_jobs = true - queue_adapter.filter = only - yield - ensure - queue_adapter.perform_enqueued_jobs = @old_perform_enqueued_jobs - queue_adapter.perform_enqueued_at_jobs = @old_perform_enqueued_at_jobs + old_perform_enqueued_jobs = queue_adapter.perform_enqueued_jobs + old_perform_enqueued_at_jobs = queue_adapter.perform_enqueued_at_jobs + old_filter = queue_adapter.filter + + begin + queue_adapter.perform_enqueued_jobs = true + queue_adapter.perform_enqueued_at_jobs = true + queue_adapter.filter = only + yield + ensure + queue_adapter.perform_enqueued_jobs = old_perform_enqueued_jobs + queue_adapter.perform_enqueued_at_jobs = old_perform_enqueued_at_jobs + queue_adapter.filter = old_filter + end end def queue_adapter diff --git a/activejob/test/cases/test_helper_test.rb b/activejob/test/cases/test_helper_test.rb index 58de2f2588..19a2820a6e 100644 --- a/activejob/test/cases/test_helper_test.rb +++ b/activejob/test/cases/test_helper_test.rb @@ -199,6 +199,14 @@ class EnqueuedJobsTest < ActiveJob::TestCase end class PerformedJobsTest < ActiveJob::TestCase + def test_performed_enqueue_jobs_with_only_option_doesnt_leak_outside_the_block + assert_equal nil, queue_adapter.filter + perform_enqueued_jobs only: HelloJob do + assert_equal HelloJob, queue_adapter.filter + end + assert_equal nil, queue_adapter.filter + end + def test_assert_performed_jobs assert_nothing_raised do assert_performed_jobs 1 do diff --git a/activejob/test/support/integration/adapters/qu.rb b/activejob/test/support/integration/adapters/qu.rb index 3a5b66a057..256ddb3cf3 100644 --- a/activejob/test/support/integration/adapters/qu.rb +++ b/activejob/test/support/integration/adapters/qu.rb @@ -3,7 +3,7 @@ module QuJobsManager require 'qu-rails' require 'qu-redis' ActiveJob::Base.queue_adapter = :qu - ENV['REDISTOGO_URL'] = "tcp://127.0.0.1:6379/12" + ENV['REDISTOGO_URL'] = "redis://127.0.0.1:6379/12" backend = Qu::Backend::Redis.new backend.namespace = "active_jobs_int_test" Qu.backend = backend diff --git a/activejob/test/support/integration/adapters/queue_classic.rb b/activejob/test/support/integration/adapters/queue_classic.rb index 038473ccdc..f522b2711f 100644 --- a/activejob/test/support/integration/adapters/queue_classic.rb +++ b/activejob/test/support/integration/adapters/queue_classic.rb @@ -1,6 +1,7 @@ module QueueClassicJobsManager def setup ENV['QC_DATABASE_URL'] ||= 'postgres:///active_jobs_qc_int_test' + ENV['QC_RAILS_DATABASE'] = 'false' ENV['QC_LISTEN_TIME'] = "0.5" uri = URI.parse(ENV['QC_DATABASE_URL']) user = uri.user||ENV['USER'] @@ -20,7 +21,8 @@ module QueueClassicJobsManager end def start_workers - QC::Conn.disconnect + QC.default_conn_adapter.disconnect + QC.default_conn_adapter = nil @pid = fork do worker = QC::Worker.new(q_name: 'integration_tests') worker.start diff --git a/activemodel/Rakefile b/activemodel/Rakefile index c30a559ef5..7256285a41 100644 --- a/activemodel/Rakefile +++ b/activemodel/Rakefile @@ -6,7 +6,7 @@ task :default => :test Rake::TestTask.new do |t| t.libs << "test" - t.test_files = Dir.glob("#{dir}/test/cases/**/*_test.rb").sort + t.test_files = Dir.glob("#{dir}/test/cases/**/*_test.rb") t.warning = true t.verbose = true t.ruby_opts = ["--dev"] if defined?(JRUBY_VERSION) diff --git a/activemodel/test/cases/helper.rb b/activemodel/test/cases/helper.rb index 3276f69f09..2b9de5e5d2 100644 --- a/activemodel/test/cases/helper.rb +++ b/activemodel/test/cases/helper.rb @@ -22,8 +22,3 @@ end def jruby_skip(message = '') skip message if defined?(JRUBY_VERSION) end - -# FIXME: we have tests that depend on run order, we should fix that and -# remove this method call. -require 'active_support/test_case' -ActiveSupport::TestCase.test_order = :sorted diff --git a/activerecord/Rakefile b/activerecord/Rakefile index 976b559da9..f1facac21b 100644 --- a/activerecord/Rakefile +++ b/activerecord/Rakefile @@ -51,7 +51,7 @@ end t.libs << 'test' t.test_files = (Dir.glob( "test/cases/**/*_test.rb" ).reject { |x| x =~ /\/adapters\// - } + Dir.glob("test/cases/adapters/#{adapter_short}/**/*_test.rb")).sort + } + Dir.glob("test/cases/adapters/#{adapter_short}/**/*_test.rb")) t.warning = true t.verbose = true diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb index e11c9490b7..685c3a5f17 100644 --- a/activerecord/lib/active_record/associations/collection_proxy.rb +++ b/activerecord/lib/active_record/associations/collection_proxy.rb @@ -976,6 +976,9 @@ module ActiveRecord # Equivalent to +delete_all+. The difference is that returns +self+, instead # of an array with the deleted objects, so methods can be chained. See # +delete_all+ for more information. + # Note that because +delete_all+ removes records by directly + # running an SQL query into the database, the +updated_at+ column of + # the object is not changed. def clear delete_all self diff --git a/activerecord/lib/active_record/attributes.rb b/activerecord/lib/active_record/attributes.rb index c8979a60d7..50339b6f69 100644 --- a/activerecord/lib/active_record/attributes.rb +++ b/activerecord/lib/active_record/attributes.rb @@ -28,15 +28,18 @@ module ActiveRecord # information about providing custom type objects. # # ==== Options + # # The following options are accepted: # # +default+ The default value to use when no value is provided. If this option # is not passed, the previous default value (if any) will be used. # Otherwise, the default will be +nil+. # - # +array+ (PG only) specifies that the type should be an array (see the examples below). + # +array+ (PG only) specifies that the type should be an array (see the + # examples below). # - # +range+ (PG only) specifies that the type should be a range (see the examples below). + # +range+ (PG only) specifies that the type should be a range (see the + # examples below). # # ==== Examples # @@ -101,12 +104,11 @@ module ActiveRecord # ==== Creating Custom Types # # Users may also define their own custom types, as long as they respond - # to the methods defined on the value type. The method - # +deserialize+ or +cast+ will be called on - # your type object, with raw input from the database or from your - # controllers. See ActiveRecord::Type::Value for the expected API. It is - # recommended that your type objects inherit from an existing type, or - # from ActiveRecord::Type::Value + # to the methods defined on the value type. The method +deserialize+ or + # +cast+ will be called on your type object, with raw input from the + # database or from your controllers. See ActiveRecord::Type::Value for the + # expected API. It is recommended that your type objects inherit from an + # existing type, or from ActiveRecord::Type::Value # # class MoneyType < ActiveRecord::Type::Integer # def cast(value) @@ -150,7 +152,7 @@ module ActiveRecord # end # # # value will be the result of +deserialize+ or - # # +cast+. Assumed to be in instance of +Money+ in + # # +cast+. Assumed to be an instance of +Money+ in # # this case. # def serialize(value) # value_in_bitcoins = @currency_converter.convert_to_bitcoins(value) diff --git a/activerecord/lib/active_record/type/value.rb b/activerecord/lib/active_record/type/value.rb index fc3ef5e83b..6b9d147ecc 100644 --- a/activerecord/lib/active_record/type/value.rb +++ b/activerecord/lib/active_record/type/value.rb @@ -12,7 +12,7 @@ module ActiveRecord def type # :nodoc: end - # Convert a value from database input to the appropriate ruby type. The + # Converts a value from database input to the appropriate ruby type. The # return value of this method will be returned from # ActiveRecord::AttributeMethods::Read#read_attribute. The default # implementation just calls Value#cast. @@ -36,7 +36,7 @@ module ActiveRecord cast_value(value) unless value.nil? end - # Cast a value from the ruby type to a type that the database knows how + # Casts a value from the ruby type to a type that the database knows how # to understand. The returned value from this method should be a # +String+, +Numeric+, +Date+, +Time+, +Symbol+, +true+, +false+, or # +nil+. @@ -44,7 +44,7 @@ module ActiveRecord value end - # Type cast a value for schema dumping. This method is private, as we are + # Type casts a value for schema dumping. This method is private, as we are # hoping to remove it entirely. def type_cast_for_schema(value) # :nodoc: value.inspect diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index 993350ebd6..4306738670 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- require "cases/helper" require 'active_support/concurrency/latch' @@ -1008,54 +1009,61 @@ class BasicsTest < ActiveRecord::TestCase end def test_switching_between_table_name + k = Class.new(Joke) + assert_difference("GoodJoke.count") do - Joke.table_name = "cold_jokes" - Joke.create + k.table_name = "cold_jokes" + k.create - Joke.table_name = "funny_jokes" - Joke.create + k.table_name = "funny_jokes" + k.create end end def test_clear_cash_when_setting_table_name - Joke.table_name = "cold_jokes" - before_columns = Joke.columns - before_seq = Joke.sequence_name + original_table_name = Joke.table_name Joke.table_name = "funny_jokes" + before_columns = Joke.columns + before_seq = Joke.sequence_name + + Joke.table_name = "cold_jokes" after_columns = Joke.columns - after_seq = Joke.sequence_name + after_seq = Joke.sequence_name assert_not_equal before_columns, after_columns assert_not_equal before_seq, after_seq unless before_seq.nil? && after_seq.nil? + ensure + Joke.table_name = original_table_name end def test_dont_clear_sequence_name_when_setting_explicitly - Joke.sequence_name = "black_jokes_seq" - Joke.table_name = "cold_jokes" - before_seq = Joke.sequence_name + k = Class.new(Joke) + k.sequence_name = "black_jokes_seq" + k.table_name = "cold_jokes" + before_seq = k.sequence_name - Joke.table_name = "funny_jokes" - after_seq = Joke.sequence_name + k.table_name = "funny_jokes" + after_seq = k.sequence_name assert_equal before_seq, after_seq unless before_seq.nil? && after_seq.nil? - ensure - Joke.reset_sequence_name end def test_dont_clear_inheritance_column_when_setting_explicitly - Joke.inheritance_column = "my_type" - before_inherit = Joke.inheritance_column + k = Class.new(Joke) + k.inheritance_column = "my_type" + before_inherit = k.inheritance_column - Joke.reset_column_information - after_inherit = Joke.inheritance_column + k.reset_column_information + after_inherit = k.inheritance_column assert_equal before_inherit, after_inherit unless before_inherit.blank? && after_inherit.blank? end def test_set_table_name_symbol_converted_to_string - Joke.table_name = :cold_jokes - assert_equal 'cold_jokes', Joke.table_name + k = Class.new(Joke) + k.table_name = :cold_jokes + assert_equal 'cold_jokes', k.table_name end def test_quoted_table_name_after_set_table_name diff --git a/activerecord/test/cases/enum_test.rb b/activerecord/test/cases/enum_test.rb index 3b7bbcf47a..eea184e530 100644 --- a/activerecord/test/cases/enum_test.rb +++ b/activerecord/test/cases/enum_test.rb @@ -341,4 +341,18 @@ class EnumTest < ActiveRecord::TestCase book2.status = :uploaded assert_equal ['drafted', 'uploaded'], book2.status_change end + + test "declare multiple enums at a time" do + klass = Class.new(ActiveRecord::Base) do + self.table_name = "books" + enum status: [:proposed, :written, :published], + nullable_status: [:single, :married] + end + + book1 = klass.proposed.create! + assert book1.proposed? + + book2 = klass.single.create! + assert book2.single? + end end diff --git a/activerecord/test/cases/helper.rb b/activerecord/test/cases/helper.rb index f2ba28a32f..b118ecc125 100644 --- a/activerecord/test/cases/helper.rb +++ b/activerecord/test/cases/helper.rb @@ -203,8 +203,3 @@ module InTimeZone end require 'mocha/setup' # FIXME: stop using mocha - -# FIXME: we have tests that depend on run order, we should fix that and -# remove this method call. -require 'active_support/test_case' -ActiveSupport::TestCase.test_order = :sorted diff --git a/activerecord/test/cases/mixin_test.rb b/activerecord/test/cases/mixin_test.rb index 7ddb2bfee1..7ebdcac711 100644 --- a/activerecord/test/cases/mixin_test.rb +++ b/activerecord/test/cases/mixin_test.rb @@ -61,8 +61,6 @@ class TouchTest < ActiveRecord::TestCase # Make sure Mixin.record_timestamps gets reset, even if this test fails, # so that other tests do not fail because Mixin.record_timestamps == false - rescue Exception => e - raise e ensure Mixin.record_timestamps = true end diff --git a/activerecord/test/cases/persistence_test.rb b/activerecord/test/cases/persistence_test.rb index 2803ad2de0..7c281a95b7 100644 --- a/activerecord/test/cases/persistence_test.rb +++ b/activerecord/test/cases/persistence_test.rb @@ -366,6 +366,12 @@ class PersistenceTest < ActiveRecord::TestCase end end + def test_update_does_not_run_sql_if_record_has_not_changed + topic = Topic.create(title: 'Another New Topic') + assert_queries(0) { topic.update(title: 'Another New Topic') } + assert_queries(0) { topic.update_attributes(title: 'Another New Topic') } + end + def test_delete topic = Topic.find(1) assert_equal topic, topic.delete, 'topic.delete did not return self' diff --git a/activerecord/test/cases/validations/length_validation_test.rb b/activerecord/test/cases/validations/length_validation_test.rb index 952e1681a7..f95f8f0b8f 100644 --- a/activerecord/test/cases/validations/length_validation_test.rb +++ b/activerecord/test/cases/validations/length_validation_test.rb @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- require "cases/helper" require 'models/owner' require 'models/pet' @@ -5,49 +6,49 @@ require 'models/person' class LengthValidationTest < ActiveRecord::TestCase fixtures :owners - repair_validations(Owner) - def test_validates_size_of_association - repair_validations Owner do - assert_nothing_raised { Owner.validates_size_of :pets, :minimum => 1 } - o = Owner.new('name' => 'nopets') - assert !o.save - assert o.errors[:pets].any? - o.pets.build('name' => 'apet') - assert o.valid? + setup do + @owner = Class.new(Owner) do + def self.name; 'Owner'; end end end + + def test_validates_size_of_association + assert_nothing_raised { @owner.validates_size_of :pets, minimum: 1 } + o = @owner.new('name' => 'nopets') + assert !o.save + assert o.errors[:pets].any? + o.pets.build('name' => 'apet') + assert o.valid? + end + def test_validates_size_of_association_using_within - repair_validations Owner do - assert_nothing_raised { Owner.validates_size_of :pets, :within => 1..2 } - o = Owner.new('name' => 'nopets') - assert !o.save - assert o.errors[:pets].any? + assert_nothing_raised { @owner.validates_size_of :pets, within: 1..2 } + o = @owner.new('name' => 'nopets') + assert !o.save + assert o.errors[:pets].any? - o.pets.build('name' => 'apet') - assert o.valid? + o.pets.build('name' => 'apet') + assert o.valid? - 2.times { o.pets.build('name' => 'apet') } - assert !o.save - assert o.errors[:pets].any? - end + 2.times { o.pets.build('name' => 'apet') } + assert !o.save + assert o.errors[:pets].any? end def test_validates_size_of_association_utf8 - repair_validations Owner do - Owner.validates_size_of :pets, :minimum => 1 - o = Owner.new('name' => 'あいうえおかきくけこ') - assert !o.save - assert o.errors[:pets].any? - o.pets.build('name' => 'あいうえおかきくけこ') - assert o.valid? - end + @owner.validates_size_of :pets, minimum: 1 + o = @owner.new('name' => 'あいうえおかきくけこ') + assert !o.save + assert o.errors[:pets].any? + o.pets.build('name' => 'あいうえおかきくけこ') + assert o.valid? end def test_validates_size_of_respects_records_marked_for_destruction - Owner.validates_size_of :pets, minimum: 1 - owner = Owner.new + @owner.validates_size_of :pets, minimum: 1 + owner = @owner.new assert_not owner.save assert owner.errors[:pets].any? pet = owner.pets.build @@ -62,8 +63,8 @@ class LengthValidationTest < ActiveRecord::TestCase end def test_does_not_validate_length_of_if_parent_record_is_validate_false - Owner.validates_length_of :name, minimum: 1 - owner = Owner.new + @owner.validates_length_of :name, minimum: 1 + owner = @owner.new owner.save!(validate: false) assert owner.persisted? diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb index f32bb8a0cc..37f9494272 100644 --- a/activesupport/lib/active_support/callbacks.rb +++ b/activesupport/lib/active_support/callbacks.rb @@ -490,17 +490,17 @@ module ActiveSupport end def around(&around) - CallbackSequence.new do |*args| - around.call(*args) { - self.call(*args) + CallbackSequence.new do |arg| + around.call(arg) { + self.call(arg) } end end - def call(*args) - @before.each { |b| b.call(*args) } - value = @call.call(*args) - @after.each { |a| a.call(*args) } + def call(arg) + @before.each { |b| b.call(arg) } + value = @call.call(arg) + @after.each { |a| a.call(arg) } value end end diff --git a/activesupport/lib/active_support/core_ext/module/remove_method.rb b/activesupport/lib/active_support/core_ext/module/remove_method.rb index 8a2569a7d0..52632d2c6b 100644 --- a/activesupport/lib/active_support/core_ext/module/remove_method.rb +++ b/activesupport/lib/active_support/core_ext/module/remove_method.rb @@ -1,13 +1,13 @@ class Module - # Remove the named method, if it exists. + # Removes the named method, if it exists. def remove_possible_method(method) if method_defined?(method) || private_method_defined?(method) undef_method(method) end end - # Replace the existing method definition, if there is one, with the contents - # of the block. + # Replaces the existing method definition, if there is one, with the passed + # block as its body. def redefine_method(method, &block) remove_possible_method(method) define_method(method, &block) diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb index 13610ba19f..6f1b653639 100644 --- a/activesupport/lib/active_support/core_ext/time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/time/calculations.rb @@ -48,7 +48,11 @@ class Time alias_method :at, :at_with_coercion end - # Seconds since midnight: Time.now.seconds_since_midnight + # Returns the number of seconds since 00:00:00. + # + # Time.new(2012, 8, 29, 0, 0, 0).seconds_since_midnight # => 0 + # Time.new(2012, 8, 29, 12, 34, 56).seconds_since_midnight # => 45296 + # Time.new(2012, 8, 29, 23, 59, 59).seconds_since_midnight # => 86399 def seconds_since_midnight to_i - change(:hour => 0).to_i + (usec / 1.0e+6) end diff --git a/activesupport/lib/active_support/number_helper/number_to_rounded_converter.rb b/activesupport/lib/active_support/number_helper/number_to_rounded_converter.rb index df316a08e6..981c562551 100644 --- a/activesupport/lib/active_support/number_helper/number_to_rounded_converter.rb +++ b/activesupport/lib/active_support/number_helper/number_to_rounded_converter.rb @@ -23,7 +23,7 @@ module ActiveSupport precision = 0 if precision < 0 # don't let it be negative else rounded_number = number.round(precision) - rounded_number = rounded_number.to_i if precision == 0 + rounded_number = rounded_number.to_i if precision == 0 && rounded_number.finite? rounded_number = rounded_number.abs if rounded_number.zero? # prevent showing negative zeros end diff --git a/activesupport/lib/active_support/railtie.rb b/activesupport/lib/active_support/railtie.rb index 6eba24b569..ef22433491 100644 --- a/activesupport/lib/active_support/railtie.rb +++ b/activesupport/lib/active_support/railtie.rb @@ -23,6 +23,11 @@ module ActiveSupport # Sets the default value for Time.zone # If assigned value cannot be matched to a TimeZone, an exception will be raised. initializer "active_support.initialize_time_zone" do |app| + begin + TZInfo::DataSource.get + rescue TZInfo::DataSourceNotFound => e + raise e.exception "tzinfo-data is not present. Please add gem 'tzinfo-data' to your Gemfile and run bundle install" + end require 'active_support/core_ext/time/zones' zone_default = Time.find_zone!(app.config.time_zone) diff --git a/activesupport/test/abstract_unit.rb b/activesupport/test/abstract_unit.rb index f65ec962f9..7ffcae6007 100644 --- a/activesupport/test/abstract_unit.rb +++ b/activesupport/test/abstract_unit.rb @@ -38,8 +38,3 @@ def jruby_skip(message = '') end require 'mocha/setup' # FIXME: stop using mocha - -# FIXME: we have tests that depend on run order, we should fix that and -# remove this method call. -require 'active_support/test_case' -ActiveSupport::TestCase.test_order = :sorted diff --git a/activesupport/test/number_helper_test.rb b/activesupport/test/number_helper_test.rb index 23996ef381..83efbffdfb 100644 --- a/activesupport/test/number_helper_test.rb +++ b/activesupport/test/number_helper_test.rb @@ -83,6 +83,10 @@ module ActiveSupport assert_equal("98a%", number_helper.number_to_percentage("98a")) assert_equal("NaN%", number_helper.number_to_percentage(Float::NAN)) assert_equal("Inf%", number_helper.number_to_percentage(Float::INFINITY)) + assert_equal("NaN%", number_helper.number_to_percentage(Float::NAN, precision: 0)) + assert_equal("Inf%", number_helper.number_to_percentage(Float::INFINITY, precision: 0)) + assert_equal("NaN%", number_helper.number_to_percentage(Float::NAN, precision: 1)) + assert_equal("Inf%", number_helper.number_to_percentage(Float::INFINITY, precision: 1)) assert_equal("1000%", number_helper.number_to_percentage(1000, precision: nil)) assert_equal("1000%", number_helper.number_to_percentage(1000, precision: nil)) assert_equal("1000.1%", number_helper.number_to_percentage(1000.1, precision: nil)) diff --git a/guides/source/autoloading_and_reloading_constants.md b/guides/source/autoloading_and_reloading_constants.md index 9e78eebf82..c6149abcba 100644 --- a/guides/source/autoloading_and_reloading_constants.md +++ b/guides/source/autoloading_and_reloading_constants.md @@ -465,7 +465,10 @@ by adding this to `config/application.rb`: ```ruby config.autoload_paths << "#{Rails.root}/lib" ``` -`config.autoload_paths` is accessible from environment-specific configuration files, but any changes made to it outside `config/application.rb` don't have an effect. + +`config.autoload_paths` is accessible from environment-specific configuration +files, but any changes made to it outside `config/application.rb` don't have any +effect. The value of `autoload_paths` can be inspected. In a just generated application it is (edited): diff --git a/guides/source/configuring.md b/guides/source/configuring.md index e0b09be782..4ebd634cd6 100644 --- a/guides/source/configuring.md +++ b/guides/source/configuring.md @@ -110,7 +110,9 @@ numbers. New applications filter out passwords by adding the following `config.f * `config.log_formatter` defines the formatter of the Rails logger. This option defaults to an instance of `ActiveSupport::Logger::SimpleFormatter` for all modes except production, where it defaults to `Logger::Formatter`. -* `config.log_level` defines the verbosity of the Rails logger. This option defaults to `:debug` for all environments. The available log levels are: :debug, :info, :warn, :error, :fatal, and :unknown. +* `config.log_level` defines the verbosity of the Rails logger. This option +defaults to `:debug` for all environments. The available log levels are: `:debug`, +`:info`, `:warn`, `:error`, `:fatal`, and `:unknown`. * `config.log_tags` accepts a list of methods that the `request` object responds to. This makes it easy to tag log lines with debug information like subdomain and request id - both very helpful in debugging multi-user production applications. diff --git a/guides/source/layouts_and_rendering.md b/guides/source/layouts_and_rendering.md index 54db23bb32..c57fa358d6 100644 --- a/guides/source/layouts_and_rendering.md +++ b/guides/source/layouts_and_rendering.md @@ -428,12 +428,13 @@ Rails understands both numeric status codes and the corresponding symbols shown | | 510 | :not_extended | | | 511 | :network_authentication_required | -NOTE: If you try to render content along with a non-content status code +NOTE: If you try to render content along with a non-content status code (100-199, 204, 205 or 304), it will be dropped from the response. ##### The `:formats` Option -Rails uses the format specified in request (or `:html` by default). You can change this adding the `:formats` option with a symbol or an array: +Rails uses the format specified in the request (or `:html` by default). You can +change this passing the `:formats` option with a symbol or an array: ```ruby render formats: :xml diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index b11815e013..ff6c905f3e 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -427,9 +427,9 @@ module Rails # Return an array of railties respecting the order they're loaded # and the order specified by the +railties_order+ config. # - # While when running initializers we need engines in reverse - # order here when copying migrations from railties we need them in the same - # order as given by +railties_order+. + # While running initializers we need engines in reverse order here when + # copying migrations from railties ; we need them in the order given by + # +railties_order+. def migration_railties # :nodoc: ordered_railties.flatten - [self] end diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index fd37fd0457..83cee28fa3 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -528,7 +528,7 @@ module Rails # Defines the routes for this engine. If a block is given to # routes, it is appended to the engine. def routes - @routes ||= ActionDispatch::Routing::RouteSet.new + @routes ||= ActionDispatch::Routing::RouteSet.new_with_config(config) @routes.append(&Proc.new) if block_given? @routes end diff --git a/railties/lib/rails/ruby_version_check.rb b/railties/lib/rails/ruby_version_check.rb index e2a199ec4d..9131c51e91 100644 --- a/railties/lib/rails/ruby_version_check.rb +++ b/railties/lib/rails/ruby_version_check.rb @@ -1,13 +1,13 @@ -if RUBY_VERSION < '2.2.0' && RUBY_ENGINE == 'ruby' +if RUBY_VERSION < '2.2.1' && RUBY_ENGINE == 'ruby' desc = defined?(RUBY_DESCRIPTION) ? RUBY_DESCRIPTION : "ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE})" abort <<-end_message - Rails 5 requires to run on Ruby 2.2.0 or newer. + Rails 5 requires to run on Ruby 2.2.1 or newer. You're running #{desc} - Please upgrade to Ruby 2.2.0 or newer to continue. + Please upgrade to Ruby 2.2.1 or newer to continue. end_message end diff --git a/railties/test/abstract_unit.rb b/railties/test/abstract_unit.rb index ab8883e135..794d180e5d 100644 --- a/railties/test/abstract_unit.rb +++ b/railties/test/abstract_unit.rb @@ -30,9 +30,4 @@ end class ActiveSupport::TestCase include ActiveSupport::Testing::Stream - - # FIXME: we have tests that depend on run order, we should fix that and - # remove this method call. - self.test_order = :sorted - end diff --git a/railties/test/application/url_generation_test.rb b/railties/test/application/url_generation_test.rb index ef16ab56ed..894e18cb39 100644 --- a/railties/test/application/url_generation_test.rb +++ b/railties/test/application/url_generation_test.rb @@ -42,5 +42,18 @@ module ApplicationTests get "/" assert_equal "/", last_response.body end + + def test_routes_know_the_relative_root + boot_rails + require "rails" + require "action_controller/railtie" + require "action_view/railtie" + + relative_url = '/hello' + ENV["RAILS_RELATIVE_URL_ROOT"] = relative_url + app = Class.new(Rails::Application) + assert_equal relative_url, app.routes.relative_url_root + ENV["RAILS_RELATIVE_URL_ROOT"] = nil + end end end |