Commit Graph

1742 Commits

Author SHA1 Message Date
Yoshiyuki Hirano ed3f315907 Auto correct rubocop offenses
Offenses:

railties/lib/rails/autoloaders.rb:1:1: C: [Corrected] Style/FrozenStringLiteralComment: Missing magic comment # frozen_string_literal: true.
module Rails
^
actionmailer/test/base_test.rb:917:1: C: [Corrected] Layout/EmptyLinesAroundBlockBody: Extra empty line detected at block body beginning.
actionmailer/test/base_test.rb:917:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
actionmailer/test/base_test.rb:917:5: C: [Corrected] Style/RedundantBegin: Redundant begin block detected.
    begin
    ^^^^^
actionmailer/test/base_test.rb:918:3: C: [Corrected] Layout/IndentationWidth: Use 2 (not 4) spaces for indentation.
      events = []
  ^^^^
actionmailer/test/base_test.rb:930:1: C: [Corrected] Layout/EmptyLinesAroundBlockBody: Extra empty line detected at block body end.
actionmailer/test/base_test.rb:930:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
2019-02-17 17:12:22 +09:00
Aaron Patterson a3a98606f3
pass format to the digestor 2019-02-16 10:57:51 -08:00
Jaap van der Plas 2488901da8 Don’t log recipients when sending mail
Since production applications typically run with log level info and
email adresses should be considered as sensitive data we want to prevent 
them from ending up in the logs. In development mode (with log level
debug) they are still logged as part of the Mail::Message object.
2019-02-13 09:55:38 -05:00
utilum 87a5379b42 Ruby 2.7 warning: creating a Proc without a block
As of [Revision 66772](
https://bugs.ruby-lang.org/projects/ruby-trunk/repository/trunk/revisions/66772)
 `Proc.new` without giving a block emits `warning: tried to create Proc object without a block`.

This commit fixes cases where Rails test suit tickles this warning.

See CI logs:
https://travis-ci.org/rails/rails/jobs/487205819#L1161-L1190
https://travis-ci.org/rails/rails/jobs/487205821#L1154-1159
https://travis-ci.org/rails/rails/jobs/487205821#L1160-L1169
https://travis-ci.org/rails/rails/jobs/487205821#L1189
https://travis-ci.org/rails/rails/jobs/487254404#L1307-L1416
https://travis-ci.org/rails/rails/jobs/487254405#L1174-L1191
2019-02-13 02:11:21 +01:00
Xavier Noria 821d6c694c Zeitwerk integration 2019-02-12 02:28:04 -08:00
Matthew Somerville c95e98090b Correctly wrap inline attachments.
This switches the behaviour from:

multipart/related
  multipart/alternative
    text/plain
    text/html
  attachment (disposition: inline, image1)
  attachment (disposition: attachment, file1)
  attachment (disposition: attachment, file2)

to:

multipart/mixed
  multipart/related
    multipart/alternative
      text/plain
      text/html
    attachment (disposition: inline, image1)
  attachment (disposition: attachment, file1)
  attachment (disposition: attachment, file2)

Fixes #2686.

Thanks to clemens and eGust for reviewing.
2019-01-22 09:50:10 +00:00
Rafael Mendonça França 5a0230c67f
Preparing for 6.0.0.beta1 release 2019-01-18 15:42:12 -05:00
Gannon McGibbon 5d6578d15b Fix legacy fallback for parameterized mailers 2019-01-07 17:38:28 -05:00
Gannon McGibbon e5f2d2906a Move MailDeliveryJob default to 6.0 defaults 2019-01-07 17:38:21 -05:00
Arun Agrawal 50e3680768 Bump license years for 2019 2018-12-31 10:24:38 +07:00
bogdanvlviv 2e29488a89
Remove mention about `receive.action_mailer` from the AS instrumentation guide
Since e3f832a743 `ActionMailer::Base.receive` is
deprecated.
2018-12-28 11:23:27 +02:00
George Claghorn e3f832a743 Deprecate ActionMailer::Base.receive in favor of Action Mailbox 2018-12-27 21:17:58 -05:00
Ryuta Kamizono 892e38c78e Enable `Style/RedundantBegin` cop to avoid newly adding redundant begin block
Currently we sometimes find a redundant begin block in code review
(e.g. https://github.com/rails/rails/pull/33604#discussion_r209784205).

I'd like to enable `Style/RedundantBegin` cop to avoid that, since
rescue/else/ensure are allowed inside do/end blocks in Ruby 2.5
(https://bugs.ruby-lang.org/issues/12906), so we'd probably meets with
that situation than before.
2018-12-21 06:12:42 +09:00
pavel bf01cc6744 fix tests for mail 2.8 2018-12-19 18:12:58 -08:00
Kasper Timm Hansen 1b7c3222e8
Require Ruby 2.5 for Rails 6.
Generally followed the pattern for https://github.com/rails/rails/pull/32034

* Removes needless CI configs for 2.4
* Targets 2.5 in rubocop
* Updates existing CHANGELOG entries for fewer merge conflicts
* Removes Hash#slice extension as that's inlined on Ruby 2.5.
* Removes the need for send on define_method in MethodCallAssertions.
2018-12-19 21:47:50 +01:00
Gannon McGibbon f5050d998d Add MailDeliveryJob for unified mail delivery
Add `MailDeliveryJob` for delivering both regular and parameterized mail.
Deprecate using `DeliveryJob` and `Parameterized::DeliveryJob`.
2018-12-04 11:00:34 -05:00
Gannon McGibbon ebf484a640 Add yield to with_delivery_job test helper
Adds yield to parameterized mail test helper so assertions
passed into with_delivery_job are actually ran.
2018-11-30 17:38:26 -05:00
Gannon McGibbon 60339da5bc Deliver parameterized mail with DeliveryJob
Deliver parameterized mail with `ActionMailer::DeliveryJob`
and remove `ActionMailer::Parameterized::DeliveryJob`.
2018-11-22 18:37:53 -05:00
Edouard CHIN e139a3ce13 Fix ActionMailer assertion not working for mail defining delivery_job:
- If a Mail defines a custom delivery_job, all ActionMailer assertion
  helper (assert_emails, assert_enqueued_emails ...) wouldn't work.

  ```ruby
    MyMailer < ApplicationMailer
      self.delivery_job = MyJob
    end

    # This assertion will fail
    assert_emails(1) do
      MyMailer.my_mail.deliver_later
    end

  This PR leverage the new ActiveJob feature that accepts Procs for the
  `only` keyword and check if the delivery job is one of ActionMailer
   registered ones.
2018-11-21 23:17:04 +01:00
Rafael Mendonça França 72062c8c9d Merge pull request #22534 from evopark/master
ActionMailer: support overriding template name in multipart
2018-11-19 19:23:44 -05:00
Gannon McGibbon e74fdbe00c Amend CVE note and security guide section wordings
Reword first sentence of dep management and CVE section of
security guide. Also, reword and move gemspec notes above deps.

[ci skip]
2018-11-06 18:06:57 -05:00
Gannon McGibbon 1c11688b56 Add CVE note to security guide and gemspecs
[ci skip]
2018-11-06 14:25:36 -05:00
yuuji.yaginuma d2d6f6b7db Fix tests on Mail 2.7.1
Up to `2.7.0`, encoding was chosen using `Mail::Encodings::TransferEncoding.negotiate`,
and base64 encoding was used.
In `2.7.1`, when `transfer_encoding` is not specified, the encoding
of the message is respected.
Related to: dead487e02

However, what chosen for transfer encoding is not essential in these tests.
To test more accurately, confirm that the decoded body instead.
2018-10-14 14:44:47 +09:00
Luke Pearce c90c6c1344 Parameterized mailers can configure delivery job
Setting parameterized_delivery_job on a mailer class will cause Parameterized::MessageDelivery to use
the specified job instead of ActionMailer::Parameterized::DeliveryJob:

    class MyMailer < ApplicationMailer
      self.parameterized_delivery_job = MyCustomDeliveryJob
      ...
    end
2018-10-05 17:02:40 +01:00
Sharang Dashputre 3c4b729f48 Fix spellings for 'unmarshall(ing/ed)' & 'marshall(ing/ed)' 2018-10-02 13:55:39 +05:30
Yasuo Honda aa3dcabd87 Add `Style/RedundantFreeze` to remove redudant `.freeze`
Since Rails 6.0 will support Ruby 2.4.1 or higher
`# frozen_string_literal: true` magic comment is enough to make string object frozen.
This magic comment is enabled by `Style/FrozenStringLiteralComment` cop.

* Exclude these files not to auto correct false positive `Regexp#freeze`
 - 'actionpack/lib/action_dispatch/journey/router/utils.rb'
 - 'activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb'

It has been fixed by https://github.com/rubocop-hq/rubocop/pull/6333
Once the newer version of RuboCop released and available at Code Climate these exclude entries should be removed.

* Replace `String#freeze` with `String#-@` manually if explicit frozen string objects are required

 - 'actionpack/test/controller/test_case_test.rb'
 - 'activemodel/test/cases/type/string_test.rb'
 - 'activesupport/lib/active_support/core_ext/string/strip.rb'
 - 'activesupport/test/core_ext/string_ext_test.rb'
 - 'railties/test/generators/actions_test.rb'
2018-09-29 07:18:44 +00:00
Rafael Mendonça França f679933daa
Change the empty block style to have space inside of the block 2018-09-25 13:19:35 -04:00
Aaron Patterson d34bd0d2d5
Merge pull request #33974 from rails/remove-catch-all-from-am
This patch removes deprecated catch-all routes from AM
2018-09-25 09:27:56 -07:00
Aaron Patterson fefcb36811
This patch removes deprecated catch-all routes from AM
It also removes a monkey patch from AM::Base
2018-09-24 16:12:44 -07:00
Kasper Timm Hansen 22dc2b3db8
Merge pull request #33949 from sjain1107/no-private-def
Remove private def
2018-09-23 19:39:15 +02:00
Sakshi Jain 0fe2bb816f Remove private def 2018-09-23 21:27:44 +05:30
yuuji.yaginuma 1b86d90136 Enable `Performance/UnfreezeString` cop
In Ruby 2.3 or later, `String#+@` is available and `+@` is faster than `dup`.

```ruby
# frozen_string_literal: true

require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org"

  gem "benchmark-ips"
end

Benchmark.ips do |x|
  x.report('+@') { +"" }
  x.report('dup') { "".dup }
  x.compare!
end
```

```
$ ruby -v benchmark.rb
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
Warming up --------------------------------------
                  +@   282.289k i/100ms
                 dup   187.638k i/100ms
Calculating -------------------------------------
                  +@      6.775M (± 3.6%) i/s -     33.875M in   5.006253s
                 dup      3.320M (± 2.2%) i/s -     16.700M in   5.032125s

Comparison:
                  +@:  6775299.3 i/s
                 dup:  3320400.7 i/s - 2.04x  slower

```
2018-09-23 08:56:55 +09:00
bogdanvlviv 5a212939c2
Add changelog entries for #33849 [ci skip]
Since these changes related to the public API, I think we should add
changelog entries.

Related to #33838, #33849
2018-09-13 16:58:56 +03:00
Ricardo Díaz 64a9759aff Include test helpers when ActionDispatch::IntegrationTest is loaded
As @dhh brings up, the point of `ActionDispatch::IntegrationTest` is to
allow users to test the integration of all the pieces called by a
controller. Asserting about the emails and jobs queued is part of that
task.

This commit includes the `ActionMailer::TestHelper` and
`ActiveJob::TestHelper` modules when the ActionMailer and ActiveJob
railties are initialized respectively.
2018-09-12 16:58:14 -05:00
Yoshiyuki Kinjo 576209b45b Add `perform_deliveries` to a payload of `deliver.action_mailer` notification. 2018-09-09 20:17:36 +09:00
Yoshiyuki Kinjo 383b8bc8e2 Skip delivery notification when perform_deliveries is false. 2018-09-08 17:29:28 +09:00
Kazuhiro Sera 52919f3d13 Fix the obvious typos detected by github.com/client9/misspell 2018-08-08 21:55:46 +09:00
Dillon Welch d108288c2f
Turn on performance based cops
Use attr_reader/attr_writer instead of methods

method is 12% slower

Use flat_map over map.flatten(1)

flatten is 66% slower

Use hash[]= instead of hash.merge! with single arguments

merge! is 166% slower

See https://github.com/rails/rails/pull/32337 for more conversation
2018-07-23 15:37:06 -07:00
bogdanvlviv ff090977c1
Fix docs of `assert_no_emails` [ci skip]
`assert_no_emails` is shortcut for `assert_emails 0, &block`.
2018-06-29 16:02:52 +03:00
bogdanvlviv 4382fcbc22
Allow call `assert_enqueued_with` and `assert_enqueued_email_with` with no block
Example of `assert_enqueued_with` with no block
```ruby
def test_assert_enqueued_with
  MyJob.perform_later(1,2,3)
  assert_enqueued_with(job: MyJob, args: [1,2,3], queue: 'low')

  MyJob.set(wait_until: Date.tomorrow.noon).perform_later
  assert_enqueued_with(job: MyJob, at: Date.tomorrow.noon)
end
```

Example of `assert_enqueued_email_with` with no block:
```ruby
def test_email
  ContactMailer.welcome.deliver_later
  assert_enqueued_email_with ContactMailer, :welcome
end

def test_email_with_arguments
  ContactMailer.welcome("Hello", "Goodbye").deliver_later
  assert_enqueued_email_with ContactMailer, :welcome, args: ["Hello", "Goodbye"]
end
```

Related to #33243
2018-06-29 15:37:02 +03:00
Kota Miyake b74edd37c5 ActionMailer::Base can unregister observer(s) and interceptor(s). (#32207)
* ActionMailer::Base can unregister observer(s) and interceptor(s).

One or multiple mail observers can be unregistered using
`ActionMailer::Base.unregister_observers` or
`ActionMailer::Base.unregister_observer`.

One or multiple mail interceptors can be unregistered using
`ActionMailer::Base.unregister_interceptors` or
`ActionMailer::Base.unregister_interceptor`.

For preview interceptors, it's possible to use
`ActionMailer::Base.unregister_preview_interceptors` or
`ActionMailer::Base.unregister_preview_interceptor`.

* Ensure to be reset registered observer(s) and interceptor(s)

* Add explanation to CHANGELOG

* Add original author's name

[Kota Miyake + Rafael Mendonça França + Claudio Ortolina]
2018-05-30 17:36:24 -04:00
Samuel Cochran 4d43b05881 Eager autoload mail gem when eager load is true (#32808)
* Eager autoload mail gem when eager load is true

We had a production issue where our Sidekiq worker threads all became
deadlocked while autoloading a file within the mail gem, required via
ActionMailer, despite setting our Rails applicaiton to eager load.
`Mail.eager_autoload!` exists and works great, ActionMailer just doesn't
call it during eager loading. Adding it to the ActionMailer Railtie's
eager_load_namespaces takes care of calling `Mail.eager_autoload!`
during the `eager_load!` initializer.

* 'Mail' isn't defined yet, use before_eager_load instead

* Make sure mail is loaded

* Move eager load of Mail into ActionMailer.eager_load!

[Samuel Cochran + Rafael Mendonça França]
2018-05-23 16:50:36 -04:00
Ryuta Kamizono e4a0a04883 Strip duplicated suffixes more strictly
In the previous code incorrectly removes intermediate words.
2018-04-22 14:30:07 +09:00
Daniel Colson a1ac18671a Replace `assert !` with `assert_not`
This autocorrects the violations after adding a custom cop in
3305c78dcd.
2018-04-19 08:11:33 -04:00
Ryuta Kamizono 41e9a671d6
Merge pull request #32427 from tjschuck/small_doc_fixes
Small doc fixes

[ci skip]
2018-04-03 11:58:53 +09:00
Michael H 795ff87837
Doc fix added missing quote 2018-04-02 17:26:56 -07:00
T.J. Schuck 0ef8221910 Small doc fixes
[ci skip]
2018-04-02 19:55:08 -04:00
bogdanvlviv 10cc06809d
Partly revert #32231
- Remove extra execution of `perform_enqueued_jobs`
  since it performs all enqueued jobs in the duration of the block.
- Fix example of using `assert_emails` without block since we
  can't use enqueued jobs in this case.
2018-03-14 01:31:35 +02:00
Rafael Mendonça França f36e298ca7
Merge pull request #32231 from gmcgibbon/perform_email_jobs_in_assert_emails
Perform email jobs in #assert_emails
2018-03-13 15:18:49 -04:00
Gannon McGibbon 96218b4568 Perform email jobs in #assert_emails
Perform enqueued delivery jobs in #assert_emails and #assert_no_emails.
2018-03-12 15:35:18 -04:00
Jeremy Daer d4eb0dc89e Rails 6 requires Ruby 2.4.1+
Skipping over 2.4.0 to sidestep the `"symbol_from_string".to_sym.dup` bug.

References #32028
2018-02-17 15:34:57 -08:00
Rafael Mendonça França 0ea8e7db1a Remove support to Ruby 2.2
Rails 6 will only support Ruby >= 2.3.
2018-02-16 18:52:10 -05:00
Rafael Mendonça França 1c383df324 Start Rails 6.0 development!!!
🎉🎉🎉
2018-01-30 18:51:17 -05:00
Daniel Colson 82c39e1a0b Use assert_empty and assert_not_empty 2018-01-25 23:32:59 -05:00
Daniel Colson 94333a4c31 Use assert_predicate and assert_not_predicate 2018-01-25 23:32:59 -05:00
Daniel Colson 0d50cae996 Use respond_to test helpers 2018-01-25 23:32:58 -05:00
Ryuta Kamizono 6003dafc1f Merge pull request #30391 from jbourassa/fix-actionmailer-lambda-default
Fix actionmailer lambda default
2018-01-24 06:01:25 +09:00
James Lovejoy 49542ae886 Fix typos, update documentation
[ci skip]
2018-01-11 17:10:06 -08:00
Prathamesh Sonpatki 07563036b0
Move the options for deliver_later up near to the example [ci skip]
- And move the Active Job related section down. Otherwise it was
  appearing as if the options are available for the `delivery_job`
  setting.
2018-01-04 21:51:30 +05:30
Yoshiyuki Hirano b20354afcc Bump license years for 2018 2017-12-31 22:36:55 +09:00
Ryuta Kamizono 2b35826389 Enable `Layout/SpaceBeforeComma` rubocop rule, and fixed more
Follow up of #31390.
2017-12-12 20:00:50 +09:00
Rafael Mendonça França 2837d0f334
Preparing for 5.2.0.beta2 release 2017-11-28 14:41:02 -05:00
Fatos Morina 37cf9b3466 Fix typos and add a few suggestions 2017-11-28 19:27:43 +01:00
Rafael Mendonça França cceeeb6e57
Preparing for 5.2.0.beta1 release 2017-11-27 14:50:03 -05:00
Dwight Watson 908aaa650e Sort mailer previews 2017-11-14 10:16:27 +11:00
Rafael Mendonça França 8dd76a7a6f
Use .tt extension to all the template files
Make clear that the files are not to be run for interpreters.

Fixes #23847.
Fixes #30690.
Closes #23878.
2017-11-13 15:23:28 -05:00
Jeremy Daer 0931e17ebf
Fix tests on Mail 2.7
Reverts 4d96be1c27
References #31026
2017-10-31 21:44:58 -07:00
Rafael França a8ebd48559
Merge pull request #31004 from shuheiktgw/remove_unnecessary_returns
Remove redundant return statements
2017-10-31 01:47:35 -04:00
Shuhei Kitagawa 03dd47ff21 removed unnecessary semicolons 2017-10-28 17:39:58 +09:00
Shuhei Kitagawa c40b4428e6 removed unnecessary returns 2017-10-28 17:20:38 +09:00
Akira Matsuda a53a52d8ca [Action Mailer] require_relative => require
This basically reverts cd9cc721ab
2017-10-21 22:48:28 +09:00
Ryuta Kamizono fced30c373 Cleanup CHANGELOGs [ci skip]
* Add missing credit
* Add backticks
* Fix indentation
* Remove trailing spaces

And some minor tweaks.
2017-10-04 07:27:33 +09:00
Mikkel Malmberg db6847dcb6 Add assert_enqueued_email_with to ActionMailer::TestHelper 2017-09-27 23:22:49 +02:00
Yoshiyuki Hirano 413bb9bd34 Update Action Mailer doc [ci skip] 2017-08-30 03:29:41 +09:00
Jimmy Bourassa fbb2fc8aa7 Fix AM::Base.default proc arity breaking change
PR #29270 changed the number of arguments that gets passed to Procs
defined in ActionMail::Base.default. With this changeset, Procs can
now have 1 or 0 arguments

Also adds test coverage for AM::Base.default Proc arity.
2017-08-29 09:42:28 -04:00
Yoshiyuki Hirano 70f75caaa3 Use tt in doc for action_mailer [ci skip] 2017-08-26 08:40:18 +09:00
Rafael Mendonça França 783295f706 Merge pull request #30213 from ckundo/ccundiff-alt-text-default
Do not generate default alt text for images
2017-08-23 11:51:34 -04:00
Yoshiyuki Hirano 3a11e0586e Update MIT licenses link [ci skip] 2017-08-22 08:46:02 +09:00
Cameron Cundiff 9a74c7b99b Do not generate default alt text in image tags
- Auto-generating content from the filename of an image is not suitable
  alternative text; alt text that isn't fully considered can be
  distracting and fatiguing for screen readers users (blind, low vision,
  dyslexic people).
- Setting a filename fallback short circuits screen reader default
  behavior and configuration for blank descriptions.
- Setting poor defaults also creates false negatives for accessibility
  linting and testing software, that makes it harder to improve
  application accessibility.

***

- After this change, if authors leave images without alt text, screen
  readers will fallback to default behavior for missing alt text.
- Also with this change, Automated linting and testing tools will
  correctly generate warnings.

[Fixes #30096]
2017-08-17 16:13:15 -04:00
yuuji.yaginuma 2f469dc308 Clear mail after test
If clear it before the test, the mail of the last executed test will not
be correctly cleared.

Therefore, executing the test with seed below will result in an error.

```
./bin/test -w --seed 55480
Run options: --seed 55480

# Running:

...........................................................................................................................................................F

Failure:
MailDeliveryTest#test_does_not_increment_the_deliveries_collection_on_error [/home/yaginuma/program/rails/master_y_yagi/rails/actionmailer/test/delivery_methods_test.rb:221]:
--- expected
+++ actual
@@ -1 +1 @@
-[]
+[#<Mail::Message:47011389364640, Multipart: false, Headers: <Date: Mon, 14 Aug 2017 07:48:40 +0900>, <From: test-sender@test.com>, <To: test-receiver@test.com>, <Message-ID: <5990d748ea5b2_29342ac1af8bcf40886f7@yaginuma.mail>>, <Subject: Test Subject>, <Mime-Version: 1.0>, <Content-Type: text/plain>, <Content-Transfer-Encoding: 7bit>>]

bin/test test/delivery_methods_test.rb:216
```
2017-08-14 07:49:13 +09:00
Rafael França b9e0b4f199 Merge pull request #29559 from kirs/eager-load-controller-actions
Eager load controller actions to reduce response time of the first request
2017-08-11 17:54:04 -04:00
Youssef Boulkaid d33bdef821 Remove outdated comment [ci skip]
The comment was describing a previous version of the method with
a different signature. This is outdated since e76c38e
2017-08-06 04:20:16 +02:00
Rafael Mendonça França feb1ddae02 Merge remote-tracking branch 'origin/master' into unlock-minitest 2017-08-01 17:34:14 -04:00
Kir Shatrov 0668c22a41 Eager load controller and mailer actions
On the first request, ActionController::Base#action_methods computes
and memoized the list of available actions [1]. With this PR we move
this expensive operation into eager load step to reduce response time
of the first request served in production.

This also reduces the memory footprint when running on forking server
like Unicorn.

[1] a3813dce9a/actionpack/lib/abstract_controller/base.rb (L66-L77)
2017-07-29 14:03:52 +03:00
Kir Shatrov 82df8c2ca5 Use frozen string literal in actionmailer/ 2017-07-23 18:17:19 +03:00
Kasper Timm Hansen aad42dce10 Merge branch 'master' into unlock-minitest 2017-07-15 21:17:27 +02:00
Xavier Noria 92c29d82eb Merge branch 'master' into require_relative_2017 2017-07-02 13:50:25 -07:00
Matthew Draper 87b3e226d6 Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"
This reverts commit 3420a14590, reversing
changes made to afb66a5a59.
2017-07-02 02:15:17 +09:30
Matthew Draper 3420a14590 Merge pull request #29540 from kirs/rubocop-frozen-string
Enforce frozen string in Rubocop
2017-07-02 01:11:50 +09:30
Matthew Draper afb66a5a59 Merge pull request #29506 from pat/frozen-string-literals
Make ActiveSupport frozen-string-literal friendly.
2017-07-02 01:07:12 +09:30
Akira Matsuda cd9cc721ab [Action Mailer] require => require_relative 2017-07-01 18:38:05 +09:00
Kir Shatrov cfade1ec7e Enforce frozen string in Rubocop 2017-07-01 02:11:03 +03:00
Grey Baker 3e6ce1cd69 Add source code and changelog links to gemspecs 2017-06-28 10:06:01 +01:00
Pat Allan dd491b24ff Make ActionMailer frozen string literal friendly. 2017-06-20 19:45:46 +10:00
Ryuta Kamizono 6bb7d50dec Fix formatting of `ActionMailer::MessageDelivery` doc [ci skip] 2017-06-16 10:33:53 +09:00
Matthew Mongeau 425e351a5e Document setting the delivery_job for ActionMailer [ci skip] 2017-06-16 10:13:40 +09:00
Ryuta Kamizono 6e227ad345 Fix indentation [ci skip] 2017-06-15 21:44:19 +09:00
Matthew Mongeau d9bbde09fc Allow mailers to configure their delivery job
Setting delivery_job on a mailer class will cause MessageDelivery to use
the specified job instead of ActionMailer::DeliveryJob:

    class MyMailer < ApplicationMailer
      self.delivery_job = MyCustomDeliveryJob

      ...
    end
2017-06-15 16:41:23 +09:00
bogdanvlviv 6673cf7071
Use `require_relative` instead of `require` with full path 2017-06-14 12:10:17 +03:00
Genadi Samokovarov b6b0c99ff3 Use mattr_accessor default: option throughout the project 2017-06-03 13:52:48 +03:00
Kasper Timm Hansen e1758b5e8c Merge branch 'master' into unlock-minitest 2017-05-29 20:37:35 +02:00
David Heinemeier Hansson 1c275d812f Add option for class_attribute default (#29270)
* Allow a default value to be declared for class_attribute

* Convert to using class_attribute default rather than explicit setter

* Removed instance_accessor option by mistake

* False is a valid default value

* Documentation
2017-05-29 18:01:50 +02:00
bogdanvlviv 40bdbce191
Define path with __dir__
".. with __dir__ we can restore order in the Universe." - by @fxn

Related to 5b8738c2df
2017-05-23 00:53:51 +03:00
David Heinemeier Hansson 75fa8dd309 Use recyclable cache keys (#29092) 2017-05-18 18:12:32 +02:00
Ryuta Kamizono b201474756 Should escape meta characters in regexp 2017-05-07 04:10:00 +09:00
Rafael França a23846e0ab Merge pull request #28835 from fphilipe/master
Add missing require in ActionMailer::Base
2017-05-02 11:16:53 -07:00
Philipe Fatio eddbb62f94
Add missing require in ActionMailer
Without this, Action Mailer doesn't work like it used to on version 4.
The following snippet fails since version 5:

    > require 'action_mailer'
    > ActionMailer::Base
    NameError: uninitialized constant ActiveSupport::Rescuable
2017-05-02 07:22:48 +02:00
Rafael Mendonça França 0d35a60ff7
Avoid stubing on this test
This will avoid to the test fail when running in isolation because the
message generated is nil.
2017-04-27 02:05:00 -07:00
Rafael França f680664d4e Merge pull request #28244 from ixti/improve/action-mailer-preview-params
Pass request params to ActionMailer::Preview
2017-04-26 20:15:30 -07:00
yuuji.yaginuma e4cf71bf7a Remove duplicated `delivery_method` definition
`ActionMailer::Base.delivery_method` is already defined in
https://github.com/rails/rails/blob/master/actionmailer/test/parameterized_test.rb#L13
2017-04-07 21:58:08 +09:00
Matthew Draper 6c08d480f1 Start Rails 5.2 development 2017-03-22 10:11:39 +10:30
Andrew White c7135d2c8e Use better duration aliases in tests 2017-03-15 14:56:27 +00:00
Andrew White ef28b68496 Don't cast to float unnecessarily
Adding durations to `Time` instances is perfectly okay.
2017-03-15 08:19:27 +00:00
Krzysztof Zych 3a6e84715e Document using `default_url_options` in an ActionMailer class. 2017-03-08 13:34:28 +01:00
Andrew White 75924c4517 Deprecate implicit coercion of `ActiveSupport::Duration`
Currently `ActiveSupport::Duration` implicitly converts to a seconds
value when used in a calculation except for the explicit examples of
addition and subtraction where the duration is the receiver, e.g:

    >> 2 * 1.day
    => 172800

This results in lots of confusion especially when using durations
with dates because adding/subtracting a value from a date treats
integers as a day and not a second, e.g:

    >> Date.today
    => Wed, 01 Mar 2017
    >> Date.today + 2 * 1.day
    => Mon, 10 Apr 2490

To fix this we're implementing `coerce` so that we can provide a
deprecation warning with the intent of removing the implicit coercion
in Rails 5.2, e.g:

    >> 2 * 1.day
    DEPRECATION WARNING: Implicit coercion of ActiveSupport::Duration
    to a Numeric is deprecated and will raise a TypeError in Rails 5.2.
    => 172800

In Rails 5.2 it will raise `TypeError`, e.g:

    >> 2 * 1.day
    TypeError: ActiveSupport::Duration can't be coerced into Integer

This is the same behavior as with other types in Ruby, e.g:

    >> 2 * "foo"
    TypeError: String can't be coerced into Integer
    >> "foo" * 2
    => "foofoo"

As part of this deprecation add `*` and `/` methods to `AS::Duration`
so that calculations that keep the duration as the receiver work
correctly whether the final receiver is a `Date` or `Time`, e.g:

    >> Date.today
    => Wed, 01 Mar 2017
    >> Date.today + 1.day * 2
    => Fri, 03 Mar 2017

Fixes #27457.
2017-03-02 08:00:22 +00:00
Alexey Zapparov 8e6c6d854c
Pass request params to ActionMailer::Preview 2017-03-01 20:54:14 +01:00
Rafael Mendonça França f4acdd83ff
Preparing for 5.1.0.beta1 release 2017-02-23 14:53:21 -05:00
Jon Moss f4d2bcdd6d Add backticks around constant
[ci skip]
2017-02-21 11:45:50 -05:00
Stan Lo dde7134e07 Freeze fragment cache related instrument name.
ActionMailer::Base#instrument_name and
ActionController::Base#instrument_name will be frequently called once
caching is enabled. So it's better to freeze them instead of create new
string on every call.

Also, the instrument name in #instrument_fragment_cache will usually
be "write_fragment.action_controller" or
"read_fragment.action_controller". So freezing them might also gain some
performance improvement. We have done something like this in other places:
https://github.com/rails/rails/blob/master/actionview/lib/action_view/template.rb#L348
2017-02-07 00:41:02 +08:00
yuuji.yaginuma 53b98f1dda Add `:args` to `process.action_mailer` event 2017-02-04 11:43:24 +09:00
Eugene Kenny ebededb372
Don't mutate raw_source in mailer preview interceptor
The raw_source method is documented as returning the exact value that
was used to create the body; mutating it breaks that contract.

Additionally, if the value used to create the body is blank, raw_source
returns a frozen string which causes the interceptor to raise an error.
2017-01-30 22:20:47 -07:00
yuuji.yaginuma 18cc66cef6 add default value to `deliver_later_queue_name` option [ci skip] 2017-01-31 10:23:21 +09:00
Rafael Mendonça França 2dadf73891
Document with with an example an link to Parameterized
Also change the class_methods to ClassMethods since the former document
the method as an instance method of Parameterized not as a class method.
2017-01-30 13:38:12 -05:00
Rafael Mendonça França d3cb00b87e
✂️ 2017-01-30 13:38:06 -05:00
Rafael Mendonça França bfda627713
No need to advertise in the rdoc documentation 2017-01-30 13:31:11 -05:00
Rafael Mendonça França 0435d65000
Avoid should in test names 2017-01-30 13:28:31 -05:00
Rafael Mendonça França 735aa635c5
Implement respond_to_missing? in the Parameterized::Mailer class 2017-01-30 13:28:14 -05:00
Rafael Mendonça França bfc69e873d
Remove unneeded nodoc 2017-01-30 13:17:52 -05:00
Rafael Mendonça França 58f9c4f096
Override the initializers instead of using tap
We own the class so we can override the initialize.
2017-01-30 13:02:30 -05:00
Rafael Mendonça França 04b59ec930
Make internal classes internal for the documentation 2017-01-30 13:02:11 -05:00
David Heinemeier Hansson d5651436d6 Make assert_enqueued_emails + assert_no_enqueued_emails consider parameterized delivery jobs
Needed for testing of parameterized mailers
2017-01-30 13:41:08 +01:00
Kasper Timm Hansen e552db0588 [ci skip] other -> order; expand ivar 2017-01-28 19:00:54 +01:00
yuuji.yaginuma a28f8b5baf restore `delivery_method` after test
Currently use two variables to restore `delivery_method`, but the order
of restoring the values is incorrect and does not restore is correctly.
2017-01-29 00:52:44 +09:00
David Heinemeier Hansson 1cec84ad2d Offer the option to use parameterization for shared processing of headers and ivars (#27825)
Offer the option to use parameterization for shared processing of headers and ivars
2017-01-28 11:20:46 +01:00
Akira Matsuda 146e928800 Don't pollute Object with rubinius_skip and jruby_skip
we call them only in the tests
2017-01-17 18:51:50 +09:00
Akira Matsuda aaece61a53 ZOMG worst typo in my life 😱 2017-01-15 05:16:53 +09:00
Akira Matsuda ec513098fe `respond_to_missing?` should fallback to `super` where method_missing could call `super` 2017-01-15 03:58:19 +09:00
Akira Matsuda b70fc698e1 Reduce string objects by using \ instead of + or << for concatenating strings
(I personally prefer writing one string in one line no matter how long it is, though)
2017-01-12 17:45:37 +09:00
Akira Matsuda c82fa18514 Use Encoding::UTF_8 constant for default_{internal,external} in the tests 2017-01-11 17:48:00 +09:00
Rafael Mendonça França e482dce0ed
Merge pull request #27227 from MQuy/allow-custom-content-type-in-mail-body
Allow to custom content type when setting mailer body
2017-01-06 06:03:41 -05:00
MQuy f091bd67b3 Remove unnecessary condition in content_type 2017-01-06 18:37:33 +08:00
Akira Matsuda 5473e390d3 `self.` is not needed when calling its own instance method
Actually, private methods cannot be called with `self.`, so it's not just redundant, it's a bad habit in Ruby
2017-01-05 19:58:52 +09:00
Rafael Mendonça França b6ffb5efcb
Revert "Merge pull request #27550 from mtsmfm/fix-generator-command-for-nested-rails-engine"
This reverts commit 1e969bfb98, reversing
changes made to a5041f267d.

Reason: It breaks the public API
2017-01-03 21:51:18 -05:00
Rafael França 1e969bfb98 Merge pull request #27550 from mtsmfm/fix-generator-command-for-nested-rails-engine
Fix generator command for nested (namespaced) rails engine
2017-01-03 21:45:25 -05:00
Rafael Mendonça França 7339547602
Remove unneeded Deprecation.silence 2017-01-03 20:54:34 -05:00
Fumiaki MATSUSHIMA 085546df45 Fix generator command for nested (namespaced) rails engine
If we create nested (namespaced) rails engine such like bukkits-admin,
`bin/rails g scaffold User name:string age:integer`
will create
`bukkits-admin/app/controllers/bukkits/users_controller.rb`
but it should create
`bukkits-admin/app/controllers/bukkits/admin/users_controller.rb`.

In #6643, we changed `namespaced_path` as root path
because we supposed application_controller is always in root
but nested rails engine's application_controller will not.
2017-01-03 21:18:09 +09:00
Jon Moss 37d956f45f Bump license years for 2017
Per https://www.timeanddate.com/counters/firstnewyear.html, it's already
2017 in a lot of places, so we should bump the Rails license years to
2017.

[ci skip]
2016-12-31 08:34:08 -05:00
Akira Matsuda 8c7e82e8e0 Privatize unneededly protected methods in Action Mailer 2016-12-24 21:01:07 +09:00
Akira Matsuda bbbc3e1619 No need to nodoc private method 2016-12-24 21:01:06 +09:00
Akira Matsuda 8e1da1188f Privatize unneededly protected methods in Action Mailer tests 2016-12-24 00:15:11 +09:00
MQuy 40b1f648b9 Add document in mailer 2016-12-06 13:47:51 +08:00
MQuy 36efba0520 Fix wrong typo in test 2016-12-05 21:47:49 +08:00
MQuy 2263769c79 Add changelog for custom content type 2016-12-01 10:18:00 +08:00
MQuy c4639b7737 allow context type when set body mail 2016-11-30 22:18:14 +08:00
Yves Senn 2b4a9735d8 update bin/test scripts to prevent double runs.
The test runner was updated to make use of autorun. This caused the
`bin/test` scripts to run Minitest twice.
2016-11-21 17:25:12 +01:00
Rafael Mendonça França fe1f4b2ad5
Add more rubocop rules about whitespaces 2016-10-29 01:17:49 -02:00
Rafael Mendonça França 79a5ea9ead
Remove deprecated support to :text in render 2016-10-10 00:02:52 -03:00
Ryuta Kamizono 3464cd5c28 Fix broken comments indentation caused by rubocop auto-correct [ci skip]
All indentation was normalized by rubocop auto-correct at 80e66cc4d9.
But comments was still kept absolute position. This commit aligns
comments with method definitions for consistency.
2016-09-14 18:26:32 +09:00
Xavier Noria 810dff7c9f RuboCop is 100% green 🎉 2016-09-02 00:43:33 +02:00
Xavier Noria bb1ecdcc67 fixes remaining RuboCop issues [Vipul A M, Xavier Noria] 2016-09-01 23:41:49 +02:00
Rafael Mendonça França 0510208dd1
Add load hooks to all tests classes
Usually users extends tests classes doing something like:

    ActionView::TestCase.include MyCustomTestHelpers

This is bad because it will load the ActionView::TestCase right aways
and this will load ActionController::Base making its on_load hooks to
execute early than it should.

One way to fix this is using the on_load hooks of the components like:

    ActiveSupport.on_load(:action_view) do
      ActionView::TestCase.include MyCustomTestHelpers
    end

The problem with this approach is that the test extension will be only
load when ActionView::Base is loaded and this may happen too late in the
test.

To fix this we are adding hooks to people extend the test classes that
will be loaded exactly when the test classes are needed.
2016-08-25 04:22:48 -03:00
Rafael Mendonça França 55f9b8129a
Add three new rubocop rules
Style/SpaceBeforeBlockBraces
Style/SpaceInsideBlockBraces
Style/SpaceInsideHashLiteralBraces

Fix all violations in the repository.
2016-08-16 04:30:11 -03:00
Xavier Noria 432222fae1 prefer __dir__ over __FILE__ in File.expand_path
Thinking .. relative to files is not natural, we are used
to think "parent of a directory", and we have __dir__
nowadays.
2016-08-11 01:03:14 +02:00
Xavier Noria 46f511685c revises more Lint/EndAlignment offenses 2016-08-08 18:25:11 +02:00
Xavier Noria a9dc45459a code gardening: removes redundant selfs
A few have been left for aesthetic reasons, but have made a pass
and removed most of them.

Note that if the method `foo` returns an array, `foo << 1`
is a regular push, nothing to do with assignments, so
no self required.
2016-08-08 01:12:38 +02:00
Stan Lo ab2af4dfcb Modify LogSubscriber for single partial's cache message.
Implement naive partial caching mechanism.

Add test for LogSubscriber

Use ActionView::Base#log_payload to store log_subscriber's payload, so we can pass cache result into it.

Fixed tests

Remove useless settings

Check if #log_payload exists before calling it. Because other classes also includes CacheHelper but don't have is attribute

Use @log_payload_for_partial_reder instead of #log_payload to carry ActionView's payload.

Update test's hash syntax

Add configuration to enable/disable fragment caching logging

Remove unless test and add new test to ensure cache info won't effect next rendering's log

Move :enable_fragment_cache_logging config from ActionView to ActionPack

Apply new config to tests

Update actionview's changelog

Update configuration guide

Improve actionview's changelog

Refactor PartialRenderer#render and log tests

Mute subscriber's log instead of disabling instrumentation.

Fix typo, remove useless comment and use new hash syntax

Improve actionpack's log_subscriber test

Fix rebase mistake

Apply new config to all caching intstrument actions
2016-08-08 00:24:39 +08:00
Ryuta Kamizono 762e3f05f3 Add `Style/EmptyLines` in `.rubocop.yml` and remove extra empty lines 2016-08-07 17:50:59 +09:00
Xavier Noria b326e82dc0 applies remaining conventions across the project 2016-08-06 20:20:22 +02:00
Xavier Noria 80e66cc4d9 normalizes indentation and whitespace across the project 2016-08-06 20:16:27 +02:00
Xavier Noria e6ab70c439 applies new string literal convention to the rest of the project
The current code base is not uniform. After some discussion,
we have chosen to go with double quotes by default.
2016-08-06 19:28:46 +02:00
Xavier Noria adca8154c6 applies new string literal convention in the gemspecs
The current code base is not uniform. After some discussion,
we have chosen to go with double quotes by default.
2016-08-06 19:27:12 +02:00
Xavier Noria b91ff557ef applies new string literal convention in actionmailer/test
The current code base is not uniform. After some discussion,
we have chosen to go with double quotes by default.
2016-08-06 19:03:39 +02:00
Xavier Noria c3e7abddfb applies new string literal convention in actionmailer/lib
The current code base is not uniform. After some discussion,
we have chosen to go with double quotes by default.
2016-08-06 19:01:31 +02:00
yuuji.yaginuma 2a45296114 remove `-t` option from default sendmail arguments [ci skip]
Follow up to #24436
2016-07-06 18:57:53 +09:00
Jonne Haß 5e3fb2f7b0
Do not suggest nonsensical OpenSSL verify modes [ci skip]
SSL_set_verify(3) explains:

SSL_VERIFY_FAIL_IF_NO_PEER_CERT
  Server mode: if the client did not return a certificate, the TLS/SSL
handshake is immediately terminated with a "handshake failure" alert.
This flag must
  be used together with SSL_VERIFY_PEER.

  Client mode: ignored

SSL_VERIFY_CLIENT_ONCE
  Server mode: only request a client certificate on the initial TLS/SSL
handshake. Do not ask for a client certificate again in case of a
renegotiation.
  This flag must be used together with SSL_VERIFY_PEER.

  Client mode: ignored

The SMTP connection here uses a OpenSSL socket in client mode,
suggesting invalid/ignored flags is rather misleading.
2016-06-07 15:50:46 +02:00
Rajat Bansal 72a0f5e24c fix grammar 2016-05-31 13:31:18 +05:30
Javan Makhmali d12209cad2 Remove package:clean task
Introduced in d6f2000a67 and was only used by Action Cable. Now handled by Action Cable’s assets:compile task.
2016-05-24 13:11:28 -04:00
Jeremy Daer e35b98e6f5
Action Mailer: Declarative exception handling with `rescue_from`.
Follows the same pattern as controllers and jobs. Exceptions raised in
delivery jobs (enqueued by `#deliver_later`) are also delegated to the
mailer's rescue_from handlers, so you can handle the DeserializationError
raised by delivery jobs:

```ruby
class MyMailer < ApplicationMailer
  rescue_from ActiveJob::DeserializationError do
    …
  end
```

ActiveSupport::Rescuable polish:
* Add the `rescue_with_handler` class method so exceptions may be
  handled at the class level without requiring an instance.
* Rationalize `exception.cause` handling. If no handler matches the
  exception, fall back to the handler that matches its cause.
* Handle exceptions raised elsewhere. Pass `object: …` to execute
  the `rescue_from` handler (e.g. a method call or a block to
  instance_exec) against a different object. Defaults to `self`.
2016-05-15 18:44:16 -07:00
Rafael Mendonça França 8ecc5ab1d8 Start Rails 5.1 development 🎉 2016-05-10 03:46:56 -03:00
Connor Shea 86c860ff0c
Update rails-dom-testing gem to 2.0
Resolves #24924.
2016-05-09 20:23:42 -06:00
Pedro Adame Vergara 7cffd6b372 Add :ssl/:tls to ActionMailer [ci skip] 2016-05-09 21:20:29 +02:00
Rafael Mendonça França fbdcf5221a Preparing for 5.0.0.rc1 release 2016-05-06 16:54:40 -05:00
Rafael França 063bc008b3 Merge pull request #24589 from vipulnsward/am-fragment-cache
Expand on Action Mailer Fragment caching tests
2016-05-05 16:26:47 -05:00
eileencodes f7a986012a Prep Rails 5 beta 4 2016-04-27 15:48:47 -05:00
arktisklada 9d63111499
Clear ActionMailer deliveries on setup and teardown
Signed-off-by: Jeremy Daer <jeremydaer@gmail.com>
2016-04-25 22:41:18 -05:00
Vipul A M cbb25c4b1c Expand on Action Mailer Fragment caching tests 2016-04-17 23:16:09 +05:30
Edouard CHIN 106ac1016f Small typo on a method name:
- clear_test_deliviers -> clear_test_deliveries
2016-04-15 13:27:09 -04:00
Vipul A M aeffcf25b4 Merge pull request #24525 from tomkadwill/action-mailer-base-docs2
Update ActionMailer base documentation [ci skip]
2016-04-14 02:14:58 +05:30
Tom Kadwill d2f87d7000 Update ActionMailer base documentation [ci skip] 2016-04-13 21:40:03 +01:00
Yves Senn c9238500bd Merge pull request #24497 from vipulnsward/am-changelog-pass
Pass over AM changelog [ci skip]
2016-04-11 17:02:20 +02:00
Vipul A M 829650ebe4 Pass over AM changelog
- Fixed statement about setting `config.action_mailer.default_url_options = {protocol: 'https'}` . We are just setting the protocol key to 'https', not replacing/initializing the complete config.
- Fixed grammar in assert_emails changlog
- Added sentence separator for code ":"

[ci skip]
2016-04-10 23:45:58 +05:30
Tom Kadwill 83ac216933 Update ActionMailer Views documentation [ci skip] 2016-04-10 14:31:32 +01:00
Jeremy Daer 2080ff2872 Merge pull request #24457 from jeremy/mailer/dont-deliver-later-after-message-is-loaded
Disallow calling `#deliver_later` after local message modifications.
2016-04-08 18:40:39 -07:00
yuuji.yaginuma a972fb81f0 remove blank line generated in application_mailer.rb 2016-04-08 06:47:46 +09:00
Jeremy Daer 95e06e6682 Disallow calling `#deliver_later` after local message modifications.
They would be lost when the delivery job is enqueued, otherwise.
Prevents a common, hard-to-find bug like:

```ruby
message = Notifier.welcome(user, foo)
message.message_id = my_generated_message_id
message.deliver_later
```

The message_id is silently lost here! *Only the mailer arguments are
passed to the delivery job.*

This raises an exception now.

Make modifications to the message within the mailer method or use a
custom Active Job to manage delivery instead of using #deliver_later.
2016-04-07 13:36:50 -07:00
arktisklada 23e4c968d2 Sendmail default arguments match Mail::SendMail
Removes `-t`
2016-04-05 14:11:37 -05:00
yui-knk 5aa6c85c3b Suppress warnings
"Using a dynamic :controller (or :action) segment in a route is deprecated"
by 6520ea5f7e (#23980).
2016-03-31 01:07:43 +09:00
Prathamesh Sonpatki 5ac7bd3ec4 Pass over CHANGELOGs [ci skip] 2016-03-30 12:23:29 +05:30
Rafael França 878c2bbaaf Merge pull request #24164 from prathamesh-sonpatki/fix-application-mailer
Correctly generate application_mailer.rb in mountable engines
2016-03-23 23:05:26 -03:00
Rafael Mendonça França 07f3ae8f35 Fix generator test to match to use the string 2016-03-21 14:07:38 -03:00