Merge branch 'master' into fix_whisper

This commit is contained in:
Sam
2016-12-02 17:44:05 +11:00
40 changed files with 322 additions and 210 deletions

View File

@@ -48,8 +48,9 @@ describe ActiveRecord::ConnectionHandling do
end
it 'should failover to a replica server' do
current_threads = Thread.list
RailsMultisite::ConnectionManagement.stubs(:all_dbs).returns(['default', multisite_db])
::PostgreSQLFallbackHandler.instance.setup!
[config, multisite_config].each do |configuration|
ActiveRecord::Base.expects(:postgresql_connection).with(configuration).raises(PG::ConnectionBad)
@@ -60,7 +61,7 @@ describe ActiveRecord::ConnectionHandling do
})).returns(@replica_connection)
end
expect(postgresql_fallback_handler.master).to eq(true)
expect(postgresql_fallback_handler.master_down?).to eq(nil)
expect { ActiveRecord::Base.postgresql_fallback_connection(config) }
.to raise_error(PG::ConnectionBad)
@@ -68,10 +69,10 @@ describe ActiveRecord::ConnectionHandling do
expect{ ActiveRecord::Base.postgresql_fallback_connection(config) }
.to change{ Discourse.readonly_mode? }.from(false).to(true)
expect(postgresql_fallback_handler.master).to eq(false)
expect(postgresql_fallback_handler.master_down?).to eq(true)
with_multisite_db(multisite_db) do
expect(postgresql_fallback_handler.master).to eq(true)
expect(postgresql_fallback_handler.master_down?).to eq(nil)
expect { ActiveRecord::Base.postgresql_fallback_connection(multisite_config) }
.to raise_error(PG::ConnectionBad)
@@ -79,30 +80,18 @@ describe ActiveRecord::ConnectionHandling do
expect{ ActiveRecord::Base.postgresql_fallback_connection(multisite_config) }
.to change{ Discourse.readonly_mode? }.from(false).to(true)
expect(postgresql_fallback_handler.master).to eq(false)
expect(postgresql_fallback_handler.master_down?).to eq(true)
end
postgresql_fallback_handler.master_up(multisite_db)
ActiveRecord::Base.unstub(:postgresql_connection)
current_threads = Thread.list
expect{ ActiveRecord::Base.connection_pool.checkout }
.to change{ Thread.list.size }.by(1)
# Ensure that we don't try to connect back to the replica when a thread
# is running
begin
ActiveRecord::Base.postgresql_fallback_connection(config)
rescue PG::ConnectionBad => e
# This is expected if the thread finishes before the above is called.
end
# Wait for the thread to finish execution
(Thread.list - current_threads).each(&:join)
postgresql_fallback_handler.initiate_fallback_to_master
expect(Discourse.readonly_mode?).to eq(false)
expect(PostgreSQLFallbackHandler.instance.master).to eq(true)
expect(postgresql_fallback_handler.master_down?).to eq(nil)
expect(ActiveRecord::Base.connection_pool.connections.count).to eq(0)

View File

@@ -383,6 +383,39 @@ describe Email::Receiver do
expect(Post.last.raw).to match(/discourse\.rb/)
end
it "handles forwarded emails" do
SiteSetting.enable_forwarded_emails = true
expect { process(:forwarded_email_1) }.to change(Topic, :count)
forwarded_post, last_post = *Post.last(2)
expect(forwarded_post.user.email).to eq("some@one.com")
expect(last_post.user.email).to eq("ba@bar.com")
expect(forwarded_post.raw).to match(/XoXo/)
expect(last_post.raw).to match(/can you have a look at this email below/)
expect(last_post.post_type).to eq(Post.types[:regular])
end
it "handles weirdly forwarded emails" do
group.add(Fabricate(:user, email: "ba@bar.com"))
group.save
SiteSetting.enable_forwarded_emails = true
expect { process(:forwarded_email_2) }.to change(Topic, :count)
forwarded_post, last_post = *Post.last(2)
expect(forwarded_post.user.email).to eq("some@one.com")
expect(last_post.user.email).to eq("ba@bar.com")
expect(forwarded_post.raw).to match(/XoXo/)
expect(last_post.raw).to match(/can you have a look at this email below/)
expect(last_post.post_type).to eq(Post.types[:whisper])
end
end
context "new topic in a category" do

View File

@@ -0,0 +1,18 @@
Message-ID: <58@foo.bar.mail>
From: Ba Bar <ba@bar.com>
To: Team <team@bar.com>
Date: Mon, 1 Dec 2016 13:37:42 +0100
Subject: FW: Discoursing much?
@team, can you have a look at this email below?
From: Some One <some@one.com>
To: Ba Bar <ba@bar.com>
Date: Mon, 1 Dec 2016 00:13:37 +0100
Subject: Discoursing much?
Hello Ba Bar,
Discoursing much today?
XoXo

View File

@@ -0,0 +1,18 @@
Message-ID: <59@foo.bar.mail>
From: Ba Bar <ba@bar.com>
To: Team <team@bar.com>
Date: Mon, 1 Dec 2016 13:37:42 +0100
Subject: Re: Discoursing much?
@team, can you have a look at this email below?
From: Some One [mailto:some@one.com]
To: Ba Bar <ba@bar.com>
Date: Mon, 1 Dec 2016 00:13:37 +0100
Subject: Discoursing much?
Hello Ba Bar,
Discoursing much today?
XoXo

View File

@@ -155,8 +155,7 @@ describe UserNotifications do
context "with new topics" do
before do
Topic.stubs(:for_digest).returns([Fabricate(:topic, user: Fabricate(:coding_horror))])
Topic.stubs(:new_since_last_seen).returns(Topic.none)
Fabricate(:topic, user: Fabricate(:coding_horror))
end
it "works" do
@@ -184,6 +183,28 @@ describe UserNotifications do
expect(html).to_not include deleted.title
expect(html).to_not include post.raw
end
it "excludes whispers and other post types that don't belong" do
t = Fabricate(:topic, user: Fabricate(:user), title: "Who likes the same stuff I like?")
whisper = Fabricate(:post, topic: t, score: 100.0, post_number: 2, raw: "You like weird stuff", post_type: Post.types[:whisper])
mod_action = Fabricate(:post, topic: t, score: 100.0, post_number: 3, raw: "This topic unlisted", post_type: Post.types[:moderator_action])
small_action = Fabricate(:post, topic: t, score: 100.0, post_number: 4, raw: "A small action", post_type: Post.types[:small_action])
html = subject.html_part.body.to_s
expect(html).to_not include whisper.raw
expect(html).to_not include mod_action.raw
expect(html).to_not include small_action.raw
end
it "excludes deleted and hidden posts" do
t = Fabricate(:topic, user: Fabricate(:user), title: "Post objectionable stuff here")
deleted = Fabricate(:post, topic: t, score: 100.0, post_number: 2, raw: "This post is uncalled for", deleted_at: 5.minutes.ago)
hidden = Fabricate(:post, topic: t, score: 100.0, post_number: 3, raw: "Try to find this post", hidden: true, hidden_at: 5.minutes.ago, hidden_reason_id: Post.hidden_reasons[:flagged_by_tl3_user])
user_deleted = Fabricate(:post, topic: t, score: 100.0, post_number: 4, raw: "I regret this post", user_deleted: true)
html = subject.html_part.body.to_s
expect(html).to_not include deleted.raw
expect(html).to_not include hidden.raw
expect(html).to_not include user_deleted.raw
end
end
end

View File

@@ -15,9 +15,15 @@ describe QuotedPost do
post1 = Fabricate(:post)
post2 = Fabricate(:post)
post2.cooked = <<HTML
<aside class="quote" data-post="#{post1.post_number}" data-topic="#{post1.topic_id}"><div class="title"><div class="quote-controls"></div><img width="20" height="20" src="/user_avatar/meta.discourse.org/techapj/20/3281.png" class="avatar">techAPJ:</div><blockquote><p>When the user will v</p></blockquote></aside>
HTML
post2.cooked = <<-HTML
<aside class="quote" data-post="#{post1.post_number}" data-topic="#{post1.topic_id}">
<div class="title">
<div class="quote-controls"></div>
<img width="20" height="20" src="/user_avatar/meta.discourse.org/techapj/20/3281.png" class="avatar">techAPJ:
</div>
<blockquote><p>When the user will v</p></blockquote>
</aside>
HTML
QuotedPost.create!(post_id: post2.id, quoted_post_id: 999)