aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/lib/action_controller/metal/conditional_get.rb1
-rw-r--r--actionview/test/template/date_helper_i18n_test.rb1
-rw-r--r--actionview/test/template/date_helper_test.rb1
-rw-r--r--activejob/test/jobs/timezone_dependent_job.rb1
-rw-r--r--activemodel/CHANGELOG.md6
-rw-r--r--activemodel/lib/active_model/dirty.rb8
-rw-r--r--activerecord/test/cases/calculations_test.rb84
-rw-r--r--activerecord/test/cases/dirty_test.rb6
-rw-r--r--activesupport/lib/active_support/core_ext/hash/conversions.rb1
-rw-r--r--activesupport/lib/active_support/core_ext/marshal.rb2
-rw-r--r--activesupport/lib/active_support/inflector/methods.rb1
-rw-r--r--activesupport/test/core_ext/hash_ext_test.rb1
-rw-r--r--activesupport/test/core_ext/object/acts_like_test.rb5
-rw-r--r--activesupport/test/core_ext/object/deep_dup_test.rb2
-rw-r--r--activesupport/test/core_ext/object/instance_variables_test.rb2
-rw-r--r--activesupport/test/core_ext/object/json_gem_encoding_test.rb2
-rw-r--r--activesupport/test/core_ext/object/try_test.rb2
-rw-r--r--activesupport/test/file_update_checker_shared_tests.rb394
-rw-r--r--activesupport/test/xml_mini_test.rb1
-rw-r--r--railties/lib/rails/generators.rb5
20 files changed, 319 insertions, 207 deletions
diff --git a/actionpack/lib/action_controller/metal/conditional_get.rb b/actionpack/lib/action_controller/metal/conditional_get.rb
index c9bb84406a..967bda38f2 100644
--- a/actionpack/lib/action_controller/metal/conditional_get.rb
+++ b/actionpack/lib/action_controller/metal/conditional_get.rb
@@ -1,6 +1,7 @@
# frozen_string_literal: true
require "active_support/core_ext/object/try"
+require "active_support/core_ext/integer/time"
module ActionController
module ConditionalGet
diff --git a/actionview/test/template/date_helper_i18n_test.rb b/actionview/test/template/date_helper_i18n_test.rb
index 60303b4c91..f100a011a8 100644
--- a/actionview/test/template/date_helper_i18n_test.rb
+++ b/actionview/test/template/date_helper_i18n_test.rb
@@ -1,6 +1,7 @@
# frozen_string_literal: true
require "abstract_unit"
+require "active_support/core_ext/integer/time"
class DateHelperDistanceOfTimeInWordsI18nTests < ActiveSupport::TestCase
include ActionView::Helpers::DateHelper
diff --git a/actionview/test/template/date_helper_test.rb b/actionview/test/template/date_helper_test.rb
index 0a294ec674..ca904a7b1e 100644
--- a/actionview/test/template/date_helper_test.rb
+++ b/actionview/test/template/date_helper_test.rb
@@ -1,6 +1,7 @@
# frozen_string_literal: true
require "abstract_unit"
+require "active_support/core_ext/integer/time"
class DateHelperTest < ActionView::TestCase
tests ActionView::Helpers::DateHelper
diff --git a/activejob/test/jobs/timezone_dependent_job.rb b/activejob/test/jobs/timezone_dependent_job.rb
index f63ff95b95..358c3aa859 100644
--- a/activejob/test/jobs/timezone_dependent_job.rb
+++ b/activejob/test/jobs/timezone_dependent_job.rb
@@ -1,6 +1,7 @@
# frozen_string_literal: true
require_relative "../support/job_buffer"
+require "active_support/time"
class TimezoneDependentJob < ActiveJob::Base
def perform(now)
diff --git a/activemodel/CHANGELOG.md b/activemodel/CHANGELOG.md
index 9d77564c61..c301f4766d 100644
--- a/activemodel/CHANGELOG.md
+++ b/activemodel/CHANGELOG.md
@@ -1,3 +1,9 @@
+* Add *_previously_was attribute methods when dirty tracking. Example:
+ pirate.update(catchphrase: "Ahoy!")
+ pirate.previous_changes["catchphrase"] # => ["Thar She Blows!", "Ahoy!"]
+ pirate.catchphrase_previously_was # => "Thar She Blows!"
+
+ *DHH*
Please check [6-0-stable](https://github.com/rails/rails/blob/6-0-stable/activemodel/CHANGELOG.md) for previous changes.
diff --git a/activemodel/lib/active_model/dirty.rb b/activemodel/lib/active_model/dirty.rb
index aaefe00c83..245616502d 100644
--- a/activemodel/lib/active_model/dirty.rb
+++ b/activemodel/lib/active_model/dirty.rb
@@ -84,6 +84,7 @@ module ActiveModel
# person.previous_changes # => {"name" => [nil, "Bill"]}
# person.name_previously_changed? # => true
# person.name_previous_change # => [nil, "Bill"]
+ # person.name_previously_was # => nil
# person.reload!
# person.previous_changes # => {}
#
@@ -122,7 +123,7 @@ module ActiveModel
included do
attribute_method_suffix "_changed?", "_change", "_will_change!", "_was"
- attribute_method_suffix "_previously_changed?", "_previous_change"
+ attribute_method_suffix "_previously_changed?", "_previous_change", "_previously_was"
attribute_method_affix prefix: "restore_", suffix: "!"
end
@@ -180,6 +181,11 @@ module ActiveModel
mutations_before_last_save.changed?(attr_name.to_s)
end
+ # Dispatch target for <tt>*_previously_was</tt> attribute methods.
+ def attribute_previously_was(attr_name) # :nodoc:
+ mutations_before_last_save.original_value(attr_name.to_s)
+ end
+
# Restore all previous data of the provided attributes.
def restore_attributes(attr_names = changed)
attr_names.each { |attr_name| restore_attribute!(attr_name) }
diff --git a/activerecord/test/cases/calculations_test.rb b/activerecord/test/cases/calculations_test.rb
index dbd1d03c4c..abce4565a4 100644
--- a/activerecord/test/cases/calculations_test.rb
+++ b/activerecord/test/cases/calculations_test.rb
@@ -952,6 +952,90 @@ class CalculationsTest < ActiveRecord::TestCase
assert_equal({ "proposed" => 2, "published" => 2 }, Book.group(:status).count)
end
+ def test_select_avg_with_group_by_as_virtual_attribute_with_sql
+ rails_core = companies(:rails_core)
+
+ sql = <<~SQL
+ SELECT firm_id, AVG(credit_limit) AS avg_credit_limit
+ FROM accounts
+ WHERE firm_id = ?
+ GROUP BY firm_id
+ LIMIT 1
+ SQL
+
+ account = Account.find_by_sql([sql, rails_core]).first
+
+ # id was not selected, so it should be nil
+ # (cannot select id because it wasn't used in the GROUP BY clause)
+ assert_nil account.id
+
+ # firm_id was explicitly selected, so it should be present
+ assert_equal(rails_core, account.firm)
+
+ # avg_credit_limit should be present as a virtual attribute
+ assert_equal(52.5, account.avg_credit_limit)
+ end
+
+ def test_select_avg_with_group_by_as_virtual_attribute_with_ar
+ rails_core = companies(:rails_core)
+
+ account = Account
+ .select(:firm_id, "AVG(credit_limit) AS avg_credit_limit")
+ .where(firm: rails_core)
+ .group(:firm_id)
+ .take!
+
+ # id was not selected, so it should be nil
+ # (cannot select id because it wasn't used in the GROUP BY clause)
+ assert_nil account.id
+
+ # firm_id was explicitly selected, so it should be present
+ assert_equal(rails_core, account.firm)
+
+ # avg_credit_limit should be present as a virtual attribute
+ assert_equal(52.5, account.avg_credit_limit)
+ end
+
+ def test_select_avg_with_joins_and_group_by_as_virtual_attribute_with_sql
+ rails_core = companies(:rails_core)
+
+ sql = <<~SQL
+ SELECT companies.*, AVG(accounts.credit_limit) AS avg_credit_limit
+ FROM companies
+ INNER JOIN accounts ON companies.id = accounts.firm_id
+ WHERE companies.id = ?
+ GROUP BY companies.id
+ LIMIT 1
+ SQL
+
+ firm = DependentFirm.find_by_sql([sql, rails_core]).first
+
+ # all the DependentFirm attributes should be present
+ assert_equal rails_core, firm
+ assert_equal rails_core.name, firm.name
+
+ # avg_credit_limit should be present as a virtual attribute
+ assert_equal(52.5, firm.avg_credit_limit)
+ end
+
+ def test_select_avg_with_joins_and_group_by_as_virtual_attribute_with_ar
+ rails_core = companies(:rails_core)
+
+ firm = DependentFirm
+ .select("companies.*", "AVG(accounts.credit_limit) AS avg_credit_limit")
+ .where(id: rails_core)
+ .joins(:account)
+ .group(:id)
+ .take!
+
+ # all the DependentFirm attributes should be present
+ assert_equal rails_core, firm
+ assert_equal rails_core.name, firm.name
+
+ # avg_credit_limit should be present as a virtual attribute
+ assert_equal(52.5, firm.avg_credit_limit)
+ end
+
def test_count_with_block_and_column_name_raises_an_error
assert_raises(ArgumentError) do
Account.count(:firm_id) { true }
diff --git a/activerecord/test/cases/dirty_test.rb b/activerecord/test/cases/dirty_test.rb
index a2a501a794..6aca7d93ad 100644
--- a/activerecord/test/cases/dirty_test.rb
+++ b/activerecord/test/cases/dirty_test.rb
@@ -491,6 +491,7 @@ class DirtyTest < ActiveRecord::TestCase
assert_equal 4, pirate.previous_changes.size
assert_equal [nil, "arrr"], pirate.previous_changes["catchphrase"]
+ assert_equal nil, pirate.catchphrase_previously_was
assert_equal [nil, pirate.id], pirate.previous_changes["id"]
assert_nil pirate.previous_changes["updated_on"][0]
assert_not_nil pirate.previous_changes["updated_on"][1]
@@ -507,6 +508,7 @@ class DirtyTest < ActiveRecord::TestCase
assert_equal 4, pirate.previous_changes.size
assert_equal [nil, "arrr"], pirate.previous_changes["catchphrase"]
+ assert_equal nil, pirate.catchphrase_previously_was
assert_equal [nil, pirate.id], pirate.previous_changes["id"]
assert_includes pirate.previous_changes, "updated_on"
assert_includes pirate.previous_changes, "created_on"
@@ -525,6 +527,7 @@ class DirtyTest < ActiveRecord::TestCase
assert_equal 2, pirate.previous_changes.size
assert_equal ["arrr", "Me Maties!"], pirate.previous_changes["catchphrase"]
+ assert_equal "arrr", pirate.catchphrase_previously_was
assert_not_nil pirate.previous_changes["updated_on"][0]
assert_not_nil pirate.previous_changes["updated_on"][1]
assert_not pirate.previous_changes.key?("parrot_id")
@@ -539,6 +542,7 @@ class DirtyTest < ActiveRecord::TestCase
assert_equal 2, pirate.previous_changes.size
assert_equal ["Me Maties!", "Thar She Blows!"], pirate.previous_changes["catchphrase"]
+ assert_equal "Me Maties!", pirate.catchphrase_previously_was
assert_not_nil pirate.previous_changes["updated_on"][0]
assert_not_nil pirate.previous_changes["updated_on"][1]
assert_not pirate.previous_changes.key?("parrot_id")
@@ -551,6 +555,7 @@ class DirtyTest < ActiveRecord::TestCase
assert_equal 2, pirate.previous_changes.size
assert_equal ["Thar She Blows!", "Ahoy!"], pirate.previous_changes["catchphrase"]
+ assert_equal "Thar She Blows!", pirate.catchphrase_previously_was
assert_not_nil pirate.previous_changes["updated_on"][0]
assert_not_nil pirate.previous_changes["updated_on"][1]
assert_not pirate.previous_changes.key?("parrot_id")
@@ -563,6 +568,7 @@ class DirtyTest < ActiveRecord::TestCase
assert_equal 2, pirate.previous_changes.size
assert_equal ["Ahoy!", "Ninjas suck!"], pirate.previous_changes["catchphrase"]
+ assert_equal "Ahoy!", pirate.catchphrase_previously_was
assert_not_nil pirate.previous_changes["updated_on"][0]
assert_not_nil pirate.previous_changes["updated_on"][1]
assert_not pirate.previous_changes.key?("parrot_id")
diff --git a/activesupport/lib/active_support/core_ext/hash/conversions.rb b/activesupport/lib/active_support/core_ext/hash/conversions.rb
index dd021410a9..cc42647879 100644
--- a/activesupport/lib/active_support/core_ext/hash/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/hash/conversions.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require "active_support/xml_mini"
-require "active_support/time"
require "active_support/core_ext/object/blank"
require "active_support/core_ext/object/to_param"
require "active_support/core_ext/object/to_query"
diff --git a/activesupport/lib/active_support/core_ext/marshal.rb b/activesupport/lib/active_support/core_ext/marshal.rb
index 0c72cd7b47..5ff0e34d82 100644
--- a/activesupport/lib/active_support/core_ext/marshal.rb
+++ b/activesupport/lib/active_support/core_ext/marshal.rb
@@ -1,5 +1,7 @@
# frozen_string_literal: true
+require "active_support/core_ext/string/inflections"
+
module ActiveSupport
module MarshalWithAutoloading # :nodoc:
def load(source, proc = nil)
diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb
index 94d1115ccf..33a17a7741 100644
--- a/activesupport/lib/active_support/inflector/methods.rb
+++ b/activesupport/lib/active_support/inflector/methods.rb
@@ -1,6 +1,7 @@
# frozen_string_literal: true
require "active_support/inflections"
+require "active_support/core_ext/object/blank"
module ActiveSupport
# The Inflector transforms words from singular to plural, class names to table
diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb
index 8572d56722..59d2d6f530 100644
--- a/activesupport/test/core_ext/hash_ext_test.rb
+++ b/activesupport/test/core_ext/hash_ext_test.rb
@@ -6,6 +6,7 @@ require "bigdecimal"
require "active_support/core_ext/string/access"
require "active_support/ordered_hash"
require "active_support/core_ext/object/conversions"
+require "active_support/core_ext/date/conversions"
require "active_support/core_ext/object/deep_dup"
require "active_support/inflections"
diff --git a/activesupport/test/core_ext/object/acts_like_test.rb b/activesupport/test/core_ext/object/acts_like_test.rb
index 31241caf0a..8aa9eb036a 100644
--- a/activesupport/test/core_ext/object/acts_like_test.rb
+++ b/activesupport/test/core_ext/object/acts_like_test.rb
@@ -1,7 +1,10 @@
# frozen_string_literal: true
require "abstract_unit"
-require "active_support/core_ext/object"
+require "active_support/core_ext/date/acts_like"
+require "active_support/core_ext/time/acts_like"
+require "active_support/core_ext/date_time/acts_like"
+require "active_support/core_ext/object/acts_like"
class ObjectTests < ActiveSupport::TestCase
class DuckTime
diff --git a/activesupport/test/core_ext/object/deep_dup_test.rb b/activesupport/test/core_ext/object/deep_dup_test.rb
index 1fb26ebac7..8e5e28c513 100644
--- a/activesupport/test/core_ext/object/deep_dup_test.rb
+++ b/activesupport/test/core_ext/object/deep_dup_test.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
require "abstract_unit"
-require "active_support/core_ext/object"
+require "active_support/core_ext/object/deep_dup"
class DeepDupTest < ActiveSupport::TestCase
def test_array_deep_dup
diff --git a/activesupport/test/core_ext/object/instance_variables_test.rb b/activesupport/test/core_ext/object/instance_variables_test.rb
index 9052d209a3..dd710e9349 100644
--- a/activesupport/test/core_ext/object/instance_variables_test.rb
+++ b/activesupport/test/core_ext/object/instance_variables_test.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
require "abstract_unit"
-require "active_support/core_ext/object"
+require "active_support/core_ext/object/instance_variables"
class ObjectInstanceVariableTest < ActiveSupport::TestCase
def setup
diff --git a/activesupport/test/core_ext/object/json_gem_encoding_test.rb b/activesupport/test/core_ext/object/json_gem_encoding_test.rb
index 4cdb6ed09f..eef02f7458 100644
--- a/activesupport/test/core_ext/object/json_gem_encoding_test.rb
+++ b/activesupport/test/core_ext/object/json_gem_encoding_test.rb
@@ -22,7 +22,7 @@ class JsonGemEncodingTest < ActiveSupport::TestCase
JSONTest::EncodingTestCases.constants.each_with_index do |name|
JSONTest::EncodingTestCases.const_get(name).each_with_index do |(subject, _), i|
- test("#{name[0..-6].underscore} #{i}") do
+ test("#{name[0..-6]} #{i}") do
assert_same_with_or_without_active_support(subject)
end
end
diff --git a/activesupport/test/core_ext/object/try_test.rb b/activesupport/test/core_ext/object/try_test.rb
index a838334034..d501b5edce 100644
--- a/activesupport/test/core_ext/object/try_test.rb
+++ b/activesupport/test/core_ext/object/try_test.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
require "abstract_unit"
-require "active_support/core_ext/object"
+require "active_support/core_ext/object/try"
class ObjectTryTest < ActiveSupport::TestCase
def setup
diff --git a/activesupport/test/file_update_checker_shared_tests.rb b/activesupport/test/file_update_checker_shared_tests.rb
index 84d89fa0a7..bd056a1576 100644
--- a/activesupport/test/file_update_checker_shared_tests.rb
+++ b/activesupport/test/file_update_checker_shared_tests.rb
@@ -3,294 +3,298 @@
require "fileutils"
module FileUpdateCheckerSharedTests
- extend ActiveSupport::Testing::Declarative
- include FileUtils
+ def self.included(kls)
+ kls.class_eval do
+ extend ActiveSupport::Testing::Declarative
+ include FileUtils
- def tmpdir
- @tmpdir
- end
+ def tmpdir
+ @tmpdir
+ end
- def tmpfile(name)
- File.join(tmpdir, name)
- end
+ def tmpfile(name)
+ File.join(tmpdir, name)
+ end
- def tmpfiles
- @tmpfiles ||= %w(foo.rb bar.rb baz.rb).map { |f| tmpfile(f) }
- end
+ def tmpfiles
+ @tmpfiles ||= %w(foo.rb bar.rb baz.rb).map { |f| tmpfile(f) }
+ end
- def run(*args)
- capture_exceptions do
- Dir.mktmpdir(nil, __dir__) { |dir| @tmpdir = dir; super }
- end
- end
+ def run(*args)
+ capture_exceptions do
+ Dir.mktmpdir(nil, __dir__) { |dir| @tmpdir = dir; super }
+ end
+ end
- test "should not execute the block if no paths are given" do
- silence_warnings { require "listen" }
- i = 0
+ test "should not execute the block if no paths are given" do
+ silence_warnings { require "listen" }
+ i = 0
- checker = new_checker { i += 1 }
+ checker = new_checker { i += 1 }
- assert_not checker.execute_if_updated
- assert_equal 0, i
- end
+ assert_not checker.execute_if_updated
+ assert_equal 0, i
+ end
- test "should not execute the block if no files change" do
- i = 0
+ test "should not execute the block if no files change" do
+ i = 0
- FileUtils.touch(tmpfiles)
+ FileUtils.touch(tmpfiles)
- checker = new_checker(tmpfiles) { i += 1 }
+ checker = new_checker(tmpfiles) { i += 1 }
- assert_not checker.execute_if_updated
- assert_equal 0, i
- end
+ assert_not checker.execute_if_updated
+ assert_equal 0, i
+ end
- test "should execute the block once when files are created" do
- i = 0
+ test "should execute the block once when files are created" do
+ i = 0
- checker = new_checker(tmpfiles) { i += 1 }
+ checker = new_checker(tmpfiles) { i += 1 }
- touch(tmpfiles)
- wait
+ touch(tmpfiles)
+ wait
- assert checker.execute_if_updated
- assert_equal 1, i
- end
+ assert checker.execute_if_updated
+ assert_equal 1, i
+ end
- test "should execute the block once when files are modified" do
- i = 0
+ test "should execute the block once when files are modified" do
+ i = 0
- FileUtils.touch(tmpfiles)
+ FileUtils.touch(tmpfiles)
- checker = new_checker(tmpfiles) { i += 1 }
+ checker = new_checker(tmpfiles) { i += 1 }
- touch(tmpfiles)
- wait
+ touch(tmpfiles)
+ wait
- assert checker.execute_if_updated
- assert_equal 1, i
- end
+ assert checker.execute_if_updated
+ assert_equal 1, i
+ end
- test "should execute the block once when files are deleted" do
- i = 0
+ test "should execute the block once when files are deleted" do
+ i = 0
- FileUtils.touch(tmpfiles)
+ FileUtils.touch(tmpfiles)
- checker = new_checker(tmpfiles) { i += 1 }
+ checker = new_checker(tmpfiles) { i += 1 }
- rm_f(tmpfiles)
- wait
+ rm_f(tmpfiles)
+ wait
- assert checker.execute_if_updated
- assert_equal 1, i
- end
+ assert checker.execute_if_updated
+ assert_equal 1, i
+ end
- test "updated should become true when watched files are created" do
- i = 0
+ test "updated should become true when watched files are created" do
+ i = 0
- checker = new_checker(tmpfiles) { i += 1 }
- assert_not_predicate checker, :updated?
+ checker = new_checker(tmpfiles) { i += 1 }
+ assert_not_predicate checker, :updated?
- touch(tmpfiles)
- wait
+ touch(tmpfiles)
+ wait
- assert_predicate checker, :updated?
- end
+ assert_predicate checker, :updated?
+ end
- test "updated should become true when watched files are modified" do
- i = 0
+ test "updated should become true when watched files are modified" do
+ i = 0
- FileUtils.touch(tmpfiles)
+ FileUtils.touch(tmpfiles)
- checker = new_checker(tmpfiles) { i += 1 }
- assert_not_predicate checker, :updated?
+ checker = new_checker(tmpfiles) { i += 1 }
+ assert_not_predicate checker, :updated?
- touch(tmpfiles)
- wait
+ touch(tmpfiles)
+ wait
- assert_predicate checker, :updated?
- end
+ assert_predicate checker, :updated?
+ end
- test "updated should become true when watched files are deleted" do
- i = 0
+ test "updated should become true when watched files are deleted" do
+ i = 0
- FileUtils.touch(tmpfiles)
+ FileUtils.touch(tmpfiles)
- checker = new_checker(tmpfiles) { i += 1 }
- assert_not_predicate checker, :updated?
+ checker = new_checker(tmpfiles) { i += 1 }
+ assert_not_predicate checker, :updated?
- rm_f(tmpfiles)
- wait
+ rm_f(tmpfiles)
+ wait
- assert_predicate checker, :updated?
- end
+ assert_predicate checker, :updated?
+ end
- test "should be robust to handle files with wrong modified time" do
- i = 0
+ test "should be robust to handle files with wrong modified time" do
+ i = 0
- FileUtils.touch(tmpfiles)
+ FileUtils.touch(tmpfiles)
- now = Time.now
- time = Time.mktime(now.year + 1, now.month, now.day) # wrong mtime from the future
- File.utime(time, time, tmpfiles[0])
+ now = Time.now
+ time = Time.mktime(now.year + 1, now.month, now.day) # wrong mtime from the future
+ File.utime(time, time, tmpfiles[0])
- checker = new_checker(tmpfiles) { i += 1 }
+ checker = new_checker(tmpfiles) { i += 1 }
- touch(tmpfiles[1..-1])
- wait
+ touch(tmpfiles[1..-1])
+ wait
- assert checker.execute_if_updated
- assert_equal 1, i
- end
+ assert checker.execute_if_updated
+ assert_equal 1, i
+ end
- test "should return max_time for files with mtime = Time.at(0)" do
- i = 0
+ test "should return max_time for files with mtime = Time.at(0)" do
+ i = 0
- FileUtils.touch(tmpfiles)
+ FileUtils.touch(tmpfiles)
- time = Time.at(0) # wrong mtime from the future
- File.utime(time, time, tmpfiles[0])
+ time = Time.at(0) # wrong mtime from the future
+ File.utime(time, time, tmpfiles[0])
- checker = new_checker(tmpfiles) { i += 1 }
+ checker = new_checker(tmpfiles) { i += 1 }
- touch(tmpfiles[1..-1])
- wait
+ touch(tmpfiles[1..-1])
+ wait
- assert checker.execute_if_updated
- assert_equal 1, i
- end
+ assert checker.execute_if_updated
+ assert_equal 1, i
+ end
- test "should cache updated result until execute" do
- i = 0
+ test "should cache updated result until execute" do
+ i = 0
- checker = new_checker(tmpfiles) { i += 1 }
- assert_not_predicate checker, :updated?
+ checker = new_checker(tmpfiles) { i += 1 }
+ assert_not_predicate checker, :updated?
- touch(tmpfiles)
- wait
+ touch(tmpfiles)
+ wait
- assert_predicate checker, :updated?
- checker.execute
- assert_not_predicate checker, :updated?
- end
+ assert_predicate checker, :updated?
+ checker.execute
+ assert_not_predicate checker, :updated?
+ end
- test "should execute the block if files change in a watched directory one extension" do
- i = 0
+ test "should execute the block if files change in a watched directory one extension" do
+ i = 0
- checker = new_checker([], tmpdir => :rb) { i += 1 }
+ checker = new_checker([], tmpdir => :rb) { i += 1 }
- touch(tmpfile("foo.rb"))
- wait
+ touch(tmpfile("foo.rb"))
+ wait
- assert checker.execute_if_updated
- assert_equal 1, i
- end
+ assert checker.execute_if_updated
+ assert_equal 1, i
+ end
- test "should execute the block if files change in a watched directory any extensions" do
- i = 0
+ test "should execute the block if files change in a watched directory any extensions" do
+ i = 0
- checker = new_checker([], tmpdir => []) { i += 1 }
+ checker = new_checker([], tmpdir => []) { i += 1 }
- touch(tmpfile("foo.rb"))
- wait
+ touch(tmpfile("foo.rb"))
+ wait
- assert checker.execute_if_updated
- assert_equal 1, i
- end
+ assert checker.execute_if_updated
+ assert_equal 1, i
+ end
- test "should execute the block if files change in a watched directory several extensions" do
- i = 0
+ test "should execute the block if files change in a watched directory several extensions" do
+ i = 0
- checker = new_checker([], tmpdir => [:rb, :txt]) { i += 1 }
+ checker = new_checker([], tmpdir => [:rb, :txt]) { i += 1 }
- touch(tmpfile("foo.rb"))
- wait
+ touch(tmpfile("foo.rb"))
+ wait
- assert checker.execute_if_updated
- assert_equal 1, i
+ assert checker.execute_if_updated
+ assert_equal 1, i
- touch(tmpfile("foo.txt"))
- wait
+ touch(tmpfile("foo.txt"))
+ wait
- assert checker.execute_if_updated
- assert_equal 2, i
- end
+ assert checker.execute_if_updated
+ assert_equal 2, i
+ end
- test "should not execute the block if the file extension is not watched" do
- i = 0
+ test "should not execute the block if the file extension is not watched" do
+ i = 0
- checker = new_checker([], tmpdir => :txt) { i += 1 }
+ checker = new_checker([], tmpdir => :txt) { i += 1 }
- touch(tmpfile("foo.rb"))
- wait
+ touch(tmpfile("foo.rb"))
+ wait
- assert_not checker.execute_if_updated
- assert_equal 0, i
- end
+ assert_not checker.execute_if_updated
+ assert_equal 0, i
+ end
- test "does not assume files exist on instantiation" do
- i = 0
+ test "does not assume files exist on instantiation" do
+ i = 0
- non_existing = tmpfile("non_existing.rb")
- checker = new_checker([non_existing]) { i += 1 }
+ non_existing = tmpfile("non_existing.rb")
+ checker = new_checker([non_existing]) { i += 1 }
- touch(non_existing)
- wait
+ touch(non_existing)
+ wait
- assert checker.execute_if_updated
- assert_equal 1, i
- end
+ assert checker.execute_if_updated
+ assert_equal 1, i
+ end
- test "detects files in new subdirectories" do
- i = 0
+ test "detects files in new subdirectories" do
+ i = 0
- checker = new_checker([], tmpdir => :rb) { i += 1 }
+ checker = new_checker([], tmpdir => :rb) { i += 1 }
- subdir = tmpfile("subdir")
- mkdir(subdir)
- wait
+ subdir = tmpfile("subdir")
+ mkdir(subdir)
+ wait
- assert_not checker.execute_if_updated
- assert_equal 0, i
+ assert_not checker.execute_if_updated
+ assert_equal 0, i
- touch(File.join(subdir, "nested.rb"))
- wait
+ touch(File.join(subdir, "nested.rb"))
+ wait
- assert checker.execute_if_updated
- assert_equal 1, i
- end
+ assert checker.execute_if_updated
+ assert_equal 1, i
+ end
- test "looked up extensions are inherited in subdirectories not listening to them" do
- i = 0
+ test "looked up extensions are inherited in subdirectories not listening to them" do
+ i = 0
- subdir = tmpfile("subdir")
- mkdir(subdir)
+ subdir = tmpfile("subdir")
+ mkdir(subdir)
- checker = new_checker([], tmpdir => :rb, subdir => :txt) { i += 1 }
+ checker = new_checker([], tmpdir => :rb, subdir => :txt) { i += 1 }
- touch(tmpfile("new.txt"))
- wait
+ touch(tmpfile("new.txt"))
+ wait
- assert_not checker.execute_if_updated
- assert_equal 0, i
+ assert_not checker.execute_if_updated
+ assert_equal 0, i
- # subdir does not look for Ruby files, but its parent tmpdir does.
- touch(File.join(subdir, "nested.rb"))
- wait
+ # subdir does not look for Ruby files, but its parent tmpdir does.
+ touch(File.join(subdir, "nested.rb"))
+ wait
- assert checker.execute_if_updated
- assert_equal 1, i
+ assert checker.execute_if_updated
+ assert_equal 1, i
- touch(File.join(subdir, "nested.txt"))
- wait
+ touch(File.join(subdir, "nested.txt"))
+ wait
- assert checker.execute_if_updated
- assert_equal 2, i
- end
+ assert checker.execute_if_updated
+ assert_equal 2, i
+ end
- test "initialize raises an ArgumentError if no block given" do
- assert_raise ArgumentError do
- new_checker([])
+ test "initialize raises an ArgumentError if no block given" do
+ assert_raise ArgumentError do
+ new_checker([])
+ end
+ end
end
end
end
diff --git a/activesupport/test/xml_mini_test.rb b/activesupport/test/xml_mini_test.rb
index 18a3f2ca66..73e7f40b0d 100644
--- a/activesupport/test/xml_mini_test.rb
+++ b/activesupport/test/xml_mini_test.rb
@@ -5,6 +5,7 @@ require "active_support/xml_mini"
require "active_support/builder"
require "active_support/core_ext/hash"
require "active_support/core_ext/big_decimal"
+require "active_support/core_ext/date/conversions"
require "yaml"
module XmlMiniTest
diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb
index 436315ce1e..aa7ef1077e 100644
--- a/railties/lib/rails/generators.rb
+++ b/railties/lib/rails/generators.rb
@@ -128,11 +128,6 @@ module Rails
end
end
- # Remove the color from output.
- def no_color!
- Thor::Base.shell = Thor::Shell::Basic
- end
-
# Returns an array of generator namespaces that are hidden.
# Generator namespaces may be hidden for a variety of reasons.
# Some are aliased such as "rails:migration" and can be