aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionmailer/CHANGELOG.md4
-rw-r--r--actionmailer/lib/action_mailer/base.rb3
-rw-r--r--actionmailer/test/base_test.rb19
-rw-r--r--activesupport/lib/active_support/core_ext/module/delegation.rb16
-rw-r--r--railties/CHANGELOG.md6
-rw-r--r--railties/lib/rails/test_unit/minitest_plugin.rb14
-rw-r--r--railties/test/application/test_runner_test.rb15
7 files changed, 62 insertions, 15 deletions
diff --git a/actionmailer/CHANGELOG.md b/actionmailer/CHANGELOG.md
index 54b07a626b..6ec10c7a70 100644
--- a/actionmailer/CHANGELOG.md
+++ b/actionmailer/CHANGELOG.md
@@ -1,3 +1,7 @@
+* Add `:args` to `process.action_mailer` event.
+
+ *Yuji Yaginuma*
+
* Add parameterized invocation of mailers as a way to share before filters and defaults between actions.
See ActionMailer::Parameterized for a full example of the benefit.
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb
index f02108a859..444be944df 100644
--- a/actionmailer/lib/action_mailer/base.rb
+++ b/actionmailer/lib/action_mailer/base.rb
@@ -598,7 +598,8 @@ module ActionMailer
def process(method_name, *args) #:nodoc:
payload = {
mailer: self.class.name,
- action: method_name
+ action: method_name,
+ args: args
}
ActiveSupport::Notifications.instrument("process.action_mailer", payload) do
diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb
index 490aaf33fc..61960d411d 100644
--- a/actionmailer/test/base_test.rb
+++ b/actionmailer/test/base_test.rb
@@ -834,6 +834,25 @@ class BaseTest < ActiveSupport::TestCase
assert_equal "special indeed!", mail["X-Special-Header"].to_s
end
+ test "notification for process" do
+ begin
+ events = []
+ ActiveSupport::Notifications.subscribe("process.action_mailer") do |*args|
+ events << ActiveSupport::Notifications::Event.new(*args)
+ end
+
+ BaseMailer.welcome(body: "Hello there").deliver_now
+
+ assert_equal 1, events.length
+ assert_equal "process.action_mailer", events[0].name
+ assert_equal "BaseMailer", events[0].payload[:mailer]
+ assert_equal :welcome, events[0].payload[:action]
+ assert_equal [{ body: "Hello there" }], events[0].payload[:args]
+ ensure
+ ActiveSupport::Notifications.unsubscribe "process.action_mailer"
+ end
+ end
+
private
# Execute the block setting the given values and restoring old values after
diff --git a/activesupport/lib/active_support/core_ext/module/delegation.rb b/activesupport/lib/active_support/core_ext/module/delegation.rb
index 19f692e943..d82758e40d 100644
--- a/activesupport/lib/active_support/core_ext/module/delegation.rb
+++ b/activesupport/lib/active_support/core_ext/module/delegation.rb
@@ -20,7 +20,8 @@ class Module
# ==== Options
# * <tt>:to</tt> - Specifies the target object
# * <tt>:prefix</tt> - Prefixes the new method with the target name or a custom prefix
- # * <tt>:allow_nil</tt> - if set to true, prevents a +NoMethodError+ from being raised
+ # * <tt>:allow_nil</tt> - if set to true, prevents a +Module::DelegationError+
+ # from being raised
#
# The macro receives one or more method names (specified as symbols or
# strings) and the name of the target object via the <tt>:to</tt> option
@@ -112,18 +113,19 @@ class Module
# invoice.customer_address # => 'Vimmersvej 13'
#
# If the target is +nil+ and does not respond to the delegated method a
- # +NoMethodError+ is raised, as with any other value. Sometimes, however, it
- # makes sense to be robust to that situation and that is the purpose of the
- # <tt>:allow_nil</tt> option: If the target is not +nil+, or it is and
- # responds to the method, everything works as usual. But if it is +nil+ and
- # does not respond to the delegated method, +nil+ is returned.
+ # +Module::DelegationError+ is raised, as with any other value. Sometimes,
+ # however, it makes sense to be robust to that situation and that is the
+ # purpose of the <tt>:allow_nil</tt> option: If the target is not +nil+, or it
+ # is and responds to the method, everything works as usual. But if it is +nil+
+ # and does not respond to the delegated method, +nil+ is returned.
#
# class User < ActiveRecord::Base
# has_one :profile
# delegate :age, to: :profile
# end
#
- # User.new.age # raises NoMethodError: undefined method `age'
+ # User.new.age
+ # # => Module::DelegationError: User#age delegated to profile.age, but profile is nil
#
# But if not having a profile yet is fine and should not be an error
# condition:
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md
index 0b2fb3e9c8..7aee513a99 100644
--- a/railties/CHANGELOG.md
+++ b/railties/CHANGELOG.md
@@ -1,3 +1,9 @@
+* Fix running multiple tests in one `rake` command
+
+ e.g. `bin/rake test:models test:controllers`
+
+ *Dominic Cleal*
+
* Add option to configure Ruby's warning behaviour to test runner.
*Yuji Yaginuma*
diff --git a/railties/lib/rails/test_unit/minitest_plugin.rb b/railties/lib/rails/test_unit/minitest_plugin.rb
index e3c70b0b3d..4df3e7f0f2 100644
--- a/railties/lib/rails/test_unit/minitest_plugin.rb
+++ b/railties/lib/rails/test_unit/minitest_plugin.rb
@@ -59,19 +59,18 @@ module Minitest
options[:color] = true
options[:output_inline] = true
- options[:patterns] = defined?(@rake_patterns) ? @rake_patterns : opts.order!
+ options[:patterns] = opts.order! unless run_via[:rake]
end
- # Running several Rake tasks in a single command would trip up the runner,
- # as the patterns would also contain the other Rake tasks.
def self.rake_run(patterns) # :nodoc:
- @rake_patterns = patterns
+ run_via[:rake] = true
+ ::Rails::TestRequirer.require_files(patterns)
autorun
end
module RunRespectingRakeTestopts
def run(args = [])
- if defined?(@rake_patterns)
+ if run_via[:rake]
args = Shellwords.split(ENV["TESTOPTS"] || "")
end
@@ -86,8 +85,9 @@ module Minitest
def self.plugin_rails_init(options)
ENV["RAILS_ENV"] = options[:environment] || "test"
- # If run via `ruby` we've been passed the files to run directly.
- unless run_via[:ruby]
+ # If run via `ruby` we've been passed the files to run directly, or if run
+ # via `rake` then they have already been eagerly required.
+ unless run_via[:ruby] || run_via[:rake]
::Rails::TestRequirer.require_files(options[:patterns])
end
diff --git a/railties/test/application/test_runner_test.rb b/railties/test/application/test_runner_test.rb
index 4e36d126fc..d3d5b6d6dd 100644
--- a/railties/test/application/test_runner_test.rb
+++ b/railties/test/application/test_runner_test.rb
@@ -536,6 +536,21 @@ module ApplicationTests
assert_match "seed=1234", output, "passing TEST= should run selected test"
end
+ def test_rake_runs_multiple_test_tasks
+ create_test_file :models, "account"
+ create_test_file :controllers, "accounts_controller"
+ output = Dir.chdir(app_path) { `bin/rake test:models test:controllers TESTOPTS='-v'` }
+ assert_match "AccountTest#test_truth", output
+ assert_match "AccountsControllerTest#test_truth", output
+ end
+
+ def test_rake_db_and_test_tasks_parses_args_correctly
+ create_test_file :models, "account"
+ output = Dir.chdir(app_path) { `bin/rake db:migrate test:models TESTOPTS='-v' && echo ".tables" | rails dbconsole` }
+ assert_match "AccountTest#test_truth", output
+ assert_match "ar_internal_metadata", output
+ end
+
def test_warnings_option
app_file "test/models/warnings_test.rb", <<-RUBY
require 'test_helper'