Skip to content

Commit 3bfda4c

Browse files
authored
Merge pull request rails#48989 from spickermann/sort-mailers-on-preview-page-alphabetically
Sort mailers on mailer preview page alphabetically
2 parents 0306f5a + dd8b0e4 commit 3bfda4c

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

actionmailer/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Mailers are listed in alphabetical order on the mailer preview page now.
2+
3+
*Martin Spickermann*
4+
15
* Deprecate passing params to `assert_enqueued_email_with` via the `:args`
26
kwarg. `assert_enqueued_email_with` now supports a `:params` kwarg, so use
37
that to pass params:

actionmailer/lib/action_mailer/preview.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class << self
103103
# Returns all mailer preview classes.
104104
def all
105105
load_previews if descendants.empty?
106-
descendants
106+
descendants.sort_by { |mailer| mailer.name.titleize }
107107
end
108108

109109
# Returns the mail object for the given email name. The registered preview

actionmailer/test/base_test.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,24 @@ def self.previewing_email(mail); end
11311131
end
11321132
end
11331133

1134+
class PreviewTest < ActiveSupport::TestCase
1135+
class A < ActionMailer::Preview; end
1136+
1137+
module B
1138+
class A < ActionMailer::Preview; end
1139+
class C < ActionMailer::Preview; end
1140+
end
1141+
1142+
class C < ActionMailer::Preview; end
1143+
1144+
test "all() returns mailers in alphabetical order" do
1145+
ActionMailer::Preview.stub(:descendants, [C, A, B::C, B::A]) do
1146+
mailers = ActionMailer::Preview.all
1147+
assert_equal [A, B::A, B::C, C], mailers
1148+
end
1149+
end
1150+
end
1151+
11341152
class BasePreviewTest < ActiveSupport::TestCase
11351153
class BaseMailerPreview < ActionMailer::Preview
11361154
def welcome

0 commit comments

Comments
 (0)