Remove limited content from email notifications
This commit is contained in:
parent
731adffa78
commit
fe6052865c
4 changed files with 45 additions and 19 deletions
|
|
@ -4,7 +4,9 @@ module NotifierHelper
|
|||
# @param opts [Hash] Optional hash. Accepts :length parameters.
|
||||
# @return [String] The truncated and formatted post.
|
||||
def post_message(post, opts={})
|
||||
if post.respond_to? :message
|
||||
if !post.public?
|
||||
I18n.translate 'notifier.a_private_message'
|
||||
elsif post.respond_to? :message
|
||||
post.message.plain_text_without_markdown truncate: opts.fetch(:length, 200)
|
||||
else
|
||||
I18n.translate 'notifier.a_post_you_shared'
|
||||
|
|
@ -15,6 +17,10 @@ module NotifierHelper
|
|||
# @param opts [Hash] Optional hash. Accepts :length parameters.
|
||||
# @return [String] The truncated and formatted comment.
|
||||
def comment_message(comment, opts={})
|
||||
comment.message.plain_text_without_markdown truncate: opts.fetch(:length, 600)
|
||||
if comment.post.public?
|
||||
comment.message.plain_text_without_markdown truncate: opts.fetch(:length, 600)
|
||||
else
|
||||
I18n.translate 'notifier.a_limited_post_comment'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -731,6 +731,8 @@ en:
|
|||
|
||||
notifier:
|
||||
a_post_you_shared: "a post."
|
||||
a_private_message: "There's a new private message in diaspora* for you to check out."
|
||||
a_limited_post_comment: "There's a new comment on a limited post in diaspora* for you to check out."
|
||||
email_sent_by_diaspora: "This email was sent by %{pod_name}. If you'd like to stop getting emails like this,"
|
||||
click_here: "click here"
|
||||
hello: "Hello %{name}!"
|
||||
|
|
|
|||
|
|
@ -8,12 +8,14 @@ describe NotifierHelper, :type => :helper do
|
|||
describe '#post_message' do
|
||||
before do
|
||||
# post for truncate test
|
||||
@post = FactoryGirl.create(:status_message, text: "hi dude! "*10)
|
||||
@post = FactoryGirl.create(:status_message, text: "hi dude! "*10, public: true)
|
||||
@truncated_post = "hi dude! hi dude! hi dude! hi dude! hi dude! hi dude! hi dude! hi dude! hi du..."
|
||||
# post for markdown test
|
||||
@markdown_post = FactoryGirl.create(:status_message,
|
||||
text: "[link](http://diasporafoundation.org) **bold text** *other text*")
|
||||
text: "[link](http://diasporafoundation.org) **bold text** *other text*", public: true)
|
||||
@striped_markdown_post = "link (http://diasporafoundation.org) bold text other text"
|
||||
|
||||
@limited_post = FactoryGirl.create(:status_message, text: "This is top secret post. Shhhhhhhh!!!", public: false)
|
||||
end
|
||||
|
||||
it 'truncates in the post' do
|
||||
|
|
@ -25,6 +27,10 @@ describe NotifierHelper, :type => :helper do
|
|||
opts = {:length => @markdown_post.text.length}
|
||||
expect(post_message(@markdown_post, opts)).to eq(@striped_markdown_post)
|
||||
end
|
||||
|
||||
it 'hides the private content' do
|
||||
expect(post_message(@limited_post)).not_to include("secret post")
|
||||
end
|
||||
end
|
||||
|
||||
describe '#comment_message' do
|
||||
|
|
@ -32,11 +38,19 @@ describe NotifierHelper, :type => :helper do
|
|||
# comment for truncate test
|
||||
@comment = FactoryGirl.create(:comment)
|
||||
@comment.text = "hi dude! "*10
|
||||
@comment.post.public = true
|
||||
@truncated_comment = "hi dude! hi dude! hi dude! hi dude! hi dude! hi dude! hi dude! hi dude! hi d..."
|
||||
|
||||
# comment for markdown test
|
||||
@markdown_comment = FactoryGirl.create(:comment)
|
||||
@markdown_comment.post.public = true
|
||||
@markdown_comment.text = "[link](http://diasporafoundation.org) **bold text** *other text*"
|
||||
@striped_markdown_comment = "link (http://diasporafoundation.org) bold text other text"
|
||||
|
||||
# comment for limited post
|
||||
@limited_comment = FactoryGirl.create(:comment)
|
||||
@limited_comment.post.public = false
|
||||
@limited_comment.text = "This is top secret comment. Shhhhhhhh!!!"
|
||||
end
|
||||
|
||||
it 'truncates in the comment' do
|
||||
|
|
@ -48,5 +62,9 @@ describe NotifierHelper, :type => :helper do
|
|||
opts = {:length => @markdown_comment.text.length}
|
||||
expect(comment_message(@markdown_comment, opts)).to eq(@striped_markdown_comment)
|
||||
end
|
||||
|
||||
it 'hides the private content' do
|
||||
expect(comment_message(@limited_comment)).not_to include("secret comment")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -82,10 +82,10 @@ describe Notifier, :type => :mailer do
|
|||
describe ".mentioned" do
|
||||
before do
|
||||
@user = alice
|
||||
@sm = FactoryGirl.create(:status_message)
|
||||
@m = Mention.create(:person => @user.person, :post=> @sm)
|
||||
@post = FactoryGirl.create(:status_message, public: true)
|
||||
@mention = Mention.create(:person => @user.person, :post => @post)
|
||||
|
||||
@mail = Notifier.mentioned(@user.id, @sm.author.id, @m.id)
|
||||
@mail = Notifier.mentioned(@user.id, @post.author.id, @mention.id)
|
||||
end
|
||||
|
||||
it 'TO: goes to the right person' do
|
||||
|
|
@ -93,11 +93,11 @@ describe Notifier, :type => :mailer do
|
|||
end
|
||||
|
||||
it 'SUBJECT: has the name of person mentioning in the subject' do
|
||||
expect(@mail.subject).to include(@sm.author.name)
|
||||
expect(@mail.subject).to include(@post.author.name)
|
||||
end
|
||||
|
||||
it 'has the post text in the body' do
|
||||
expect(@mail.body.encoded).to include(@sm.text)
|
||||
expect(@mail.body.encoded).to include(@post.text)
|
||||
end
|
||||
|
||||
it 'should not include translation fallback' do
|
||||
|
|
@ -107,8 +107,8 @@ describe Notifier, :type => :mailer do
|
|||
|
||||
describe ".liked" do
|
||||
before do
|
||||
@sm = FactoryGirl.create(:status_message, :author => alice.person)
|
||||
@like = @sm.likes.create!(:author => bob.person)
|
||||
@post = FactoryGirl.create(:status_message, :author => alice.person, :public => true)
|
||||
@like = @post.likes.create!(:author => bob.person)
|
||||
@mail = Notifier.liked(alice.id, @like.author.id, @like.id)
|
||||
end
|
||||
|
||||
|
|
@ -117,7 +117,7 @@ describe Notifier, :type => :mailer do
|
|||
end
|
||||
|
||||
it 'BODY: contains the truncated original post' do
|
||||
expect(@mail.body.encoded).to include(@sm.message.plain_text)
|
||||
expect(@mail.body.encoded).to include(@post.message.plain_text)
|
||||
end
|
||||
|
||||
it 'BODY: contains the name of person liking' do
|
||||
|
|
@ -137,8 +137,8 @@ describe Notifier, :type => :mailer do
|
|||
|
||||
describe ".reshared" do
|
||||
before do
|
||||
@sm = FactoryGirl.create(:status_message, :author => alice.person, :public => true)
|
||||
@reshare = FactoryGirl.create(:reshare, :root => @sm, :author => bob.person)
|
||||
@post = FactoryGirl.create(:status_message, :author => alice.person, :public => true)
|
||||
@reshare = FactoryGirl.create(:reshare, :root => @post, :author => bob.person)
|
||||
@mail = Notifier.reshared(alice.id, @reshare.author.id, @reshare.id)
|
||||
end
|
||||
|
||||
|
|
@ -147,7 +147,7 @@ describe Notifier, :type => :mailer do
|
|||
end
|
||||
|
||||
it 'BODY: contains the truncated original post' do
|
||||
expect(@mail.body.encoded).to include(@sm.message.plain_text)
|
||||
expect(@mail.body.encoded).to include(@post.message.plain_text)
|
||||
end
|
||||
|
||||
it 'BODY: contains the name of person liking' do
|
||||
|
|
@ -196,8 +196,8 @@ describe Notifier, :type => :mailer do
|
|||
expect(@mail.subject).to eq("Re: #{@cnv.subject}")
|
||||
end
|
||||
|
||||
it 'BODY: contains the message text' do
|
||||
expect(@mail.body.encoded).to include(@cnv.messages.first.text)
|
||||
it 'BODY: does not contain the message text' do
|
||||
expect(@mail.body.encoded).not_to include(@cnv.messages.first.text)
|
||||
end
|
||||
|
||||
it 'should not include translation fallback' do
|
||||
|
|
@ -206,7 +206,7 @@ describe Notifier, :type => :mailer do
|
|||
end
|
||||
|
||||
context "comments" do
|
||||
let(:commented_post) {bob.post(:status_message, :text => "### Headline \r\n It's **really** sunny outside today, and this is a super long status message! #notreally", :to => :all)}
|
||||
let(:commented_post) {bob.post(:status_message, :text => "### Headline \r\n It's **really** sunny outside today, and this is a super long status message! #notreally", :to => :all, :public => true)}
|
||||
let(:comment) { eve.comment!(commented_post, "Totally is")}
|
||||
|
||||
describe ".comment_on_post" do
|
||||
|
|
@ -271,7 +271,7 @@ describe Notifier, :type => :mailer do
|
|||
end
|
||||
|
||||
it "contains the original post's link" do
|
||||
expect(comment_mail.body.encoded.include?("#{comment.post.id.to_s}")).to be true
|
||||
expect(comment_mail.body.encoded).to include("#{comment.post.id.to_s}")
|
||||
end
|
||||
|
||||
it 'should not include translation fallback' do
|
||||
|
|
|
|||
Loading…
Reference in a new issue