diff options
-rw-r--r-- | activesupport/lib/active_support/core_ext/module/anonymous.rb | 7 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/range/conversions.rb | 19 | ||||
-rw-r--r-- | guides/source/active_support_core_extensions.md | 4 | ||||
-rw-r--r-- | guides/source/testing.md | 1 | ||||
-rw-r--r-- | railties/CHANGELOG.md | 7 | ||||
-rw-r--r-- | railties/lib/rails/tasks.rb | 1 | ||||
-rw-r--r-- | railties/lib/rails/tasks/restart.rake | 4 | ||||
-rw-r--r-- | railties/test/application/rake/restart_test.rb | 31 |
8 files changed, 70 insertions, 4 deletions
diff --git a/activesupport/lib/active_support/core_ext/module/anonymous.rb b/activesupport/lib/active_support/core_ext/module/anonymous.rb index b0c7b021db..0ecc67a855 100644 --- a/activesupport/lib/active_support/core_ext/module/anonymous.rb +++ b/activesupport/lib/active_support/core_ext/module/anonymous.rb @@ -7,6 +7,13 @@ class Module # m = Module.new # m.name # => nil # + # +anonymous?+ method returns true if module does not have a name: + # + # Module.new.anonymous? # => true + # + # module M; end + # M.anonymous? # => false + # # A module gets a name when it is first assigned to a constant. Either # via the +module+ or +class+ keyword or by an explicit assignment: # diff --git a/activesupport/lib/active_support/core_ext/range/conversions.rb b/activesupport/lib/active_support/core_ext/range/conversions.rb index b1a12781f3..83eced50bf 100644 --- a/activesupport/lib/active_support/core_ext/range/conversions.rb +++ b/activesupport/lib/active_support/core_ext/range/conversions.rb @@ -3,9 +3,24 @@ class Range :db => Proc.new { |start, stop| "BETWEEN '#{start.to_s(:db)}' AND '#{stop.to_s(:db)}'" } } - # Gives a human readable format of the range. + # Convert range to a formatted string. See RANGE_FORMATS for predefined formats. # - # (1..100).to_formatted_s # => "1..100" + # This method is aliased to <tt>to_s</tt>. + # + # range = (1..100) # => 1..100 + # + # range.to_formatted_s # => "1..100" + # range.to_s # => "1..100" + # + # range.to_formatted_s(:db) # => "BETWEEN '1' AND '100'" + # range.to_s(:db) # => "BETWEEN '1' AND '100'" + # + # == Adding your own range formats to to_formatted_s + # You can add your own formats to the Range::RANGE_FORMATS hash. + # Use the format name as the hash key and a Proc instance. + # + # # config/initializers/range_formats.rb + # Range::RANGE_FORMATS[:short] = ->(start, stop) { "Between #{start.to_s(:db)} and #{stop.to_s(:db)}" } def to_formatted_s(format = :default) if formatter = RANGE_FORMATS[format] formatter.call(first, last) diff --git a/guides/source/active_support_core_extensions.md b/guides/source/active_support_core_extensions.md index 0594b701dc..2e7f776319 100644 --- a/guides/source/active_support_core_extensions.md +++ b/guides/source/active_support_core_extensions.md @@ -349,7 +349,7 @@ end we get: ```ruby -current_user.to_query('user') # => user=357-john-smith +current_user.to_query('user') # => "user=357-john-smith" ``` This method escapes whatever is needed, both for the key and the value: @@ -1237,7 +1237,7 @@ Calling `dup` or `clone` on safe strings yields safe strings. The method `remove` will remove all occurrences of the pattern: ```ruby -"Hello World".remove(/Hello /) => "World" +"Hello World".remove(/Hello /) # => "World" ``` There's also the destructive version `String#remove!`. diff --git a/guides/source/testing.md b/guides/source/testing.md index 14bc75aa7d..cb3bd68fbe 100644 --- a/guides/source/testing.md +++ b/guides/source/testing.md @@ -450,6 +450,7 @@ All the basic assertions such as `assert_equal` defined in `Minitest::Assertions * `ActionMailer::TestCase` * `ActionView::TestCase` * `ActionDispatch::IntegrationTest` +* `ActiveJob::TestCase` Each of these classes include `Minitest::Assertions`, allowing us to use all of the basic assertions in our tests. diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 8306233dcd..8b10144413 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,10 @@ +* Created rake restart task. Restarts your Rails app by touching the + `tmp/restart.txt`. + + Fixes #18876. + + *Hyonjee Joo* + * Set Rails console to use log formatter and log level as specified for the given environment. diff --git a/railties/lib/rails/tasks.rb b/railties/lib/rails/tasks.rb index 945fbdb3e2..a5e4d2935e 100644 --- a/railties/lib/rails/tasks.rb +++ b/railties/lib/rails/tasks.rb @@ -7,6 +7,7 @@ require 'rake' log middleware misc + restart routes statistics tmp diff --git a/railties/lib/rails/tasks/restart.rake b/railties/lib/rails/tasks/restart.rake new file mode 100644 index 0000000000..1af0302824 --- /dev/null +++ b/railties/lib/rails/tasks/restart.rake @@ -0,0 +1,4 @@ +desc "Restart app by touching tmp/restart.txt" +task restart: :environment do + FileUtils.touch('tmp/restart.txt') +end diff --git a/railties/test/application/rake/restart_test.rb b/railties/test/application/rake/restart_test.rb new file mode 100644 index 0000000000..35099913fb --- /dev/null +++ b/railties/test/application/rake/restart_test.rb @@ -0,0 +1,31 @@ +require "isolation/abstract_unit" + +module ApplicationTests + module RakeTests + class RakeRestartTest < ActiveSupport::TestCase + include ActiveSupport::Testing::Isolation + + def setup + build_app + boot_rails + end + + def teardown + teardown_app + end + + test 'rake restart touches tmp/restart.txt' do + Dir.chdir(app_path) do + `rake restart` + assert File.exist?("tmp/restart.txt") + + prev_mtime = File.mtime("tmp/restart.txt") + sleep(1) + `rake restart` + curr_mtime = File.mtime("tmp/restart.txt") + assert_not_equal prev_mtime, curr_mtime + end + end + end + end +end |