Commit Graph

1157 Commits

Author SHA1 Message Date
Akira Matsuda
6ffb29d24e users_dont_suck_but_only_we_suck_and_only_our_tests_are_order_dependent!
Calling ActiveSupport::TestCase.i_suck_and_my_tests_are_order_dependent! in AS::TestCase makes
everyone's tests order dependent, which should never be done by the framework.
2014-08-12 19:37:04 +09:00
@schneems and @sgrif
2bbcca004c Deprecate *_path methods in mailers
Email does not support relative links since there is no implicit host. Therefore all links inside of emails must be fully qualified URLs. All path helpers are now deprecated. When removed, the error will give early indication to developers to use `*_url` methods instead.

Currently if a developer uses a `*_path` helper, their tests and `mail_view` will not catch the mistake. The only way to see the error is by sending emails in production. Preventing sending out emails with non-working path's is the desired end goal of this PR.

Currently path helpers are mixed-in to controllers (the ActionMailer::Base acts as a controller). All `*_url` and `*_path` helpers are made available through the same module. This PR separates this behavior into two modules so we can extend the `*_path` methods to add a Deprecation to them. Once deprecated we can use this same area to raise a NoMethodError and add an informative message directing the developer to use `*_url` instead.

The module with warnings is only mixed in when a controller returns false from the newly added `supports_relative_path?`.

Paired @sgrif & @schneems
2014-07-30 12:01:45 -05:00
Yves Senn
b8120ab14d Raise an exception when attachments are added after mail was called.
Closes #16163

Adding attachments after a call to `mail` will result in invalid emails.
This is related to the fact, that `mail` is making the required preparations
before the email is ready to be sent. These change depending on your
added attachments.
2014-07-29 09:24:06 +02:00
Rafael Mendonça França
08754f12e6 Merge branch 'rm-remove-mocha'
Conflicts:
	actionpack/test/abstract_unit.rb
2014-07-19 18:17:13 -03:00
Rafael Mendonça França
fd6aaaa0c3 Stop requiring mocha automatically
We are planning to remove mocha from our test suite because of
performance problems. To make this possible we should stop require mocha
on ActionSupport::TestCase.

This should not affect applications since users still need to add mocha
to Gemfile and this already load mocha.

Added FIXME notes to place that still need mocha removal
2014-07-19 17:35:12 -03:00
Guo Xiang Tan
ee35b79d4c Prefer to pass block when logging.
The Logger by default includes a guard which checks for the
logging level. By removing the custom logging guards, we can decouple
the logging guard from the logging action to be done.

This also follows the good practice listed on http://guides.rubyonrails.org/debugging_rails_applications.html#impact-of-logs-on-performance.
2014-07-18 15:04:43 +08:00
Santosh Wadghule
dfee0327b5 Fix typos like a html to an html and 'an mail' to 'an email'. [ci skip] 2014-07-14 00:14:47 +05:30
Aaron Patterson
e0c6b35dac test i18n against a routed app 2014-07-07 15:08:12 -07:00
Dmitry Polushkin
99f8d4feeb add test coverage for the action mailer 2014-07-04 15:55:33 +01:00
Rafael Mendonça França
72f58b0244 Rename preview_enabled option to show_previews 2014-07-01 13:09:24 -03:00
Leonard Garvey
84ed7b8dfe Add configuration to enable mail previews
Adds `config.action_mailer.preview_enabled`

This allows mail previewing to be enabled easily in non-development
environments such as staging. The default is set to true for development
so no changes should be required to existing Rails applications.

The mail preview path can still be configured using the existing
`config.action_mailer.preview_path` configuration option.

Adding this avoids devs from having to do stuff like:
https://gist.github.com/lengarvey/fa2c9bd6cdbeba96526a

Update actionmailer/CHANGELOG with new configuration.
Update configuring guide with new configuratation.
Add `config.action_mailer.preview_path` to configuring guide.
2014-07-01 14:39:59 +10:00
Rafael Mendonça França
6a682e3f8b Merge pull request #15815 from DNNX/mail-helper-refactoring
Remove unused block parameter from #gsub call in AM::MailHelper#block_format
2014-06-19 13:27:03 -03:00
Viktar Basharymau
9f6a796234 Add logger.debug? guard to ActionMailer::LogSubscriber#process
*TLDR*: The method is 4 times faster when log level is higher than DEBUG.
Also, the other two methods, `#deliver` and `#receive` have similar guard statements,
so this commit adds some symmetry to the code.

This is probably not the most critical part of ActionMailer in terms
of performance, but here are some benchmarks:

```
require 'benchmark/ips'
require 'action_mailer'

event = ActiveSupport::Notifications::Event.new(
            'process.action_mailer',
            Time.now,
            Time.now,
            'bf4e2b36ce085fd35b24',
            { mailer: "UserMailer", action: :welcome }
        )

ActionMailer::Base.logger = ActiveSupport::Logger.new '/dev/null'

subscriber = ActionMailer::LogSubscriber.new
def subscriber.process_with_guard(event)
  return unless logger.debug?
  mailer = event.payload[:mailer]
  action = event.payload[:action]
  debug("\n#{mailer}##{action}: processed outbound mail in #{event.duration.round(1)}ms")
end

Benchmark.ips do |r|
  ActionMailer::Base.logger.level = ::Logger::Severity::INFO
  r.report('no guard') { subscriber.process(event) }
  r.report('   guard') { subscriber.process_with_guard(event) }
end

__END__
Calculating -------------------------------------
            no guard      9640 i/100ms
               guard     38381 i/100ms
-------------------------------------------------
            no guard   169166.9 (±10.2%) i/s -     838680 in   5.007262s
               guard   728184.9 (±9.6%) i/s -    3607814 in   4.999218s
```

When log level is DEBUG, the _guarded_ method is a bit slower. This is a
good tradeoff for 4x improvement in production mode.

```
Benchmark.ips do |r|
  ActionMailer::Base.logger.level = ::Logger::Severity::DEBUG
  r.report('no guard') { subscriber.process(event) }
  r.report('   guard') { subscriber.process_with_guard(event) }
end

__END__
Calculating -------------------------------------
            no guard      4970 i/100ms
               guard      4564 i/100ms
-------------------------------------------------
            no guard    55617.4 (±3.5%) i/s -     278320 in   5.010523s
               guard    49452.1 (±5.6%) i/s -     251020 in   5.093358s

```
2014-06-19 18:52:11 +03:00
Viktar Basharymau
e60c85b4b6 Remove unused block parameter from #gsub call in AM::MailHelper#block_format 2014-06-19 17:40:37 +03:00
Yves Senn
f59ed560ac allow preview interceptors to be registered through config.action_mailer.
This was partially broken because `preview_interceptors=` just assigned the
raw values, whithout going through `register_preview_interceptor`. Now the
Action Mailer railtie takes care of the `preview_interceptors` option.

This commit is a partial revert of:

Revert "Merge pull request #15739 from y-yagi/correct_doc_for_action_mailer_base"

This reverts commit a15704d7f35f17d34d0118546799141d6f853656, reversing
changes made to 1bd12a8609d275ad75fcc4b622ca4f5b32dc76be.

/cc @kuldeepaggarwal @y-yagi
2014-06-15 14:17:00 +02:00
yuuji.yaginuma
71da4b0c79 [ci skip] correct doc for register_preview_interceptor 2014-06-15 09:31:28 +09:00
Yves Senn
8f247871bb Merge pull request #15590 from zuhao/refactor_actionview_register_template_handler
Add unregister_template_handler to prevent leaks.

Conflicts:
	actionview/CHANGELOG.md
2014-06-12 14:06:59 +02:00
Zuhao Wan
a1dbb4e7e0 Add unregister_template_handler to prevent leaks. 2014-06-12 18:49:40 +08:00
Juanito Fatas
6a781b9245 [ci skip] Improve enable_starttls_auto documentation. 2014-06-11 01:51:06 +08:00
Zuhao Wan
573a8421e7 Restore I18n.locale to default after test.
If i18n_with_controller_test.rb were to run first, the I18n.locale will
be changed to :de, and the following tests in base_test.rb will fail:

"subject gets default from I18n"
“default subject can have interpolations”
"translations are scoped properly"
"implicit multipart with default locale"
2014-06-07 00:52:24 +08:00
Zuhao Wan
c4f4123ef4 Restore test deliveries properly in ActionMailer.
`ActionMailer::Base.delivery_method` and
`ActionMailer::Base.perform_deliveries` have leaked states.

"delivery method can be customized per instance" and "delivery method
can be customized in subclasses not changing the parent" in
delivery_methods_test.rb will fail if test_helper_test.rb (in which
TestHelperMailerTest is inherited from ActionMailer::TestCase) runs
before it.
2014-06-07 00:11:24 +08:00
Benjamin Fleischer
bb0890d056 Relax mail gem constraint from ~> 2.5.4 to ~> 2.5, >= 2.5.4
This allows Rails users to install mail 2.6 which relaxes
the mime-types dependency, which is a big win for a lot of people.

Previously, the mail gem restricted mime-types to ~> 1.16
but now it has expanded to [">= 1.16", "< 3"]

And the mime-types maintainer will also be checking that
2.x releases don't break mail.

See https://github.com/mikel/mail/pull/713
https://rubygems.org/gems/mail/versions/2.6.0
2014-06-03 11:54:45 -05:00
Zachary Scott
4c66ab2b21 Feature requests should be made on the mailing list, not submitted to
the issue tracker. See also #15455 [ci skip]
2014-06-01 19:11:39 -07:00
Zachary Scott
415ba0c323 Pass through AM documentation re: 02d048d [ci skip] 2014-05-26 16:45:50 -07:00
Zachary Scott
02d048d926 Use "Action Mailer" as canonical name in documentation [ci skip]
See also:
3a297f8db7 (commitcomment-6451708)
2014-05-26 16:38:44 -07:00
Zachary Scott
3a297f8db7 Add description of ActionMailer::TestHelper module [ci skip] 2014-05-26 16:34:16 -07:00
Yves Senn
fd6d6dc602 Merge pull request #15083 from zuhao/refactor_actionmailer_i18n_with_controller_test
Use with_translation helper to clean up I18n stored translations.
2014-05-13 10:43:50 +02:00
Zuhao Wan
32ef7d3c5c Use with_translation helper to clean up I18n stored translations. 2014-05-13 16:38:21 +08:00
Yves Senn
9392d1615c Merge pull request #15082 from zuhao/refactor_actionmailer_delivery_methods_test
Clean up deliveries after each test.
2014-05-13 10:32:37 +02:00
Zuhao Wan
5330b894e5 Move state restoration from setup/teardown into affected test cases. 2014-05-13 16:28:39 +08:00
Yves Senn
b6d627b49a Merge pull request #15086 from zuhao/refactor_actionmailer_mail_layout_test
Do not clear deliveries in setup.
2014-05-13 09:39:13 +02:00
Zuhao Wan
4d9e4ea47a Remove unnecessary setup and teardown. 2014-05-13 15:03:53 +08:00
Zuhao Wan
275d20ca01 A minor stylistic fix and cleanup of mail deliveries. 2014-05-13 13:01:14 +08:00
Zuhao Wan
1401637e3f Fix state leaks in actionmailer/test/base_test.rb. 2014-05-07 20:49:43 +08:00
Gaurav Sharma
c4807672a8 [ci skip] Improve formatting and yml 2014-04-24 18:51:34 +05:30
Arthur Neves
f870c4d063
Fix MailerPreview broken tests
`BaseMailerPreview.welcome` is an instance method, so we need to stub the
method on a instance level and not on Class. The stub is important to make
sure the Message object is the same in the other expectations.
This was working randomly because Mocha uses == to compare two objects
on the `with()` expectation and even if the Mail::Message objects were
not the same object they are equal, but thats not the case in 100% of
the runs. So we need to make sure we use `.any_instance` method and have
the right message object.
2014-03-15 18:56:32 -04:00
Arthur Neves
d39bba7c85
Make sure we clean preview_interceptors
We should make sure we clean preview_interceptors after each test so they dont leaky to the next test
2014-03-07 14:53:18 -05:00
Vijay Dev
70ff31d69f Merge branch 'master' of github.com:rails/docrails
Conflicts:
	guides/source/4_1_release_notes.md
2014-03-07 20:58:11 +05:30
Prem Sichanugrist
2dd2fcf896
Introduce Rails.gem_version
This method return `Gem::Version.new(Rails.version)`, suggesting a more
reliable way to perform version comparison.

Example:

    Rails.version #=> "4.1.2"
    Rails.gem_version #=> #<Gem::Version "4.1.2">

    Rails.version > "4.1.10" #=> false
    Rails.gem_version > Gem::Version.new("4.1.10") #=> true
    Gem::Requirement.new("~> 4.1.2") =~ Rails.gem_version #=> true

This was originally introduced as `.version` by @charliesome in #8501
but got reverted in #10002 since it was not backward compatible.

Also, updating template for `rake update_versions`.
2014-03-05 12:37:38 -05:00
Carlos Antonio da Silva
71b3910a7d Point master changelogs to 4-1-stable branch
Remove 4-1 related entries from master [ci skip]
2014-02-25 09:14:36 -03:00
Yves Senn
c554d170e6 update version to 4.2.0.alpha 2014-02-23 13:14:43 +01:00
Zachary Scott
f302079d97 ✂️
This commit also addresses rails/docrails#169 and rails/rails#14159
2014-02-23 20:24:23 +11:00
Guillermo Iguaran
1c248dfbab Fix render plain docs example in AM::Base
The errors were introduced in e220a34e39
2014-02-18 15:18:37 -05:00
robertomiranda
e220a34e39 Update Docs in favor to use render plain instead of text option
ref #14062
2014-02-18 15:05:10 -05:00
Rafael Mendonça França
1879c259b8 Merge branch '4-1-0-beta2'
Conflicts:
	actionview/CHANGELOG.md
	activerecord/CHANGELOG.md
2014-02-18 16:00:47 -03:00
Rafael Mendonça França
8b20c72dd8 Preparing for 4.1.0.beta2 release 2014-02-18 15:45:20 -03:00
Rafael Mendonça França
99cdad6d9c Fix typo [ci skip] 2014-02-16 21:49:50 -03:00
Rafael Mendonça França
e4911e9162 Merge pull request #13997 from dmitry/test_coverage_improvement
Test coverage improvement
2014-02-09 16:51:59 -02:00
Dmitry Polushkin
5af7cab02d add actionmailer test coverage for undefined delivery method 2014-02-09 18:41:41 +00:00
Vijay Dev
92fdd65162 Merge branch 'master' of github.com:rails/docrails
Conflicts:
	guides/source/active_record_validations.md
	guides/source/api_documentation_guidelines.md
	guides/source/configuring.md
2014-02-09 23:33:55 +05:30