Skip to content

Commit

Permalink
Make ActionMailer::TestCase#read_fixture public
Browse files Browse the repository at this point in the history
Since this method has been documented in the guides for ages, it's probably safe.

https://guides.rubyonrails.org/testing.html#revenge-of-the-fixtures

TODO: I don't like how these methods are documented on
ActionMailer::TestCase::Behavior, even though the API is meant to be
exposed through ActionMailer::TestCase
  • Loading branch information
zzak committed Jun 20, 2023
1 parent 162c4b4 commit 2cdb05f
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions actionmailer/lib/action_mailer/test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ def determine_default_mailer(name)
end
end

# Reads the fixture file for the given mailer.
#
# This is useful when testing mailers by being able to write the body of
# an email inside a fixture. See the testing guide for a concrete example:
# https://guides.rubyonrails.org/testing.html#revenge-of-the-fixtures
def read_fixture(action)
IO.readlines(File.join(Rails.root, "test", "fixtures", self.class.mailer_class.name.underscore, action))
end

private
def initialize_test_deliveries
set_delivery_method :test
Expand Down Expand Up @@ -110,10 +119,6 @@ def charset
def encode(subject)
Mail::Encodings.q_value_encode(subject, charset)
end

def read_fixture(action)
IO.readlines(File.join(Rails.root, "test", "fixtures", self.class.mailer_class.name.underscore, action))
end
end

include Behavior
Expand Down

0 comments on commit 2cdb05f

Please sign in to comment.