Merge pull request #4599 from tgxworld/remove_rspec_given
Remove RSpec given.
This commit is contained in:
commit
20f9aad539
2
Gemfile
2
Gemfile
|
@ -138,8 +138,6 @@ group :test, :development do
|
|||
gem 'rb-inotify', '~> 0.9', require: RUBY_PLATFORM =~ /linux/i ? 'rb-inotify' : false
|
||||
gem 'rspec-rails', require: false
|
||||
gem 'shoulda', require: false
|
||||
gem 'simplecov', require: false
|
||||
gem 'rspec-given'
|
||||
gem 'rspec-html-matchers'
|
||||
gem 'spork-rails'
|
||||
gem 'pry-nav'
|
||||
|
|
16
Gemfile.lock
16
Gemfile.lock
|
@ -77,7 +77,6 @@ GEM
|
|||
discourse-qunit-rails (0.0.9)
|
||||
railties
|
||||
discourse_fastimage (2.0.3)
|
||||
docile (1.1.5)
|
||||
domain_name (0.5.25)
|
||||
unf (>= 0.0.5, < 1.0.0)
|
||||
email_reply_trimmer (0.1.6)
|
||||
|
@ -115,8 +114,6 @@ GEM
|
|||
thor (~> 0.19.1)
|
||||
fspath (2.1.1)
|
||||
gctools (0.2.3)
|
||||
given_core (3.7.1)
|
||||
sorcerer (>= 0.3.7)
|
||||
globalid (0.3.7)
|
||||
activesupport (>= 4.1.0)
|
||||
guess_html_encoding (0.0.11)
|
||||
|
@ -300,9 +297,6 @@ GEM
|
|||
rspec-expectations (3.4.0)
|
||||
diff-lcs (>= 1.2.0, < 2.0)
|
||||
rspec-support (~> 3.4.0)
|
||||
rspec-given (3.7.1)
|
||||
given_core (= 3.7.1)
|
||||
rspec (>= 2.14.0)
|
||||
rspec-html-matchers (0.7.0)
|
||||
nokogiri (~> 1)
|
||||
rspec (~> 3)
|
||||
|
@ -340,7 +334,7 @@ GEM
|
|||
shoulda (3.5.0)
|
||||
shoulda-context (~> 1.0, >= 1.0.1)
|
||||
shoulda-matchers (>= 1.4.1, < 3.0)
|
||||
shoulda-context (1.2.1)
|
||||
shoulda-context (1.2.2)
|
||||
shoulda-matchers (2.8.0)
|
||||
activesupport (>= 3.0.0)
|
||||
sidekiq (4.2.4)
|
||||
|
@ -351,17 +345,11 @@ GEM
|
|||
sidekiq-statistic (1.2.0)
|
||||
sidekiq (>= 3.3.4, < 5)
|
||||
simple-rss (1.3.1)
|
||||
simplecov (0.11.1)
|
||||
docile (~> 1.1.0)
|
||||
json (~> 1.8)
|
||||
simplecov-html (~> 0.10.0)
|
||||
simplecov-html (0.10.0)
|
||||
sinatra (1.4.6)
|
||||
rack (~> 1.4)
|
||||
rack-protection (~> 1.4)
|
||||
tilt (>= 1.3, < 3)
|
||||
slop (3.6.0)
|
||||
sorcerer (1.0.2)
|
||||
spork (1.0.0rc4)
|
||||
spork-rails (4.0.0)
|
||||
rails (>= 3.0.0, < 5)
|
||||
|
@ -475,7 +463,6 @@ DEPENDENCIES
|
|||
rinku
|
||||
rmmseg-cpp
|
||||
rspec
|
||||
rspec-given
|
||||
rspec-html-matchers
|
||||
rspec-rails
|
||||
rtlit
|
||||
|
@ -488,7 +475,6 @@ DEPENDENCIES
|
|||
sidekiq
|
||||
sidekiq-statistic
|
||||
simple-rss
|
||||
simplecov
|
||||
sinatra
|
||||
spork-rails
|
||||
stackprof
|
||||
|
|
|
@ -80,19 +80,19 @@ describe Email::Sender do
|
|||
context "doesn't add return_path when no plus addressing" do
|
||||
before { SiteSetting.reply_by_email_address = '%{reply_key}@test.com' }
|
||||
|
||||
When { email_sender.send }
|
||||
Then {
|
||||
it 'should not set the return_path' do
|
||||
email_sender.send
|
||||
expect(message.header[:return_path].to_s).to eq("")
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
context "adds return_path with plus addressing" do
|
||||
before { SiteSetting.reply_by_email_address = 'replies+%{reply_key}@test.com' }
|
||||
|
||||
When { email_sender.send }
|
||||
Then {
|
||||
it 'should set the return_path' do
|
||||
email_sender.send
|
||||
expect(message.header[:return_path].to_s).to eq("replies+verp-#{EmailLog.last.bounce_key}@test.com")
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
context "adds a List-ID header to identify the forum" do
|
||||
|
@ -102,14 +102,21 @@ describe Email::Sender do
|
|||
message.header['X-Discourse-Topic-Id'] = topic.id
|
||||
end
|
||||
|
||||
When { email_sender.send }
|
||||
Then { expect(message.header['List-ID']).to be_present }
|
||||
Then { expect(message.header['List-ID'].to_s).to match('name-with-space') }
|
||||
it 'should add the right header' do
|
||||
email_sender.send
|
||||
|
||||
expect(message.header['List-ID']).to be_present
|
||||
expect(message.header['List-ID'].to_s).to match('name-with-space')
|
||||
end
|
||||
end
|
||||
|
||||
context "adds a Message-ID header even when topic id is not present" do
|
||||
When { email_sender.send }
|
||||
Then { expect(message.header['Message-ID']).to be_present }
|
||||
|
||||
it 'should add the right header' do
|
||||
email_sender.send
|
||||
|
||||
expect(message.header['Message-ID']).to be_present
|
||||
end
|
||||
end
|
||||
|
||||
context "adds Precedence header" do
|
||||
|
@ -117,8 +124,10 @@ describe Email::Sender do
|
|||
message.header['X-Discourse-Topic-Id'] = 5577
|
||||
end
|
||||
|
||||
When { email_sender.send }
|
||||
Then { expect(message.header['Precedence']).to be_present }
|
||||
it 'should add the right header' do
|
||||
email_sender.send
|
||||
expect(message.header['Precedence']).to be_present
|
||||
end
|
||||
end
|
||||
|
||||
context "removes custom Discourse headers from topic notification mails" do
|
||||
|
@ -126,17 +135,21 @@ describe Email::Sender do
|
|||
message.header['X-Discourse-Topic-Id'] = 5577
|
||||
end
|
||||
|
||||
When { email_sender.send }
|
||||
Then { expect(message.header['X-Discourse-Topic-Id']).not_to be_present }
|
||||
Then { expect(message.header['X-Discourse-Post-Id']).not_to be_present }
|
||||
Then { expect(message.header['X-Discourse-Reply-Key']).not_to be_present }
|
||||
it 'should remove the right headers' do
|
||||
email_sender.send
|
||||
expect(message.header['X-Discourse-Topic-Id']).not_to be_present
|
||||
expect(message.header['X-Discourse-Post-Id']).not_to be_present
|
||||
expect(message.header['X-Discourse-Reply-Key']).not_to be_present
|
||||
end
|
||||
end
|
||||
|
||||
context "removes custom Discourse headers from digest/registration/other mails" do
|
||||
When { email_sender.send }
|
||||
Then { expect(message.header['X-Discourse-Topic-Id']).not_to be_present }
|
||||
Then { expect(message.header['X-Discourse-Post-Id']).not_to be_present }
|
||||
Then { expect(message.header['X-Discourse-Reply-Key']).not_to be_present }
|
||||
it 'should remove the right headers' do
|
||||
email_sender.send
|
||||
expect(message.header['X-Discourse-Topic-Id']).not_to be_present
|
||||
expect(message.header['X-Discourse-Post-Id']).not_to be_present
|
||||
expect(message.header['X-Discourse-Reply-Key']).not_to be_present
|
||||
end
|
||||
end
|
||||
|
||||
context "email threading" do
|
||||
|
@ -214,8 +227,10 @@ describe Email::Sender do
|
|||
message.header['X-MC-Metadata'] = { foo: "bar" }.to_json
|
||||
end
|
||||
|
||||
When { email_sender.send }
|
||||
Then { expect(message.header['X-MC-Metadata'].to_s).to match(message.message_id) }
|
||||
it 'should set the right header' do
|
||||
email_sender.send
|
||||
expect(message.header['X-MC-Metadata'].to_s).to match(message.message_id)
|
||||
end
|
||||
end
|
||||
|
||||
context "merges custom sparkpost header" do
|
||||
|
@ -224,19 +239,24 @@ describe Email::Sender do
|
|||
message.header['X-MSYS-API'] = { foo: "bar" }.to_json
|
||||
end
|
||||
|
||||
When { email_sender.send }
|
||||
Then { expect(message.header['X-MSYS-API'].to_s).to match(message.message_id) }
|
||||
it 'should set the right header' do
|
||||
email_sender.send
|
||||
expect(message.header['X-MSYS-API'].to_s).to match(message.message_id)
|
||||
end
|
||||
end
|
||||
|
||||
context 'email logs' do
|
||||
let(:email_log) { EmailLog.last }
|
||||
|
||||
When { email_sender.send }
|
||||
Then { expect(email_log).to be_present }
|
||||
Then { expect(email_log.email_type).to eq('valid_type') }
|
||||
Then { expect(email_log.to_address).to eq('eviltrout@test.domain') }
|
||||
Then { expect(email_log.reply_key).to be_blank }
|
||||
Then { expect(email_log.user_id).to be_blank }
|
||||
it 'should create the right log' do
|
||||
email_sender.send
|
||||
|
||||
expect(email_log).to be_present
|
||||
expect(email_log.email_type).to eq('valid_type')
|
||||
expect(email_log.to_address).to eq('eviltrout@test.domain')
|
||||
expect(email_log.reply_key).to be_blank
|
||||
expect(email_log.user_id).to be_blank
|
||||
end
|
||||
end
|
||||
|
||||
context "email log with a post id and topic id" do
|
||||
|
@ -246,9 +266,12 @@ describe Email::Sender do
|
|||
end
|
||||
|
||||
let(:email_log) { EmailLog.last }
|
||||
When { email_sender.send }
|
||||
Then { expect(email_log.post_id).to eq(3344) }
|
||||
Then { expect(email_log.topic_id).to eq(5577) }
|
||||
|
||||
it 'should create the right log' do
|
||||
email_sender.send
|
||||
expect(email_log.post_id).to eq(3344)
|
||||
expect(email_log.topic_id).to eq(5577)
|
||||
end
|
||||
end
|
||||
|
||||
context "email log with a reply key" do
|
||||
|
@ -257,17 +280,23 @@ describe Email::Sender do
|
|||
end
|
||||
|
||||
let(:email_log) { EmailLog.last }
|
||||
When { email_sender.send }
|
||||
Then { expect(email_log.reply_key).to eq(reply_key) }
|
||||
|
||||
it 'should create the right log' do
|
||||
email_sender.send
|
||||
expect(email_log.reply_key).to eq(reply_key)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
context 'email parts' do
|
||||
When { email_sender.send }
|
||||
Then { expect(message).to be_multipart }
|
||||
Then { expect(message.text_part.content_type).to eq('text/plain; charset=UTF-8') }
|
||||
Then { expect(message.html_part.content_type).to eq('text/html; charset=UTF-8') }
|
||||
Then { expect(message.html_part.body.to_s).to match("<p><strong>hello</strong></p>") }
|
||||
it 'should contain the right message' do
|
||||
email_sender.send
|
||||
|
||||
expect(message).to be_multipart
|
||||
expect(message.text_part.content_type).to eq('text/plain; charset=UTF-8')
|
||||
expect(message.html_part.content_type).to eq('text/html; charset=UTF-8')
|
||||
expect(message.html_part.body.to_s).to match("<p><strong>hello</strong></p>")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -4,53 +4,66 @@ require 'rails_helper'
|
|||
|
||||
describe SpamRulesEnforcer do
|
||||
|
||||
Given(:ip_address) { '182.189.119.174' }
|
||||
Given!(:spammer1) { Fabricate(:user, ip_address: ip_address) }
|
||||
Given!(:spammer2) { Fabricate(:user, ip_address: ip_address) }
|
||||
Given(:spammer3) { Fabricate(:user, ip_address: ip_address) }
|
||||
let(:ip_address) { '182.189.119.174' }
|
||||
let!(:spammer1) { Fabricate(:user, ip_address: ip_address) }
|
||||
let!(:spammer2) { Fabricate(:user, ip_address: ip_address) }
|
||||
let(:spammer3) { Fabricate(:user, ip_address: ip_address) }
|
||||
|
||||
context 'flag_sockpuppets is disabled' do
|
||||
Given { SiteSetting.stubs(:flag_sockpuppets).returns(false) }
|
||||
Given!(:first_post) { create_post(user: spammer1) }
|
||||
Given!(:second_post) { create_post(user: spammer2, topic: first_post.topic) }
|
||||
let!(:first_post) { create_post(user: spammer1) }
|
||||
let!(:second_post) { create_post(user: spammer2, topic: first_post.topic) }
|
||||
|
||||
Then { expect(first_post.reload.spam_count).to eq(0) }
|
||||
And { expect(second_post.reload.spam_count).to eq(0) }
|
||||
it 'should not increase spam count' do
|
||||
expect(first_post.reload.spam_count).to eq(0)
|
||||
expect(second_post.reload.spam_count).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
context 'flag_sockpuppets is enabled' do
|
||||
Given { SiteSetting.stubs(:flag_sockpuppets).returns(true) }
|
||||
before do
|
||||
SiteSetting.flag_sockpuppets = true
|
||||
end
|
||||
|
||||
after do
|
||||
SiteSetting.flag_sockpuppets = false
|
||||
end
|
||||
|
||||
context 'first spammer starts a topic' do
|
||||
Given!(:first_post) { create_post(user: spammer1) }
|
||||
let!(:first_post) { create_post(user: spammer1) }
|
||||
|
||||
context 'second spammer replies' do
|
||||
Given!(:second_post) { create_post(user: spammer2, topic: first_post.topic) }
|
||||
let!(:second_post) { create_post(user: spammer2, topic: first_post.topic) }
|
||||
|
||||
Then { expect(first_post.reload.spam_count).to eq(1) }
|
||||
And { expect(second_post.reload.spam_count).to eq(1) }
|
||||
it 'should increase spam count' do
|
||||
expect(first_post.reload.spam_count).to eq(1)
|
||||
expect(second_post.reload.spam_count).to eq(1)
|
||||
end
|
||||
|
||||
context 'third spam post' do
|
||||
Given!(:third_post) { create_post(user: spammer3, topic: first_post.topic) }
|
||||
let!(:third_post) { create_post(user: spammer3, topic: first_post.topic) }
|
||||
|
||||
Then { expect(first_post.reload.spam_count).to eq(1) }
|
||||
And { expect(second_post.reload.spam_count).to eq(1) }
|
||||
And { expect(third_post.reload.spam_count).to eq(1) }
|
||||
it 'should increase spam count' do
|
||||
expect(first_post.reload.spam_count).to eq(1)
|
||||
expect(second_post.reload.spam_count).to eq(1)
|
||||
expect(third_post.reload.spam_count).to eq(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'first user is not new' do
|
||||
Given!(:old_user) { Fabricate(:user, ip_address: ip_address, created_at: 2.days.ago, trust_level: TrustLevel[1]) }
|
||||
let!(:old_user) { Fabricate(:user, ip_address: ip_address, created_at: 2.days.ago, trust_level: TrustLevel[1]) }
|
||||
|
||||
context 'first user starts a topic' do
|
||||
Given!(:first_post) { create_post(user: old_user) }
|
||||
let!(:first_post) { create_post(user: old_user) }
|
||||
|
||||
context 'a reply by a new user at the same IP address' do
|
||||
Given!(:second_post) { create_post(user: spammer2, topic: first_post.topic) }
|
||||
let!(:second_post) { create_post(user: spammer2, topic: first_post.topic) }
|
||||
|
||||
Then { expect(first_post.reload.spam_count).to eq(0) }
|
||||
And { expect(second_post.reload.spam_count).to eq(1) }
|
||||
it 'should increase the spam count correctly' do
|
||||
expect(first_post.reload.spam_count).to eq(0)
|
||||
expect(second_post.reload.spam_count).to eq(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,102 +5,129 @@ require 'rails_helper'
|
|||
describe SpamRulesEnforcer do
|
||||
|
||||
describe 'auto-blocking users based on flagging' do
|
||||
before do
|
||||
SiteSetting.stubs(:flags_required_to_hide_post).returns(0) # never
|
||||
SiteSetting.stubs(:num_spam_flags_to_block_new_user).returns(2)
|
||||
SiteSetting.stubs(:num_users_to_block_new_user).returns(2)
|
||||
end
|
||||
site_setting(:flags_required_to_hide_post, 0)
|
||||
site_setting(:num_spam_flags_to_block_new_user, 2)
|
||||
site_setting(:num_users_to_block_new_user, 2)
|
||||
|
||||
Given!(:admin) { Fabricate(:admin) } # needed to send a system message
|
||||
Given!(:moderator) { Fabricate(:moderator) }
|
||||
Given(:user1) { Fabricate(:user) }
|
||||
Given(:user2) { Fabricate(:user) }
|
||||
let!(:admin) { Fabricate(:admin) } # needed to send a system message
|
||||
let!(:moderator) { Fabricate(:moderator) }
|
||||
let(:user1) { Fabricate(:user) }
|
||||
let(:user2) { Fabricate(:user) }
|
||||
|
||||
context 'spammer is a new user' do
|
||||
Given(:spammer) { Fabricate(:user, trust_level: TrustLevel[0]) }
|
||||
let(:spammer) { Fabricate(:user, trust_level: TrustLevel[0]) }
|
||||
|
||||
context 'spammer post is not flagged enough times' do
|
||||
Given!(:spam_post) { create_post(user: spammer) }
|
||||
Given!(:spam_post2) { create_post(user: spammer) }
|
||||
When { PostAction.act(user1, spam_post, PostActionType.types[:spam]) }
|
||||
Then { expect(spam_post.reload).to_not be_hidden }
|
||||
let!(:spam_post) { create_post(user: spammer) }
|
||||
let!(:spam_post2) { create_post(user: spammer) }
|
||||
|
||||
before do
|
||||
PostAction.act(user1, spam_post, PostActionType.types[:spam])
|
||||
end
|
||||
|
||||
it 'should not hide the post' do
|
||||
expect(spam_post.reload).to_not be_hidden
|
||||
end
|
||||
|
||||
context 'spam posts are flagged enough times, but not by enough users' do
|
||||
When { PostAction.act(user1, spam_post2, PostActionType.types[:spam]) }
|
||||
Then { expect(spam_post.reload).to_not be_hidden }
|
||||
And { expect(spam_post2.reload).to_not be_hidden }
|
||||
And { expect(spammer.reload).to_not be_blocked }
|
||||
it 'should not hide the post' do
|
||||
PostAction.act(user1, spam_post2, PostActionType.types[:spam])
|
||||
|
||||
expect(spam_post.reload).to_not be_hidden
|
||||
expect(spam_post2.reload).to_not be_hidden
|
||||
expect(spammer.reload).to_not be_blocked
|
||||
end
|
||||
end
|
||||
|
||||
context 'one spam post is flagged enough times by enough users' do
|
||||
Given!(:another_topic) { Fabricate(:topic) }
|
||||
Given!(:private_messages_count) { spammer.private_topics_count }
|
||||
Given!(:mod_pm_count) { moderator.private_topics_count }
|
||||
let!(:another_topic) { Fabricate(:topic) }
|
||||
let!(:private_messages_count) { spammer.private_topics_count }
|
||||
let!(:mod_pm_count) { moderator.private_topics_count }
|
||||
|
||||
When { PostAction.act(user2, spam_post, PostActionType.types[:spam]) }
|
||||
before do
|
||||
PostAction.act(user2, spam_post, PostActionType.types[:spam])
|
||||
|
||||
Invariant { expect(Guardian.new(spammer).can_create_topic?(nil)).to be false }
|
||||
Invariant { expect{PostCreator.create(spammer, {title: 'limited time offer for you', raw: 'better buy this stuff ok', archetype_id: 1})}.to raise_error(Discourse::InvalidAccess) }
|
||||
Invariant { expect(PostCreator.create(spammer, {topic_id: another_topic.id, raw: 'my reply is spam in your topic', archetype_id: 1})).to eq(nil) }
|
||||
|
||||
Then { expect(spammer.reload).to be_blocked }
|
||||
And { expect(spam_post.reload).to be_hidden }
|
||||
And { expect(spam_post2.reload).to be_hidden }
|
||||
And { expect(spammer.reload.private_topics_count).to eq(private_messages_count + 1) }
|
||||
expect(Guardian.new(spammer).can_create_topic?(nil)).to be(false)
|
||||
expect{PostCreator.create(spammer, {title: 'limited time offer for you', raw: 'better buy this stuff ok', archetype_id: 1})}.to raise_error(Discourse::InvalidAccess)
|
||||
expect(PostCreator.create(spammer, {topic_id: another_topic.id, raw: 'my reply is spam in your topic', archetype_id: 1})).to eq(nil)
|
||||
end
|
||||
|
||||
it 'should hide the posts' do
|
||||
expect(spammer.reload).to be_blocked
|
||||
expect(spam_post.reload).to be_hidden
|
||||
expect(spam_post2.reload).to be_hidden
|
||||
expect(spammer.reload.private_topics_count).to eq(private_messages_count + 1)
|
||||
end
|
||||
|
||||
# The following cases describe when a staff user takes some action, but the user
|
||||
# still won't be able to make posts.
|
||||
# A staff user needs to clear the blocked flag from the user record.
|
||||
|
||||
context "a post's flags are cleared" do
|
||||
When { PostAction.clear_flags!(spam_post, admin); spammer.reload }
|
||||
Then { expect(spammer.reload).to be_blocked }
|
||||
it 'should block the spammer' do
|
||||
PostAction.clear_flags!(spam_post, admin); spammer.reload
|
||||
expect(spammer.reload).to be_blocked
|
||||
end
|
||||
end
|
||||
|
||||
context "a post is deleted" do
|
||||
When { spam_post.trash!(moderator); spammer.reload }
|
||||
Then { expect(spammer.reload).to be_blocked }
|
||||
it 'should block the spammer' do
|
||||
spam_post.trash!(moderator); spammer.reload
|
||||
expect(spammer.reload).to be_blocked
|
||||
end
|
||||
end
|
||||
|
||||
context "spammer becomes trust level 1" do
|
||||
When { spammer.change_trust_level!(TrustLevel[1]); spammer.reload }
|
||||
Then { expect(spammer.reload).to be_blocked }
|
||||
it 'should block the spammer' do
|
||||
spammer.change_trust_level!(TrustLevel[1]); spammer.reload
|
||||
expect(spammer.reload).to be_blocked
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'flags_required_to_hide_post takes effect too' do
|
||||
Given { SiteSetting.stubs(:flags_required_to_hide_post).returns(2) }
|
||||
When { PostAction.act(user2, spam_post, PostActionType.types[:spam]) }
|
||||
Then { expect(spammer.reload).to be_blocked }
|
||||
And { expect(Guardian.new(spammer).can_create_topic?(nil)).to be false }
|
||||
site_setting(:flags_required_to_hide_post, 2)
|
||||
|
||||
it 'should block the spammer' do
|
||||
PostAction.act(user2, spam_post, PostActionType.types[:spam])
|
||||
expect(spammer.reload).to be_blocked
|
||||
expect(Guardian.new(spammer).can_create_topic?(nil)).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "spammer has trust level basic" do
|
||||
Given(:spammer) { Fabricate(:user, trust_level: TrustLevel[1]) }
|
||||
let(:spammer) { Fabricate(:user, trust_level: TrustLevel[1]) }
|
||||
|
||||
context 'one spam post is flagged enough times by enough users' do
|
||||
Given!(:spam_post) { Fabricate(:post, user: spammer) }
|
||||
Given!(:private_messages_count) { spammer.private_topics_count }
|
||||
When { PostAction.act(user1, spam_post, PostActionType.types[:spam]) }
|
||||
When { PostAction.act(user2, spam_post, PostActionType.types[:spam]) }
|
||||
Then { expect(spam_post.reload).to_not be_hidden }
|
||||
And { expect(Guardian.new(spammer).can_create_topic?(nil)).to be true }
|
||||
And { expect{PostCreator.create(spammer, {title: 'limited time offer for you', raw: 'better buy this stuff ok', archetype_id: 1})}.to_not raise_error }
|
||||
And { expect(spammer.reload.private_topics_count).to eq(private_messages_count) }
|
||||
let!(:spam_post) { Fabricate(:post, user: spammer) }
|
||||
let!(:private_messages_count) { spammer.private_topics_count }
|
||||
|
||||
it 'should not allow spammer to create new posts' do
|
||||
PostAction.act(user1, spam_post, PostActionType.types[:spam])
|
||||
PostAction.act(user2, spam_post, PostActionType.types[:spam])
|
||||
|
||||
expect(spam_post.reload).to_not be_hidden
|
||||
expect(Guardian.new(spammer).can_create_topic?(nil)).to be(true)
|
||||
expect{PostCreator.create(spammer, {title: 'limited time offer for you', raw: 'better buy this stuff ok', archetype_id: 1})}.to_not raise_error
|
||||
expect(spammer.reload.private_topics_count).to eq(private_messages_count)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
[[:user, trust_level: TrustLevel[2]], [:admin], [:moderator]].each do |spammer_args|
|
||||
context "spammer is trusted #{spammer_args[0]}" do
|
||||
Given!(:spammer) { Fabricate(*spammer_args) }
|
||||
Given!(:spam_post) { Fabricate(:post, user: spammer) }
|
||||
Given!(:private_messages_count) { spammer.private_topics_count }
|
||||
When { PostAction.act(user1, spam_post, PostActionType.types[:spam]) }
|
||||
When { PostAction.act(user2, spam_post, PostActionType.types[:spam]) }
|
||||
Then { expect(spam_post.reload).to_not be_hidden }
|
||||
let!(:spammer) { Fabricate(*spammer_args) }
|
||||
let!(:spam_post) { Fabricate(:post, user: spammer) }
|
||||
let!(:private_messages_count) { spammer.private_topics_count }
|
||||
|
||||
it 'should not hide the post' do
|
||||
PostAction.act(user1, spam_post, PostActionType.types[:spam])
|
||||
PostAction.act(user2, spam_post, PostActionType.types[:spam])
|
||||
|
||||
expect(spam_post.reload).to_not be_hidden
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -19,25 +19,35 @@ describe Topic do
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
before {
|
||||
before do
|
||||
@original_value = SiteSetting.queue_jobs
|
||||
SiteSetting.queue_jobs = true
|
||||
Jobs::CloseTopic.jobs.clear
|
||||
}
|
||||
end
|
||||
|
||||
after do
|
||||
SiteSetting.queue_jobs = @original_value
|
||||
end
|
||||
|
||||
context 'creating a topic without auto-close' do
|
||||
Given(:topic) { Fabricate(:topic, category: category) }
|
||||
let(:topic) { Fabricate(:topic, category: category) }
|
||||
|
||||
context 'uncategorized' do
|
||||
Given(:category) { nil }
|
||||
Then { expect(topic.auto_close_at).to eq(nil) }
|
||||
And { expect(scheduled_jobs_for(:close_topic)).to be_empty }
|
||||
let(:category) { nil }
|
||||
|
||||
it 'should not schedule the topic to auto-close' do
|
||||
expect(topic.auto_close_at).to eq(nil)
|
||||
expect(scheduled_jobs_for(:close_topic)).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
context 'category without default auto-close' do
|
||||
Given(:category) { Fabricate(:category, auto_close_hours: nil) }
|
||||
Then { expect(topic.auto_close_at).to eq(nil) }
|
||||
And { expect(scheduled_jobs_for(:close_topic)).to be_empty }
|
||||
let(:category) { Fabricate(:category, auto_close_hours: nil) }
|
||||
|
||||
it 'should not schedule the topic to auto-close' do
|
||||
expect(topic.auto_close_at).to eq(nil)
|
||||
expect(scheduled_jobs_for(:close_topic)).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
context 'jobs may be queued' do
|
||||
|
@ -51,50 +61,69 @@ describe Topic do
|
|||
end
|
||||
|
||||
context 'category has a default auto-close' do
|
||||
Given(:category) { Fabricate(:category, auto_close_hours: 2.0) }
|
||||
Then { expect(topic.auto_close_at).to be_within_one_second_of(2.hours.from_now) }
|
||||
And { expect(topic.auto_close_started_at).to eq(Time.zone.now) }
|
||||
And { expect(scheduled_jobs_for(:close_topic, {topic_id: topic.id}).size).to eq(1) }
|
||||
And { expect(scheduled_jobs_for(:close_topic, {topic_id: category.topic.id})).to be_empty }
|
||||
let(:category) { Fabricate(:category, auto_close_hours: 2.0) }
|
||||
|
||||
it 'should schedule the topic to auto-close' do
|
||||
expect(topic.auto_close_at).to be_within_one_second_of(2.hours.from_now)
|
||||
expect(topic.auto_close_started_at).to eq(Time.zone.now)
|
||||
expect(scheduled_jobs_for(:close_topic, {topic_id: topic.id}).size).to eq(1)
|
||||
expect(scheduled_jobs_for(:close_topic, {topic_id: category.topic.id})).to be_empty
|
||||
end
|
||||
|
||||
context 'topic was created by staff user' do
|
||||
Given(:admin) { Fabricate(:admin) }
|
||||
Given(:staff_topic) { Fabricate(:topic, user: admin, category: category) }
|
||||
Then { expect(scheduled_jobs_for(:close_topic, {topic_id: staff_topic.id, user_id: admin.id}).size).to eq(1) }
|
||||
let(:admin) { Fabricate(:admin) }
|
||||
let(:staff_topic) { Fabricate(:topic, user: admin, category: category) }
|
||||
|
||||
it 'should schedule the topic to auto-close' do
|
||||
expect(scheduled_jobs_for(:close_topic, {topic_id: staff_topic.id, user_id: admin.id}).size).to eq(1)
|
||||
end
|
||||
|
||||
context 'topic is closed manually' do
|
||||
When { staff_topic.update_status('closed', true, admin) }
|
||||
Then { expect(staff_topic.reload.auto_close_at).to eq(nil) }
|
||||
And { expect(staff_topic.auto_close_started_at).to eq(nil) }
|
||||
it 'should remove the schedule to auto-close the topic' do
|
||||
staff_topic.update_status('closed', true, admin)
|
||||
expect(staff_topic.reload.auto_close_at).to eq(nil)
|
||||
expect(staff_topic.auto_close_started_at).to eq(nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'topic was created by a non-staff user' do
|
||||
Given!(:system_user) { Discourse.system_user }
|
||||
Given { Discourse.stubs(:system_user).returns(system_user) }
|
||||
Given(:regular_user) { Fabricate(:user) }
|
||||
Given(:regular_user_topic) { Fabricate(:topic, user: regular_user, category: category) }
|
||||
Then { expect(scheduled_jobs_for(:close_topic, {topic_id: regular_user_topic.id, user_id: system_user.id}).size).to eq(1) }
|
||||
let(:regular_user) { Fabricate(:user) }
|
||||
let(:regular_user_topic) { Fabricate(:topic, user: regular_user, category: category) }
|
||||
|
||||
it 'should schedule the topic to auto-close' do
|
||||
expect(scheduled_jobs_for(:close_topic, {topic_id: regular_user_topic.id, user_id: Discourse.system_user.id}).size).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
context 'auto_close_hours of topic was set to 0' do
|
||||
Given(:dont_close_topic) { Fabricate(:topic, auto_close_hours: 0, category: category) }
|
||||
Then { expect(scheduled_jobs_for(:close_topic)).to be_empty }
|
||||
let(:dont_close_topic) { Fabricate(:topic, auto_close_hours: 0, category: category) }
|
||||
|
||||
it 'should not schedule the topic to auto-close' do
|
||||
expect(scheduled_jobs_for(:close_topic)).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
context 'two topics in the category' do
|
||||
Given!(:other_topic) { Fabricate(:topic, category: category) }
|
||||
When { topic } # create the second topic
|
||||
Then { expect(scheduled_jobs_for(:close_topic).size).to eq(2) }
|
||||
let!(:other_topic) { Fabricate(:topic, category: category) }
|
||||
|
||||
it 'should schedule the topic to auto-close' do
|
||||
topic
|
||||
|
||||
expect(scheduled_jobs_for(:close_topic).size).to eq(2)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'a topic that has been auto-closed' do
|
||||
Given(:admin) { Fabricate(:admin) }
|
||||
Given!(:auto_closed_topic) { Fabricate(:topic, user: admin, closed: true, auto_close_at: 1.day.ago, auto_close_user_id: admin.id, auto_close_started_at: 6.days.ago) }
|
||||
When { auto_closed_topic.update_status('closed', false, admin) }
|
||||
Then { expect(auto_closed_topic.reload.auto_close_at).to eq(nil) }
|
||||
And { expect(auto_closed_topic.auto_close_started_at).to eq(nil) }
|
||||
let(:admin) { Fabricate(:admin) }
|
||||
let!(:auto_closed_topic) { Fabricate(:topic, user: admin, closed: true, auto_close_at: 1.day.ago, auto_close_user_id: admin.id, auto_close_started_at: 6.days.ago) }
|
||||
|
||||
it 'should set the right attributes' do
|
||||
auto_closed_topic.update_status('closed', false, admin)
|
||||
expect(auto_closed_topic.reload.auto_close_at).to eq(nil)
|
||||
expect(auto_closed_topic.auto_close_started_at).to eq(nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,21 +15,32 @@ describe Jobs::EnqueueDigestEmails do
|
|||
end
|
||||
|
||||
context 'unapproved users' do
|
||||
Given!(:unapproved_user) { Fabricate(:active_user, approved: false, last_emailed_at: 8.days.ago, last_seen_at: 10.days.ago) }
|
||||
When { SiteSetting.stubs(:must_approve_users?).returns(true) }
|
||||
Then { expect(Jobs::EnqueueDigestEmails.new.target_user_ids.include?(unapproved_user.id)).to eq(false) }
|
||||
let!(:unapproved_user) { Fabricate(:active_user, approved: false, last_emailed_at: 8.days.ago, last_seen_at: 10.days.ago) }
|
||||
|
||||
# As a moderator
|
||||
And { unapproved_user.update_column(:moderator, true) }
|
||||
And { expect(Jobs::EnqueueDigestEmails.new.target_user_ids.include?(unapproved_user.id)).to eq(true) }
|
||||
before do
|
||||
@original_value = SiteSetting.must_approve_users
|
||||
SiteSetting.must_approve_users = true
|
||||
end
|
||||
|
||||
# As an admin
|
||||
And { unapproved_user.update_attributes(admin: true, moderator: false) }
|
||||
And { expect(Jobs::EnqueueDigestEmails.new.target_user_ids.include?(unapproved_user.id)).to eq(true) }
|
||||
after do
|
||||
SiteSetting.must_approve_users = @original_value
|
||||
end
|
||||
|
||||
# As an approved user
|
||||
And { unapproved_user.update_attributes(admin: false, moderator: false, approved: true ) }
|
||||
And { expect(Jobs::EnqueueDigestEmails.new.target_user_ids.include?(unapproved_user.id)).to eq(true) }
|
||||
it 'should enqueue the right digest emails' do
|
||||
expect(Jobs::EnqueueDigestEmails.new.target_user_ids.include?(unapproved_user.id)).to eq(false)
|
||||
|
||||
# As a moderator
|
||||
unapproved_user.update_column(:moderator, true)
|
||||
expect(Jobs::EnqueueDigestEmails.new.target_user_ids.include?(unapproved_user.id)).to eq(true)
|
||||
|
||||
# As an admin
|
||||
unapproved_user.update_attributes(admin: true, moderator: false)
|
||||
expect(Jobs::EnqueueDigestEmails.new.target_user_ids.include?(unapproved_user.id)).to eq(true)
|
||||
|
||||
# As an approved user
|
||||
unapproved_user.update_attributes(admin: false, moderator: false, approved: true )
|
||||
expect(Jobs::EnqueueDigestEmails.new.target_user_ids.include?(unapproved_user.id)).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
context 'staged users' do
|
||||
|
|
|
@ -6,24 +6,33 @@ describe Jobs::EnqueueMailingListEmails do
|
|||
describe '#target_users' do
|
||||
|
||||
context 'unapproved users' do
|
||||
Given!(:unapproved_user) { Fabricate(:active_user, approved: false, first_seen_at: 24.hours.ago) }
|
||||
When do
|
||||
let!(:unapproved_user) { Fabricate(:active_user, approved: false, first_seen_at: 24.hours.ago) }
|
||||
|
||||
before do
|
||||
@original_value = SiteSetting.must_approve_users
|
||||
SiteSetting.must_approve_users = true
|
||||
unapproved_user.user_option.update(mailing_list_mode: true, mailing_list_mode_frequency: 0)
|
||||
end
|
||||
Then { expect(Jobs::EnqueueMailingListEmails.new.target_user_ids.include?(unapproved_user.id)).to eq(false) }
|
||||
|
||||
# As a moderator
|
||||
And { unapproved_user.update_column(:moderator, true) }
|
||||
And { expect(Jobs::EnqueueMailingListEmails.new.target_user_ids.include?(unapproved_user.id)).to eq(true) }
|
||||
after do
|
||||
SiteSetting.must_approve_users = @original_value
|
||||
end
|
||||
|
||||
# As an admin
|
||||
And { unapproved_user.update_attributes(admin: true, moderator: false) }
|
||||
And { expect(Jobs::EnqueueMailingListEmails.new.target_user_ids.include?(unapproved_user.id)).to eq(true) }
|
||||
it 'should enqueue the right emails' do
|
||||
unapproved_user.user_option.update(mailing_list_mode: true, mailing_list_mode_frequency: 0)
|
||||
expect(Jobs::EnqueueMailingListEmails.new.target_user_ids.include?(unapproved_user.id)).to eq(false)
|
||||
|
||||
# As an approved user
|
||||
And { unapproved_user.update_attributes(admin: false, moderator: false, approved: true ) }
|
||||
And { expect(Jobs::EnqueueMailingListEmails.new.target_user_ids.include?(unapproved_user.id)).to eq(true) }
|
||||
# As a moderator
|
||||
unapproved_user.update_column(:moderator, true)
|
||||
expect(Jobs::EnqueueMailingListEmails.new.target_user_ids.include?(unapproved_user.id)).to eq(true)
|
||||
|
||||
# As an admin
|
||||
unapproved_user.update_attributes(admin: true, moderator: false)
|
||||
expect(Jobs::EnqueueMailingListEmails.new.target_user_ids.include?(unapproved_user.id)).to eq(true)
|
||||
|
||||
# As an approved user
|
||||
unapproved_user.update_attributes(admin: false, moderator: false, approved: true )
|
||||
expect(Jobs::EnqueueMailingListEmails.new.target_user_ids.include?(unapproved_user.id)).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
context 'staged users' do
|
||||
|
|
|
@ -1,4 +1,20 @@
|
|||
module Helpers
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
class_methods do
|
||||
def site_setting(setting_name, value)
|
||||
original_value = SiteSetting.public_send(setting_name.to_sym)
|
||||
|
||||
self.before do
|
||||
SiteSetting.public_send("#{setting_name}=", value)
|
||||
end
|
||||
|
||||
self.after do
|
||||
SiteSetting.public_send("#{setting_name}=", original_value)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.next_seq
|
||||
@next_seq = (@next_seq || 0) + 1
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue