diff options
author | Benjamin Neff <benjamin@coding4coffee.ch> | 2022-07-16 05:44:59 +0300 |
---|---|---|
committer | Benjamin Neff <benjamin@coding4coffee.ch> | 2022-07-16 05:44:59 +0300 |
commit | 5669ba6b48f2488e394789bc6fb8504358e966b7 (patch) | |
tree | d6a9e81d424f3e3003262de74a7fcbb40a995751 /spec | |
parent | c6dda6cf2d776eb1be2ba02a554c2ea1fc4131a4 (diff) | |
parent | a5e5c7f3782e83d527b9b28a0e8f46fb1f83389b (diff) |
Merge branch 'next-minor' into develop
Diffstat (limited to 'spec')
-rw-r--r-- | spec/helpers/notifier_helper_spec.rb | 28 | ||||
-rw-r--r-- | spec/helpers/people_helper_spec.rb | 2 | ||||
-rw-r--r-- | spec/lib/diaspora/mentionable_spec.rb | 10 | ||||
-rw-r--r-- | spec/lib/diaspora/message_renderer_spec.rb | 8 | ||||
-rw-r--r-- | spec/mailers/notifier_spec.rb | 40 | ||||
-rw-r--r-- | spec/workers/reset_password_spec.rb | 4 |
6 files changed, 32 insertions, 60 deletions
diff --git a/spec/helpers/notifier_helper_spec.rb b/spec/helpers/notifier_helper_spec.rb index c4d5a4c6e..77eb2a1dc 100644 --- a/spec/helpers/notifier_helper_spec.rb +++ b/spec/helpers/notifier_helper_spec.rb @@ -5,18 +5,23 @@ # the COPYRIGHT file. describe NotifierHelper, :type => :helper do - describe '#post_message' do + describe "#post_message" do before do # post for markdown test @markdown_post = FactoryBot.create(:status_message, - text: "[link](http://diasporafoundation.org) **bold text** *other text*", public: true) - @striped_markdown_post = "link (http://diasporafoundation.org) bold text other text" + text: "[link](https://diasporafoundation.org) **bold text** *other text*", + public: true) + @striped_markdown_post = "link (https://diasporafoundation.org) bold text other text" end - it 'strip markdown in the post' do + it "strip markdown in the post" do expect(post_message(@markdown_post)).to eq(@striped_markdown_post) end + it "renders markdown as html" do + expect(post_message(@markdown_post, html: true)).to include("<a href=\"https://diasporafoundation.org\">link</a>") + end + it "falls back to the title if the post has no text" do photo = FactoryBot.build(:photo, public: true) photo_post = FactoryBot.build(:status_message, author: photo.author, text: "", photos: [photo], public: true) @@ -32,13 +37,13 @@ describe NotifierHelper, :type => :helper do end end - describe '#comment_message' do + describe "#comment_message" do before do # comment for markdown test @markdown_comment = FactoryBot.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" + @markdown_comment.text = "[link](https://diasporafoundation.org) **bold text** *other text*" + @striped_markdown_comment = "link (https://diasporafoundation.org) bold text other text" # comment for limited post @limited_comment = FactoryBot.create(:comment) @@ -46,11 +51,16 @@ describe NotifierHelper, :type => :helper do @limited_comment.text = "This is top secret comment. Shhhhhhhh!!!" end - it 'strip markdown in the comment' do + it "strip markdown in the comment" do expect(comment_message(@markdown_comment)).to eq(@striped_markdown_comment) end - it 'hides the private content' do + it "renders markdown as html" do + expect(comment_message(@markdown_comment, html: true)) + .to include("<a href=\"https://diasporafoundation.org\">link</a>") + end + + it "hides the private content" do expect(comment_message(@limited_comment)).not_to include("secret comment") end end diff --git a/spec/helpers/people_helper_spec.rb b/spec/helpers/people_helper_spec.rb index 12ab56230..7c36e176c 100644 --- a/spec/helpers/people_helper_spec.rb +++ b/spec/helpers/people_helper_spec.rb @@ -75,7 +75,7 @@ describe PeopleHelper, :type => :helper do end it 'links by id for a local user' do - expect(person_link(@user.person)).to include "href='#{person_path(@user.person)}'" + expect(person_link(@user.person)).to include "href=\"#{person_path(@user.person)}\"" end it "recognizes the 'display_name' option" do diff --git a/spec/lib/diaspora/mentionable_spec.rb b/spec/lib/diaspora/mentionable_spec.rb index 63a065ed5..174bb8de3 100644 --- a/spec/lib/diaspora/mentionable_spec.rb +++ b/spec/lib/diaspora/mentionable_spec.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true describe Diaspora::Mentionable do - include PeopleHelper - let(:people) { [alice, bob, eve].map(&:person) } let(:names) { %w(Alice\ A Bob\ B "Eve>\ E) } @@ -41,7 +39,9 @@ STR end describe ".format" do - context "html output" do + context "html output", type: :helper do + include PeopleHelper + it "adds the links to the formatted message" do fmt_msg = Diaspora::Mentionable.format(test_text_with_names, people) @@ -75,7 +75,7 @@ STR fmt_msg = Diaspora::Mentionable.format(test_txt, people) expect(fmt_msg).not_to include(name) - expect(fmt_msg).to include(">", "<", "'") # ">", "<", "'" + expect(fmt_msg).to include("</a><script>alert('h')</script>") end end @@ -184,7 +184,7 @@ STR user_a.aspects.where(name: "generic").first.contacts.map(&:person_id) ) - expect(txt).to include("@[user C](#{local_or_remote_person_path(user_c.person)}") + expect(txt).to include("@[user C](#{Rails.application.routes.url_helpers.person_path(user_c.person)}") expect(txt).not_to include("href") expect(txt).not_to include(mention) end diff --git a/spec/lib/diaspora/message_renderer_spec.rb b/spec/lib/diaspora/message_renderer_spec.rb index 9f2cea726..a9a12e85b 100644 --- a/spec/lib/diaspora/message_renderer_spec.rb +++ b/spec/lib/diaspora/message_renderer_spec.rb @@ -78,12 +78,6 @@ describe Diaspora::MessageRenderer do end context 'linking all mentions' do - it 'makes plain links for people not in the post aspects' do - message = message("@{Bob; #{bob.person.diaspora_handle}}", link_all_mentions: true).html - expect(message).to_not include 'hovercard' - expect(message).to include '/u/bob' - end - it "makes no hovercards if they're disabled" do message = message( "@{Bob; #{bob.person.diaspora_handle}}", @@ -91,7 +85,7 @@ describe Diaspora::MessageRenderer do disable_hovercards: true ).html expect(message).to_not include 'hovercard' - expect(message).to include '/u/bob' + expect(message).to include AppConfig.url_to("/people/#{bob.person.guid}") end end end diff --git a/spec/mailers/notifier_spec.rb b/spec/mailers/notifier_spec.rb index 542a75275..0f4a13f7b 100644 --- a/spec/mailers/notifier_spec.rb +++ b/spec/mailers/notifier_spec.rb @@ -121,10 +121,6 @@ describe Notifier, type: :mailer do it "has the post text in the body" do expect(@mail.body.encoded).to include(@post.text) end - - it "should not include translation fallback" do - expect(@mail.body.encoded).not_to include(I18n.translate "notifier.a_post_you_shared") - end end describe ".mentioned_in_comment" do @@ -180,10 +176,6 @@ describe Notifier, type: :mailer do it "has the post text not in the body" do expect(@mail.body.encoded).not_to include(@post.text) end - - it "should not include translation fallback" do - expect(@mail.body.encoded).not_to include(I18n.translate "notifier.a_post_you_shared") - end end describe ".liked" do @@ -205,10 +197,6 @@ describe Notifier, type: :mailer do expect(@mail.body.encoded).to include(@like.author.name) end - it "should not include translation fallback" do - expect(@mail.body.encoded).not_to include(I18n.translate "notifier.a_post_you_shared") - end - it "can handle a reshare" do reshare = FactoryBot.create(:reshare) like = reshare.likes.create!(author: bob.person) @@ -247,10 +235,6 @@ describe Notifier, type: :mailer do it "BODY: contains the name of person liking" do expect(@mail.body.encoded).to include(@reshare.author.name) end - - it "should not include translation fallback" do - expect(@mail.body.encoded).not_to include(I18n.translate "notifier.a_post_you_shared") - end end describe ".private_message" do @@ -294,10 +278,6 @@ describe Notifier, type: :mailer do 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 - expect(@mail.body.encoded).not_to include(I18n.translate "notifier.a_post_you_shared") - end end context "comments" do @@ -334,10 +314,6 @@ describe Notifier, type: :mailer do it "contains the original post's link with comment anchor" do expect(comment_mail.body.encoded).to include("#{comment.post.id}##{comment.guid}") end - - it "should not include translation fallback" do - expect(comment_mail.body.encoded).not_to include(I18n.translate "notifier.a_post_you_shared") - end end [:reshare].each do |post_type| @@ -380,10 +356,6 @@ describe Notifier, type: :mailer do it "contains the original post's link with comment anchor" do expect(comment_mail.body.encoded).to include("#{comment.post.id}##{comment.guid}") end - - it "should not include translation fallback" do - expect(comment_mail.body.encoded).not_to include(I18n.translate "notifier.a_post_you_shared") - end end [:reshare].each do |post_type| context post_type.to_s do @@ -490,10 +462,6 @@ describe Notifier, type: :mailer do it "BODY: contains the name of person liking" do expect(mail.body.encoded).to include(bob.name) end - - it "should not include translation fallback" do - expect(mail.body.encoded).not_to include(I18n.translate "notifier.a_post_you_shared") - end end end @@ -580,16 +548,16 @@ describe Notifier, type: :mailer do it "has some informative text in the body" do email.body.parts.each do |part| - expect(part.decoded).to include("https://www.owasp.org/index.php/Cross-Site_Request_Forgery_(CSRF)") + expect(part.decoded).to include("https://owasp.org/www-community/attacks/csrf") end end end describe "hashtags" do it "escapes hashtags" do - mails = Notifier.admin("#Welcome to bureaucracy!", [bob]) - expect(mails.length).to eq(1) - mail = mails.first + status = FactoryBot.create(:status_message, author: alice.person, text: "#Welcome to bureaucracy!", public: true) + like = status.likes.create!(author: bob.person) + mail = Notifier.send_notification("liked", alice.id, like.author.id, like.id) expect(mail.body.encoded).to match( "<p><a href=\"#{AppConfig.url_to(tag_path('welcome'))}\">#Welcome</a> to bureaucracy!</p>" ) diff --git a/spec/workers/reset_password_spec.rb b/spec/workers/reset_password_spec.rb index 6d1b7ca72..59c5cca79 100644 --- a/spec/workers/reset_password_spec.rb +++ b/spec/workers/reset_password_spec.rb @@ -12,8 +12,8 @@ describe Workers::ResetPassword do Workers::ResetPassword.new.perform(alice.id) mail = Devise.mailer.deliveries.last expect(mail.to).to eq([alice.email]) - expect(mail.body).to include("change your password") - expect(mail.body).to include(alice.username) + expect(mail.body.encoded).to include("change your password") + expect(mail.body.encoded).to include(alice.username) end end end |