Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mastodon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pierre Boudes
mastodon
Commits
f596a413
Commit
f596a413
authored
7 years ago
by
Akihiko Odaki (@fn_aki@pawoo.net)
Committed by
Eugen Rochko
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Localize date in digest and cover NotificationMailer more (#3694)
* Localize date in digest * Cover NotificationMailer more
parent
9e53fe5c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/views/notification_mailer/digest.text.erb
+1
-1
1 addition, 1 deletion
app/views/notification_mailer/digest.text.erb
spec/mailers/notification_mailer_spec.rb
+61
-9
61 additions, 9 deletions
spec/mailers/notification_mailer_spec.rb
with
62 additions
and
10 deletions
app/views/notification_mailer/digest.text.erb
+
1
−
1
View file @
f596a413
<%=
display_name
(
@me
)
%>
,
<%=
raw
t
(
'notification_mailer.digest.body'
,
since:
@since
,
instance:
root_url
)
%>
<%=
raw
t
(
'notification_mailer.digest.body'
,
since:
l
(
@since
)
,
instance:
root_url
)
%>
<%
@notifications
.
each
do
|
notification
|
%>
*
<%=
raw
t
(
'notification_mailer.digest.mention'
,
name:
notification
.
from_account
.
acct
)
%>
...
...
This diff is collapsed.
Click to expand it.
spec/mailers/notification_mailer_spec.rb
+
61
−
9
View file @
f596a413
...
...
@@ -3,13 +3,28 @@ require "rails_helper"
RSpec
.
describe
NotificationMailer
,
type: :mailer
do
let
(
:receiver
)
{
Fabricate
(
:user
,
account:
Fabricate
(
:account
,
username:
'alice'
))
}
let
(
:sender
)
{
Fabricate
(
:account
,
username:
'bob'
)
}
let
(
:foreign_status
)
{
Fabricate
(
:status
,
account:
sender
)
}
let
(
:own_status
)
{
Fabricate
(
:status
,
account:
receiver
.
account
)
}
let
(
:foreign_status
)
{
Fabricate
(
:status
,
account:
sender
,
text:
'The body of the foreign status'
)
}
let
(
:own_status
)
{
Fabricate
(
:status
,
account:
receiver
.
account
,
text:
'The body of the own status'
)
}
shared_examples
'localized subject'
do
|*
args
,
**
kwrest
|
it
'renders subject localized for the locale of the receiver'
do
locale
=
I18n
.
available_locales
.
sample
receiver
.
update!
(
locale:
locale
)
expect
(
mail
.
subject
).
to
eq
I18n
.
t
(
*
args
,
kwrest
.
merge
(
locale:
locale
))
end
it
'renders subject localized for the default locale if the locale of the receiver is unavailable'
do
receiver
.
update!
(
locale:
nil
)
expect
(
mail
.
subject
).
to
eq
I18n
.
t
(
*
args
,
kwrest
.
merge
(
locale:
I18n
.
default_locale
))
end
end
describe
"mention"
do
let
(
:mention
)
{
Mention
.
create!
(
account:
receiver
.
account
,
status:
foreign_status
)
}
let
(
:mail
)
{
NotificationMailer
.
mention
(
receiver
.
account
,
Notification
.
create!
(
account:
receiver
.
account
,
activity:
mention
))
}
include_examples
'localized subject'
,
'notification_mailer.mention.subject'
,
name:
'bob'
it
"renders the headers"
do
expect
(
mail
.
subject
).
to
eq
(
"You were mentioned by bob"
)
expect
(
mail
.
to
).
to
eq
([
receiver
.
email
])
...
...
@@ -17,6 +32,7 @@ RSpec.describe NotificationMailer, type: :mailer do
it
"renders the body"
do
expect
(
mail
.
body
.
encoded
).
to
match
(
"You were mentioned by bob"
)
expect
(
mail
.
body
.
encoded
).
to
include
'The body of the foreign status'
end
end
...
...
@@ -24,6 +40,8 @@ RSpec.describe NotificationMailer, type: :mailer do
let
(
:follow
)
{
sender
.
follow!
(
receiver
.
account
)
}
let
(
:mail
)
{
NotificationMailer
.
follow
(
receiver
.
account
,
Notification
.
create!
(
account:
receiver
.
account
,
activity:
follow
))
}
include_examples
'localized subject'
,
'notification_mailer.follow.subject'
,
name:
'bob'
it
"renders the headers"
do
expect
(
mail
.
subject
).
to
eq
(
"bob is now following you"
)
expect
(
mail
.
to
).
to
eq
([
receiver
.
email
])
...
...
@@ -38,6 +56,8 @@ RSpec.describe NotificationMailer, type: :mailer do
let
(
:favourite
)
{
Favourite
.
create!
(
account:
sender
,
status:
own_status
)
}
let
(
:mail
)
{
NotificationMailer
.
favourite
(
own_status
.
account
,
Notification
.
create!
(
account:
receiver
.
account
,
activity:
favourite
))
}
include_examples
'localized subject'
,
'notification_mailer.favourite.subject'
,
name:
'bob'
it
"renders the headers"
do
expect
(
mail
.
subject
).
to
eq
(
"bob favourited your status"
)
expect
(
mail
.
to
).
to
eq
([
receiver
.
email
])
...
...
@@ -45,6 +65,7 @@ RSpec.describe NotificationMailer, type: :mailer do
it
"renders the body"
do
expect
(
mail
.
body
.
encoded
).
to
match
(
"Your status was favourited by bob"
)
expect
(
mail
.
body
.
encoded
).
to
include
'The body of the own status'
end
end
...
...
@@ -52,6 +73,8 @@ RSpec.describe NotificationMailer, type: :mailer do
let
(
:reblog
)
{
Status
.
create!
(
account:
sender
,
reblog:
own_status
)
}
let
(
:mail
)
{
NotificationMailer
.
reblog
(
own_status
.
account
,
Notification
.
create!
(
account:
receiver
.
account
,
activity:
reblog
))
}
include_examples
'localized subject'
,
'notification_mailer.reblog.subject'
,
name:
'bob'
it
"renders the headers"
do
expect
(
mail
.
subject
).
to
eq
(
"bob boosted your status"
)
expect
(
mail
.
to
).
to
eq
([
receiver
.
email
])
...
...
@@ -59,6 +82,7 @@ RSpec.describe NotificationMailer, type: :mailer do
it
"renders the body"
do
expect
(
mail
.
body
.
encoded
).
to
match
(
"Your status was boosted by bob"
)
expect
(
mail
.
body
.
encoded
).
to
include
'The body of the own status'
end
end
...
...
@@ -66,6 +90,8 @@ RSpec.describe NotificationMailer, type: :mailer do
let
(
:follow_request
)
{
Fabricate
(
:follow_request
,
account:
sender
,
target_account:
receiver
.
account
)
}
let
(
:mail
)
{
NotificationMailer
.
follow_request
(
receiver
.
account
,
Notification
.
create!
(
account:
receiver
.
account
,
activity:
follow_request
))
}
include_examples
'localized subject'
,
'notification_mailer.follow_request.subject'
,
name:
'bob'
it
'renders the headers'
do
expect
(
mail
.
subject
).
to
eq
(
'Pending follower: bob'
)
expect
(
mail
.
to
).
to
eq
([
receiver
.
email
])
...
...
@@ -78,18 +104,44 @@ RSpec.describe NotificationMailer, type: :mailer do
describe
'digest'
do
before
do
mention
=
Fabricate
(
:mention
,
account:
receiver
.
account
)
mention
=
Fabricate
(
:mention
,
account:
receiver
.
account
,
status:
foreign_status
)
Fabricate
(
:notification
,
account:
receiver
.
account
,
activity:
mention
)
sender
.
follow!
(
receiver
.
account
)
end
let
(
:mail
)
{
NotificationMailer
.
digest
(
receiver
.
account
,
since:
5
.
days
.
ago
)
}
it
'renders the headers'
do
expect
(
mail
.
subject
).
to
match
(
'notification since your last'
)
expect
(
mail
.
to
).
to
eq
([
receiver
.
email
])
context
do
let!
(
:mail
)
{
NotificationMailer
.
digest
(
receiver
.
account
,
since:
5
.
days
.
ago
)
}
include_examples
'localized subject'
,
'notification_mailer.digest.subject'
,
count:
1
,
name:
'bob'
it
'renders the headers'
do
expect
(
mail
.
subject
).
to
match
(
'notification since your last'
)
expect
(
mail
.
to
).
to
eq
([
receiver
.
email
])
end
it
'renders the body'
do
expect
(
mail
.
body
.
encoded
).
to
match
(
'brief summary'
)
expect
(
mail
.
body
.
encoded
).
to
include
'The body of the foreign status'
expect
(
mail
.
body
.
encoded
).
to
include
sender
.
username
end
end
it
'renders the body'
do
expect
(
mail
.
body
.
encoded
).
to
match
(
'brief summary'
)
it
'includes activities since the date specified by :since option'
do
receiver
.
update!
(
last_emailed_at:
'2000-02-01T00:00:00Z'
,
current_sign_in_at:
'2000-03-01T00:00:00Z'
)
mail
=
NotificationMailer
.
digest
(
receiver
.
account
,
since:
Time
.
parse
(
'2000-01-01T00:00:00Z'
))
expect
(
mail
.
body
.
encoded
).
to
include
'Jan 01, 2000, 00:00'
end
it
'includes activities since the receiver was last emailed if :since option is unavailable'
do
receiver
.
update!
(
last_emailed_at:
'2000-02-01T00:00:00Z'
,
current_sign_in_at:
'2000-03-01T00:00:00Z'
)
mail
=
NotificationMailer
.
digest
(
receiver
.
account
)
expect
(
mail
.
body
.
encoded
).
to
include
'Feb 01, 2000, 00:00'
end
it
'includes activities since the receiver last signed in if :since option and the last emailed date are unavailable'
do
receiver
.
update!
(
last_emailed_at:
nil
,
current_sign_in_at:
'2000-03-01T00:00:00Z'
)
mail
=
NotificationMailer
.
digest
(
receiver
.
account
)
expect
(
mail
.
body
.
encoded
).
to
include
'Mar 01, 2000, 00:00'
end
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment