Nuke all SiteSetting.stubs from our codebase.

This commit is contained in:
Guo Xiang Tan 2017-07-07 15:09:14 +09:00
parent e7e16de3e0
commit 13f3de4bf6
59 changed files with 257 additions and 262 deletions

View File

@ -28,7 +28,7 @@ describe ComposerMessagesFinder do
let(:finder) { ComposerMessagesFinder.new(user, composer_action: 'createTopic') } let(:finder) { ComposerMessagesFinder.new(user, composer_action: 'createTopic') }
before do before do
SiteSetting.stubs(:educate_until_posts).returns(10) SiteSetting.educate_until_posts = 10
end end
it "returns a message for a user who has not posted any topics" do it "returns a message for a user who has not posted any topics" do
@ -66,7 +66,7 @@ describe ComposerMessagesFinder do
let(:finder) { ComposerMessagesFinder.new(user, composer_action: 'reply') } let(:finder) { ComposerMessagesFinder.new(user, composer_action: 'reply') }
before do before do
SiteSetting.stubs(:educate_until_posts).returns(10) SiteSetting.educate_until_posts = 10
end end
it "returns a message for a user who has not posted any topics" do it "returns a message for a user who has not posted any topics" do
@ -152,13 +152,13 @@ describe ComposerMessagesFinder do
let(:topic) { Fabricate(:topic) } let(:topic) { Fabricate(:topic) }
before do before do
SiteSetting.stubs(:educate_until_posts).returns(10) SiteSetting.educate_until_posts = 10
user.stubs(:post_count).returns(11) user.stubs(:post_count).returns(11)
Fabricate(:post, topic: topic, user: user) Fabricate(:post, topic: topic, user: user)
Fabricate(:post, topic: topic, user: user) Fabricate(:post, topic: topic, user: user)
SiteSetting.stubs(:sequential_replies_threshold).returns(2) SiteSetting.sequential_replies_threshold = 2
end end
it "does not give a message for new topics" do it "does not give a message for new topics" do
@ -189,7 +189,7 @@ describe ComposerMessagesFinder do
end end
it "doesn't notify a user who has less than the `sequential_replies_threshold` threshold posts" do it "doesn't notify a user who has less than the `sequential_replies_threshold` threshold posts" do
SiteSetting.stubs(:sequential_replies_threshold).returns(5) SiteSetting.sequential_replies_threshold = 5
expect(finder.check_sequential_replies).to be_blank expect(finder.check_sequential_replies).to be_blank
end end
@ -224,16 +224,16 @@ describe ComposerMessagesFinder do
let(:topic) { Fabricate(:topic) } let(:topic) { Fabricate(:topic) }
before do before do
SiteSetting.stubs(:educate_until_posts).returns(10) SiteSetting.educate_until_posts = 10
user.stubs(:post_count).returns(11) user.stubs(:post_count).returns(11)
SiteSetting.stubs(:summary_posts_required).returns(1) SiteSetting.summary_posts_required = 1
Fabricate(:post, topic: topic, user: user) Fabricate(:post, topic: topic, user: user)
Fabricate(:post, topic: topic, user: user) Fabricate(:post, topic: topic, user: user)
Fabricate(:post, topic: topic, user: Fabricate(:user)) Fabricate(:post, topic: topic, user: Fabricate(:user))
SiteSetting.stubs(:sequential_replies_threshold).returns(2) SiteSetting.sequential_replies_threshold = 2
end end
it "does not give a message for new topics" do it "does not give a message for new topics" do
@ -254,7 +254,7 @@ describe ComposerMessagesFinder do
end end
it "does not notify if the `summary_posts_required` has not been reached" do it "does not notify if the `summary_posts_required` has not been reached" do
SiteSetting.stubs(:summary_posts_required).returns(100) SiteSetting.summary_posts_required = 100
expect(finder.check_dominating_topic).to be_blank expect(finder.check_dominating_topic).to be_blank
end end
@ -269,12 +269,12 @@ describe ComposerMessagesFinder do
end end
it "doesn't notify a user if the topic has less than `summary_posts_required` posts" do it "doesn't notify a user if the topic has less than `summary_posts_required` posts" do
SiteSetting.stubs(:summary_posts_required).returns(5) SiteSetting.summary_posts_required = 5
expect(finder.check_dominating_topic).to be_blank expect(finder.check_dominating_topic).to be_blank
end end
it "doesn't notify a user if they've posted less than the percentage" do it "doesn't notify a user if they've posted less than the percentage" do
SiteSetting.stubs(:dominating_topic_minimum_percent).returns(100) SiteSetting.dominating_topic_minimum_percent = 100
expect(finder.check_dominating_topic).to be_blank expect(finder.check_dominating_topic).to be_blank
end end
@ -433,7 +433,7 @@ describe ComposerMessagesFinder do
context "a reply" do context "a reply" do
context "warn_reviving_old_topic_age is 180 days" do context "warn_reviving_old_topic_age is 180 days" do
before do before do
SiteSetting.stubs(:warn_reviving_old_topic_age).returns(180) SiteSetting.warn_reviving_old_topic_age = 180
end end
it "does not notify if last post is recent" do it "does not notify if last post is recent" do
@ -449,7 +449,7 @@ describe ComposerMessagesFinder do
context "warn_reviving_old_topic_age is 0" do context "warn_reviving_old_topic_age is 0" do
before do before do
SiteSetting.stubs(:warn_reviving_old_topic_age).returns(0) SiteSetting.warn_reviving_old_topic_age = 0
end end
it "does not notify if last post is new" do it "does not notify if last post is new" do

View File

@ -298,21 +298,21 @@ describe CookedPostProcessor do
it "resizes when only width is specified" do it "resizes when only width is specified" do
img = { 'src' => 'http://foo.bar/image3.png', 'width' => 100} img = { 'src' => 'http://foo.bar/image3.png', 'width' => 100}
SiteSetting.stubs(:crawl_images?).returns(true) SiteSetting.crawl_images = true
FastImage.expects(:size).returns([200, 400]) FastImage.expects(:size).returns([200, 400])
expect(cpp.get_size_from_attributes(img)).to eq([100, 200]) expect(cpp.get_size_from_attributes(img)).to eq([100, 200])
end end
it "resizes when only height is specified" do it "resizes when only height is specified" do
img = { 'src' => 'http://foo.bar/image3.png', 'height' => 100} img = { 'src' => 'http://foo.bar/image3.png', 'height' => 100}
SiteSetting.stubs(:crawl_images?).returns(true) SiteSetting.crawl_images = true
FastImage.expects(:size).returns([100, 300]) FastImage.expects(:size).returns([100, 300])
expect(cpp.get_size_from_attributes(img)).to eq([33, 100]) expect(cpp.get_size_from_attributes(img)).to eq([33, 100])
end end
it "doesn't raise an error with a weird url" do it "doesn't raise an error with a weird url" do
img = { 'src' => nil, 'height' => 100} img = { 'src' => nil, 'height' => 100}
SiteSetting.stubs(:crawl_images?).returns(true) SiteSetting.crawl_images = true
expect(cpp.get_size_from_attributes(img)).to be_nil expect(cpp.get_size_from_attributes(img)).to be_nil
end end
@ -346,7 +346,7 @@ describe CookedPostProcessor do
end end
it "caches the results" do it "caches the results" do
SiteSetting.stubs(:crawl_images?).returns(true) SiteSetting.crawl_images = true
FastImage.expects(:size).returns([200, 400]) FastImage.expects(:size).returns([200, 400])
cpp.get_size("http://foo.bar/image3.png") cpp.get_size("http://foo.bar/image3.png")
expect(cpp.get_size("http://foo.bar/image3.png")).to eq([200, 400]) expect(cpp.get_size("http://foo.bar/image3.png")).to eq([200, 400])
@ -354,7 +354,9 @@ describe CookedPostProcessor do
context "when crawl_images is disabled" do context "when crawl_images is disabled" do
before { SiteSetting.stubs(:crawl_images?).returns(false) } before do
SiteSetting.crawl_images = false
end
it "doesn't call FastImage" do it "doesn't call FastImage" do
FastImage.expects(:size).never FastImage.expects(:size).never
@ -525,14 +527,15 @@ describe CookedPostProcessor do
before { cpp.stubs(:available_disk_space).returns(90) } before { cpp.stubs(:available_disk_space).returns(90) }
it "does not run when download_remote_images_to_local is disabled" do it "does not run when download_remote_images_to_local is disabled" do
SiteSetting.stubs(:download_remote_images_to_local).returns(false) SiteSetting.download_remote_images_to_local = false
Jobs.expects(:cancel_scheduled_job).never Jobs.expects(:cancel_scheduled_job).never
cpp.pull_hotlinked_images cpp.pull_hotlinked_images
end end
context "when download_remote_images_to_local? is enabled" do context "when download_remote_images_to_local? is enabled" do
before do
before { SiteSetting.stubs(:download_remote_images_to_local).returns(true) } SiteSetting.download_remote_images_to_local = true
end
it "does not run when there is not enough disk space" do it "does not run when there is not enough disk space" do
cpp.expects(:disable_if_low_on_disk_space).returns(true) cpp.expects(:disable_if_low_on_disk_space).returns(true)

View File

@ -53,12 +53,7 @@ describe Discourse do
let!(:another_admin) { Fabricate(:admin) } let!(:another_admin) { Fabricate(:admin) }
it 'returns the user specified by the site setting site_contact_username' do it 'returns the user specified by the site setting site_contact_username' do
SiteSetting.stubs(:site_contact_username).returns(another_admin.username) SiteSetting.site_contact_username = another_admin.username
expect(Discourse.site_contact_user).to eq(another_admin)
end
it 'returns the user specified by the site setting site_contact_username regardless of its case' do
SiteSetting.stubs(:site_contact_username).returns(another_admin.username.upcase)
expect(Discourse.site_contact_user).to eq(another_admin) expect(Discourse.site_contact_user).to eq(another_admin)
end end
@ -211,4 +206,3 @@ describe Discourse do
end end
end end

View File

@ -254,7 +254,7 @@ describe Email::Receiver do
end end
it 'does nothing unless unsubscribe_via_email is turned on' do it 'does nothing unless unsubscribe_via_email is turned on' do
SiteSetting.stubs("unsubscribe_via_email").returns(false) SiteSetting.unsubscribe_via_email = false
before_deliveries = ActionMailer::Base.deliveries.count before_deliveries = ActionMailer::Base.deliveries.count
expect { process("unsubscribe_subject") }.to raise_error { Email::Receiver::BadDestinationAddress } expect { process("unsubscribe_subject") }.to raise_error { Email::Receiver::BadDestinationAddress }
expect(before_deliveries).to eq ActionMailer::Base.deliveries.count expect(before_deliveries).to eq ActionMailer::Base.deliveries.count
@ -272,7 +272,7 @@ describe Email::Receiver do
end end
it 'does nothing unless unsubscribe_via_email is turned on' do it 'does nothing unless unsubscribe_via_email is turned on' do
SiteSetting.stubs(:unsubscribe_via_email).returns(false) SiteSetting.unsubscribe_via_email = false
before_deliveries = ActionMailer::Base.deliveries.count before_deliveries = ActionMailer::Base.deliveries.count
expect { process("unsubscribe_body") }.to raise_error { Email::Receiver::InvalidPost } expect { process("unsubscribe_body") }.to raise_error { Email::Receiver::InvalidPost }
expect(before_deliveries).to eq ActionMailer::Base.deliveries.count expect(before_deliveries).to eq ActionMailer::Base.deliveries.count

View File

@ -117,7 +117,7 @@ describe Email::Styles do
context "without https" do context "without https" do
before do before do
SiteSetting.stubs(:force_https).returns(false) SiteSetting.force_https = false
end end
it "rewrites the href to have http" do it "rewrites the href to have http" do
@ -138,7 +138,7 @@ describe Email::Styles do
context "with https" do context "with https" do
before do before do
SiteSetting.stubs(:force_https).returns(true) SiteSetting.force_https = true
end end
it "rewrites the forum URL to have https" do it "rewrites the forum URL to have https" do

View File

@ -209,13 +209,13 @@ describe FileStore::S3Store do
end end
it "uses the proper endpoint" do it "uses the proper endpoint" do
SiteSetting.stubs(:s3_region).returns("us-east-1") SiteSetting.s3_region = "us-east-1"
expect(FileStore::S3Store.new(s3_helper).absolute_base_url).to eq("//s3-upload-bucket.s3.amazonaws.com") expect(FileStore::S3Store.new(s3_helper).absolute_base_url).to eq("//s3-upload-bucket.s3.amazonaws.com")
SiteSetting.stubs(:s3_region).returns("us-east-2") SiteSetting.s3_region = "us-west-2"
expect(FileStore::S3Store.new(s3_helper).absolute_base_url).to eq("//s3-upload-bucket.s3-us-east-2.amazonaws.com") expect(FileStore::S3Store.new(s3_helper).absolute_base_url).to eq("//s3-upload-bucket.s3-us-west-2.amazonaws.com")
SiteSetting.stubs(:s3_region).returns("cn-north-1") SiteSetting.s3_region = "cn-north-1"
expect(FileStore::S3Store.new(s3_helper).absolute_base_url).to eq("//s3-upload-bucket.s3.cn-north-1.amazonaws.com.cn") expect(FileStore::S3Store.new(s3_helper).absolute_base_url).to eq("//s3-upload-bucket.s3.cn-north-1.amazonaws.com.cn")
end end

View File

@ -1,4 +1,5 @@
require 'rails_helper' require 'rails_helper';
require 'guardian' require 'guardian'
require_dependency 'post_destroyer' require_dependency 'post_destroyer'
@ -322,7 +323,7 @@ describe Guardian do
end end
it 'returns false when the local logins are disabled' do it 'returns false when the local logins are disabled' do
SiteSetting.stubs(:enable_local_logins).returns(false) SiteSetting.enable_local_logins = false
expect(Guardian.new(user).can_invite_to_forum?).to be_falsey expect(Guardian.new(user).can_invite_to_forum?).to be_falsey
expect(Guardian.new(moderator).can_invite_to_forum?).to be_falsey expect(Guardian.new(moderator).can_invite_to_forum?).to be_falsey
end end
@ -536,7 +537,7 @@ describe Guardian do
it "restricts static doc topics" do it "restricts static doc topics" do
tos_topic = Fabricate(:topic, user: Discourse.system_user) tos_topic = Fabricate(:topic, user: Discourse.system_user)
SiteSetting.stubs(:tos_topic_id).returns(tos_topic.id) SiteSetting.tos_topic_id = tos_topic.id
expect(Guardian.new(build(:user)).can_edit?(tos_topic)).to be_falsey expect(Guardian.new(build(:user)).can_edit?(tos_topic)).to be_falsey
expect(Guardian.new(moderator).can_edit?(tos_topic)).to be_falsey expect(Guardian.new(moderator).can_edit?(tos_topic)).to be_falsey
@ -609,7 +610,7 @@ describe Guardian do
let(:post_revision) { Fabricate(:post_revision) } let(:post_revision) { Fabricate(:post_revision) }
context 'edit_history_visible_to_public is true' do context 'edit_history_visible_to_public is true' do
before { SiteSetting.stubs(:edit_history_visible_to_public).returns(true) } before { SiteSetting.edit_history_visible_to_public = true }
it 'is false for nil' do it 'is false for nil' do
expect(Guardian.new.can_see?(nil)).to be_falsey expect(Guardian.new.can_see?(nil)).to be_falsey
@ -625,7 +626,7 @@ describe Guardian do
end end
context 'edit_history_visible_to_public is false' do context 'edit_history_visible_to_public is false' do
before { SiteSetting.stubs(:edit_history_visible_to_public).returns(false) } before { SiteSetting.edit_history_visible_to_public = false }
it 'is true for staff' do it 'is true for staff' do
expect(Guardian.new(Fabricate(:admin)).can_see?(post_revision)).to be_truthy expect(Guardian.new(Fabricate(:admin)).can_see?(post_revision)).to be_truthy
@ -685,12 +686,12 @@ describe Guardian do
end end
it "is false if user has not met minimum trust level" do it "is false if user has not met minimum trust level" do
SiteSetting.stubs(:min_trust_to_create_topic).returns(1) SiteSetting.min_trust_to_create_topic = 1
expect(Guardian.new(build(:user, trust_level: 0)).can_create?(Topic,Fabricate(:category))).to be_falsey expect(Guardian.new(build(:user, trust_level: 0)).can_create?(Topic,Fabricate(:category))).to be_falsey
end end
it "is true if user has met or exceeded the minimum trust level" do it "is true if user has met or exceeded the minimum trust level" do
SiteSetting.stubs(:min_trust_to_create_topic).returns(1) SiteSetting.min_trust_to_create_topic = 1
expect(Guardian.new(build(:user, trust_level: 1)).can_create?(Topic,Fabricate(:category))).to be_truthy expect(Guardian.new(build(:user, trust_level: 1)).can_create?(Topic,Fabricate(:category))).to be_truthy
expect(Guardian.new(build(:user, trust_level: 2)).can_create?(Topic,Fabricate(:category))).to be_truthy expect(Guardian.new(build(:user, trust_level: 2)).can_create?(Topic,Fabricate(:category))).to be_truthy
expect(Guardian.new(build(:admin, trust_level: 0)).can_create?(Topic,Fabricate(:category))).to be_truthy expect(Guardian.new(build(:admin, trust_level: 0)).can_create?(Topic,Fabricate(:category))).to be_truthy
@ -1094,7 +1095,7 @@ describe Guardian do
end end
it 'returns false when another user has too low trust level to edit wiki post' do it 'returns false when another user has too low trust level to edit wiki post' do
SiteSetting.stubs(:min_trust_to_edit_wiki_post).returns(2) SiteSetting.min_trust_to_edit_wiki_post = 2
post.wiki = true post.wiki = true
coding_horror.trust_level = 1 coding_horror.trust_level = 1
@ -1102,7 +1103,7 @@ describe Guardian do
end end
it 'returns true when another user has adequate trust level to edit wiki post' do it 'returns true when another user has adequate trust level to edit wiki post' do
SiteSetting.stubs(:min_trust_to_edit_wiki_post).returns(2) SiteSetting.min_trust_to_edit_wiki_post = 2
post.wiki = true post.wiki = true
coding_horror.trust_level = 2 coding_horror.trust_level = 2
@ -1110,7 +1111,7 @@ describe Guardian do
end end
it 'returns true for post author even when he has too low trust level to edit wiki post' do it 'returns true for post author even when he has too low trust level to edit wiki post' do
SiteSetting.stubs(:min_trust_to_edit_wiki_post).returns(2) SiteSetting.min_trust_to_edit_wiki_post = 2
post.wiki = true post.wiki = true
post.user.trust_level = 1 post.user.trust_level = 1
@ -1119,8 +1120,9 @@ describe Guardian do
context 'post is older than post_edit_time_limit' do context 'post is older than post_edit_time_limit' do
let(:old_post) { build(:post, topic: topic, user: topic.user, created_at: 6.minutes.ago) } let(:old_post) { build(:post, topic: topic, user: topic.user, created_at: 6.minutes.ago) }
before do before do
SiteSetting.stubs(:post_edit_time_limit).returns(5) SiteSetting.post_edit_time_limit = 5
end end
it 'returns false to the author of the post' do it 'returns false to the author of the post' do
@ -1148,7 +1150,7 @@ describe Guardian do
context "first post of a static page doc" do context "first post of a static page doc" do
let!(:tos_topic) { Fabricate(:topic, user: Discourse.system_user) } let!(:tos_topic) { Fabricate(:topic, user: Discourse.system_user) }
let!(:tos_first_post) { build(:post, topic: tos_topic, user: tos_topic.user) } let!(:tos_first_post) { build(:post, topic: tos_topic, user: tos_topic.user) }
before { SiteSetting.stubs(:tos_topic_id).returns(tos_topic.id) } before { SiteSetting.tos_topic_id = tos_topic.id }
it "restricts static doc posts" do it "restricts static doc posts" do
expect(Guardian.new(build(:user)).can_edit?(tos_first_post)).to be_falsey expect(Guardian.new(build(:user)).can_edit?(tos_first_post)).to be_falsey
@ -1246,7 +1248,7 @@ describe Guardian do
context 'very old' do context 'very old' do
let(:old_topic) { build(:topic, user: user, created_at: 6.minutes.ago) } let(:old_topic) { build(:topic, user: user, created_at: 6.minutes.ago) }
before { SiteSetting.stubs(:post_edit_time_limit).returns(5) } before { SiteSetting.post_edit_time_limit = 5 }
it 'returns true as a moderator' do it 'returns true as a moderator' do
expect(Guardian.new(moderator).can_edit?(old_topic)).to be_truthy expect(Guardian.new(moderator).can_edit?(old_topic)).to be_truthy
@ -1433,7 +1435,7 @@ describe Guardian do
it 'returns false for static doc topics' do it 'returns false for static doc topics' do
tos_topic = Fabricate(:topic, user: Discourse.system_user) tos_topic = Fabricate(:topic, user: Discourse.system_user)
SiteSetting.stubs(:tos_topic_id).returns(tos_topic.id) SiteSetting.tos_topic_id = tos_topic.id
expect(Guardian.new(admin).can_delete?(tos_topic)).to be_falsey expect(Guardian.new(admin).can_delete?(tos_topic)).to be_falsey
end end
end end
@ -1478,7 +1480,7 @@ describe Guardian do
it 'returns false when post is first in a static doc topic' do it 'returns false when post is first in a static doc topic' do
tos_topic = Fabricate(:topic, user: Discourse.system_user) tos_topic = Fabricate(:topic, user: Discourse.system_user)
SiteSetting.stubs(:tos_topic_id).returns(tos_topic.id) SiteSetting.tos_topic_id = tos_topic.id
post.update_attribute :post_number, 1 post.update_attribute :post_number, 1
post.update_attribute :topic_id, tos_topic.id post.update_attribute :topic_id, tos_topic.id
expect(Guardian.new(admin).can_delete?(post)).to be_falsey expect(Guardian.new(admin).can_delete?(post)).to be_falsey
@ -1487,7 +1489,7 @@ describe Guardian do
context 'post is older than post_edit_time_limit' do context 'post is older than post_edit_time_limit' do
let(:old_post) { build(:post, topic: topic, user: topic.user, post_number: 2, created_at: 6.minutes.ago) } let(:old_post) { build(:post, topic: topic, user: topic.user, post_number: 2, created_at: 6.minutes.ago) }
before do before do
SiteSetting.stubs(:post_edit_time_limit).returns(5) SiteSetting.post_edit_time_limit = 5
end end
it 'returns false to the author of the post' do it 'returns false to the author of the post' do
@ -1781,7 +1783,7 @@ describe Guardian do
context "when must_approve_users is false" do context "when must_approve_users is false" do
before do before do
SiteSetting.stubs(:must_approve_users?).returns(false) SiteSetting.must_approve_users = false
end end
it "returns true for a nil user" do it "returns true for a nil user" do
@ -1795,7 +1797,7 @@ describe Guardian do
context 'when must_approve_users is true' do context 'when must_approve_users is true' do
before do before do
SiteSetting.stubs(:must_approve_users?).returns(true) SiteSetting.must_approve_users = true
end end
it "returns false for a nil user" do it "returns false for a nil user" do
@ -1860,7 +1862,7 @@ describe Guardian do
it "is true if user is not an admin and first post is not too old" do it "is true if user is not an admin and first post is not too old" do
user = Fabricate.build(:user, created_at: 100.days.ago) user = Fabricate.build(:user, created_at: 100.days.ago)
user.stubs(:first_post_created_at).returns(9.days.ago) user.stubs(:first_post_created_at).returns(9.days.ago)
SiteSetting.stubs(:delete_user_max_post_age).returns(10) SiteSetting.delete_user_max_post_age = 10
expect(Guardian.new(actor).can_delete_user?(user)).to be_truthy expect(Guardian.new(actor).can_delete_user?(user)).to be_truthy
end end
@ -1871,7 +1873,7 @@ describe Guardian do
it "is false if user's first post is too old" do it "is false if user's first post is too old" do
user = Fabricate.build(:user, created_at: 100.days.ago) user = Fabricate.build(:user, created_at: 100.days.ago)
user.stubs(:first_post_created_at).returns(11.days.ago) user.stubs(:first_post_created_at).returns(11.days.ago)
SiteSetting.stubs(:delete_user_max_post_age).returns(10) SiteSetting.delete_user_max_post_age = 10
expect(Guardian.new(actor).can_delete_user?(user)).to be_falsey expect(Guardian.new(actor).can_delete_user?(user)).to be_falsey
end end
end end
@ -1902,21 +1904,21 @@ describe Guardian do
shared_examples "can_delete_all_posts examples" do shared_examples "can_delete_all_posts examples" do
it "is true if user has no posts" do it "is true if user has no posts" do
SiteSetting.stubs(:delete_user_max_post_age).returns(10) SiteSetting.delete_user_max_post_age = 10
expect(Guardian.new(actor).can_delete_all_posts?(Fabricate(:user, created_at: 100.days.ago))).to be_truthy expect(Guardian.new(actor).can_delete_all_posts?(Fabricate(:user, created_at: 100.days.ago))).to be_truthy
end end
it "is true if user's first post is newer than delete_user_max_post_age days old" do it "is true if user's first post is newer than delete_user_max_post_age days old" do
user = Fabricate(:user, created_at: 100.days.ago) user = Fabricate(:user, created_at: 100.days.ago)
user.stubs(:first_post_created_at).returns(9.days.ago) user.stubs(:first_post_created_at).returns(9.days.ago)
SiteSetting.stubs(:delete_user_max_post_age).returns(10) SiteSetting.delete_user_max_post_age = 10
expect(Guardian.new(actor).can_delete_all_posts?(user)).to be_truthy expect(Guardian.new(actor).can_delete_all_posts?(user)).to be_truthy
end end
it "is false if user's first post is older than delete_user_max_post_age days old" do it "is false if user's first post is older than delete_user_max_post_age days old" do
user = Fabricate(:user, created_at: 100.days.ago) user = Fabricate(:user, created_at: 100.days.ago)
user.stubs(:first_post_created_at).returns(11.days.ago) user.stubs(:first_post_created_at).returns(11.days.ago)
SiteSetting.stubs(:delete_user_max_post_age).returns(10) SiteSetting.delete_user_max_post_age = 10
expect(Guardian.new(actor).can_delete_all_posts?(user)).to be_falsey expect(Guardian.new(actor).can_delete_all_posts?(user)).to be_falsey
end end
@ -1927,14 +1929,14 @@ describe Guardian do
it "is true if number of posts is small" do it "is true if number of posts is small" do
u = Fabricate(:user, created_at: 1.day.ago) u = Fabricate(:user, created_at: 1.day.ago)
u.stubs(:post_count).returns(1) u.stubs(:post_count).returns(1)
SiteSetting.stubs(:delete_all_posts_max).returns(10) SiteSetting.delete_all_posts_max = 10
expect(Guardian.new(actor).can_delete_all_posts?(u)).to be_truthy expect(Guardian.new(actor).can_delete_all_posts?(u)).to be_truthy
end end
it "is false if number of posts is not small" do it "is false if number of posts is not small" do
u = Fabricate(:user, created_at: 1.day.ago) u = Fabricate(:user, created_at: 1.day.ago)
u.stubs(:post_count).returns(11) u.stubs(:post_count).returns(11)
SiteSetting.stubs(:delete_all_posts_max).returns(10) SiteSetting.delete_all_posts_max = 10
expect(Guardian.new(actor).can_delete_all_posts?(u)).to be_falsey expect(Guardian.new(actor).can_delete_all_posts?(u)).to be_falsey
end end
end end
@ -2064,7 +2066,7 @@ describe Guardian do
context 'for an old user' do context 'for an old user' do
before do before do
SiteSetting.stubs(:username_change_period).returns(3) SiteSetting.username_change_period = 3
end end
let(:target_user) { Fabricate(:user, created_at: 4.days.ago) } let(:target_user) { Fabricate(:user, created_at: 4.days.ago) }
@ -2087,7 +2089,7 @@ describe Guardian do
context 'when editing is disabled in preferences' do context 'when editing is disabled in preferences' do
before do before do
SiteSetting.stubs(:username_change_period).returns(0) SiteSetting.username_change_period = 0
end end
include_examples "staff can always change usernames" include_examples "staff can always change usernames"
@ -2099,8 +2101,8 @@ describe Guardian do
context 'when SSO username override is active' do context 'when SSO username override is active' do
before do before do
SiteSetting.stubs(:enable_sso).returns(true) SiteSetting.enable_sso = true
SiteSetting.stubs(:sso_overrides_username).returns(true) SiteSetting.sso_overrides_username = true
end end
it "is false for admins" do it "is false for admins" do
@ -2120,7 +2122,7 @@ describe Guardian do
describe "can_edit_email?" do describe "can_edit_email?" do
context 'when allowed in settings' do context 'when allowed in settings' do
before do before do
SiteSetting.stubs(:email_editable?).returns(true) SiteSetting.email_editable = true
end end
it "is false when not logged in" do it "is false when not logged in" do
@ -2146,7 +2148,7 @@ describe Guardian do
context 'when not allowed in settings' do context 'when not allowed in settings' do
before do before do
SiteSetting.stubs(:email_editable?).returns(false) SiteSetting.email_editable = false
end end
it "is false when not logged in" do it "is false when not logged in" do
@ -2172,8 +2174,8 @@ describe Guardian do
context 'when SSO email override is active' do context 'when SSO email override is active' do
before do before do
SiteSetting.stubs(:enable_sso).returns(true) SiteSetting.enable_sso = true
SiteSetting.stubs(:sso_overrides_email).returns(true) SiteSetting.sso_overrides_email = true
end end
it "is false for admins" do it "is false for admins" do
@ -2217,7 +2219,7 @@ describe Guardian do
context 'when name is disabled in preferences' do context 'when name is disabled in preferences' do
before do before do
SiteSetting.stubs(:enable_names).returns(false) SiteSetting.enable_names = false
end end
it 'is false for the user to change their own name' do it 'is false for the user to change their own name' do
@ -2235,13 +2237,13 @@ describe Guardian do
context 'when name is enabled in preferences' do context 'when name is enabled in preferences' do
before do before do
SiteSetting.stubs(:enable_names).returns(true) SiteSetting.enable_names = true
end end
context 'when SSO is disabled' do context 'when SSO is disabled' do
before do before do
SiteSetting.stubs(:enable_sso).returns(false) SiteSetting.enable_sso = false
SiteSetting.stubs(:sso_overrides_name).returns(false) SiteSetting.sso_overrides_name = false
end end
it 'is true for admins' do it 'is true for admins' do
@ -2259,12 +2261,12 @@ describe Guardian do
context 'when SSO is enabled' do context 'when SSO is enabled' do
before do before do
SiteSetting.stubs(:enable_sso).returns(true) SiteSetting.enable_sso = true
end end
context 'when SSO name override is active' do context 'when SSO name override is active' do
before do before do
SiteSetting.stubs(:sso_overrides_name).returns(true) SiteSetting.sso_overrides_name = true
end end
it 'is false for admins' do it 'is false for admins' do
@ -2282,7 +2284,7 @@ describe Guardian do
context 'when SSO name override is not active' do context 'when SSO name override is not active' do
before do before do
SiteSetting.stubs(:sso_overrides_name).returns(false) SiteSetting.sso_overrides_name = false
end end
it 'is true for admins' do it 'is true for admins' do

View File

@ -4,8 +4,8 @@ require 'image_sizer'
describe ImageSizer do describe ImageSizer do
before do before do
SiteSetting.stubs(:max_image_width).returns(500) SiteSetting.max_image_width = 500
SiteSetting.stubs(:max_image_height).returns(500) SiteSetting.max_image_height = 500
end end
it 'returns the same dimensions when smaller than the maximums' do it 'returns the same dimensions when smaller than the maximums' do

View File

@ -8,19 +8,19 @@ describe Onebox::Engine::FlashVideoOnebox do
context "when SiteSetting.enable_flash_video_onebox is true" do context "when SiteSetting.enable_flash_video_onebox is true" do
before do before do
SiteSetting.stubs(:enable_flash_video_onebox).returns(true) SiteSetting.enable_flash_video_onebox = true
end end
it "generates a flash video" do it "generates a flash video" do
expect(@o.to_html).to match_html( expect(@o.to_html).to match_html(
"<object width='100%' height='100%'><param name='http://player.56.com/v_OTMyNTk1MzE.swf' value='http://player.56.com/v_OTMyNTk1MzE.swf'><embed src='http://player.56.com/v_OTMyNTk1MzE.swf' width='100%' height='100%'></embed></object>" "<object width='100%' height='100%'><param name='http://player.56.com/v_OTMyNTk1MzE.swf' value='http://player.56.com/v_OTMyNTk1MzE.swf'><embed src='http://player.56.com/v_OTMyNTk1MzE.swf' width='100%' height='100%'></embed></object>"
) )
end end
end end
context "when SiteSetting.enable_flash_video_onebox is false" do context "when SiteSetting.enable_flash_video_onebox is false" do
before do before do
SiteSetting.stubs(:enable_flash_video_onebox).returns(false) SiteSetting.enable_flash_video_onebox = false
end end
it "generates a link" do it "generates a link" do

View File

@ -51,7 +51,7 @@ describe PostDestroyer do
describe 'destroy_old_stubs' do describe 'destroy_old_stubs' do
it 'destroys stubs for deleted by user posts' do it 'destroys stubs for deleted by user posts' do
SiteSetting.stubs(:delete_removed_posts_after).returns(24) SiteSetting.delete_removed_posts_after = 24
Fabricate(:admin) Fabricate(:admin)
topic = post.topic topic = post.topic
reply1 = create_post(topic: topic) reply1 = create_post(topic: topic)
@ -102,7 +102,7 @@ describe PostDestroyer do
PostDestroyer.new(reply1.user, reply1).destroy PostDestroyer.new(reply1.user, reply1).destroy
PostDestroyer.new(reply2.user, reply2).destroy PostDestroyer.new(reply2.user, reply2).destroy
SiteSetting.stubs(:delete_removed_posts_after).returns(1) SiteSetting.delete_removed_posts_after = 1
reply2.update_column(:updated_at, 70.minutes.ago) reply2.update_column(:updated_at, 70.minutes.ago)
@ -114,7 +114,7 @@ describe PostDestroyer do
expect(reply1.deleted_at).to eq(nil) expect(reply1.deleted_at).to eq(nil)
expect(reply2.deleted_at).not_to eq(nil) expect(reply2.deleted_at).not_to eq(nil)
SiteSetting.stubs(:delete_removed_posts_after).returns(72) SiteSetting.delete_removed_posts_after = 72
reply1.update_column(:updated_at, 2.days.ago) reply1.update_column(:updated_at, 2.days.ago)
@ -122,7 +122,7 @@ describe PostDestroyer do
expect(reply1.reload.deleted_at).to eq(nil) expect(reply1.reload.deleted_at).to eq(nil)
SiteSetting.stubs(:delete_removed_posts_after).returns(47) SiteSetting.delete_removed_posts_after = 47
PostDestroyer.destroy_stubs PostDestroyer.destroy_stubs
@ -134,7 +134,7 @@ describe PostDestroyer do
topic = post.topic topic = post.topic
reply1 = create_post(topic: topic) reply1 = create_post(topic: topic)
SiteSetting.stubs(:delete_removed_posts_after).returns(0) SiteSetting.delete_removed_posts_after = 0
PostDestroyer.new(reply1.user, reply1).destroy PostDestroyer.new(reply1.user, reply1).destroy

View File

@ -73,7 +73,7 @@ describe PostRevisor do
describe 'ninja editing' do describe 'ninja editing' do
it 'correctly applies edits' do it 'correctly applies edits' do
SiteSetting.stubs(:editing_grace_period).returns(1.minute) SiteSetting.editing_grace_period = 1.minute
subject.revise!(post.user, { raw: 'updated body' }, revised_at: post.updated_at + 10.seconds) subject.revise!(post.user, { raw: 'updated body' }, revised_at: post.updated_at + 10.seconds)
post.reload post.reload
@ -86,7 +86,7 @@ describe PostRevisor do
end end
it "doesn't create a new version" do it "doesn't create a new version" do
SiteSetting.stubs(:editing_grace_period).returns(1.minute) SiteSetting.editing_grace_period = 1.minute
# making a revision # making a revision
subject.revise!(post.user, { raw: 'updated body' }, revised_at: post.updated_at + SiteSetting.editing_grace_period + 1.seconds) subject.revise!(post.user, { raw: 'updated body' }, revised_at: post.updated_at + SiteSetting.editing_grace_period + 1.seconds)
@ -106,7 +106,7 @@ describe PostRevisor do
let!(:revised_at) { post.updated_at + 2.minutes } let!(:revised_at) { post.updated_at + 2.minutes }
before do before do
SiteSetting.stubs(:editing_grace_period).returns(1.minute.to_i) SiteSetting.editing_grace_period = 1.minute
subject.revise!(post.user, { raw: 'updated body' }, revised_at: revised_at) subject.revise!(post.user, { raw: 'updated body' }, revised_at: revised_at)
post.reload post.reload
end end
@ -244,7 +244,7 @@ describe PostRevisor do
let(:changed_by) { Fabricate(:admin) } let(:changed_by) { Fabricate(:admin) }
before do before do
SiteSetting.stubs(:newuser_max_images).returns(0) SiteSetting.newuser_max_images = 0
url = "http://i.imgur.com/wfn7rgU.jpg" url = "http://i.imgur.com/wfn7rgU.jpg"
Oneboxer.stubs(:onebox).with(url, anything).returns("<img src='#{url}'>") Oneboxer.stubs(:onebox).with(url, anything).returns("<img src='#{url}'>")
subject.revise!(changed_by, { raw: "So, post them here!\n#{url}" }) subject.revise!(changed_by, { raw: "So, post them here!\n#{url}" })
@ -262,7 +262,7 @@ describe PostRevisor do
describe "new user editing their own post" do describe "new user editing their own post" do
before do before do
SiteSetting.stubs(:newuser_max_images).returns(0) SiteSetting.newuser_max_images = 0
url = "http://i.imgur.com/FGg7Vzu.gif" url = "http://i.imgur.com/FGg7Vzu.gif"
Oneboxer.stubs(:cached_onebox).with(url, anything).returns("<img src='#{url}'>") Oneboxer.stubs(:cached_onebox).with(url, anything).returns("<img src='#{url}'>")
subject.revise!(post.user, { raw: "So, post them here!\n#{url}" }) subject.revise!(post.user, { raw: "So, post them here!\n#{url}" })
@ -312,7 +312,7 @@ describe PostRevisor do
context 'second poster posts again quickly' do context 'second poster posts again quickly' do
before do before do
SiteSetting.stubs(:editing_grace_period).returns(1.minute.to_i) SiteSetting.editing_grace_period = 1.minute
subject.revise!(changed_by, { raw: 'yet another updated body' }, revised_at: post.updated_at + 10.seconds) subject.revise!(changed_by, { raw: 'yet another updated body' }, revised_at: post.updated_at + 10.seconds)
post.reload post.reload
end end
@ -326,7 +326,7 @@ describe PostRevisor do
context 'passing skip_revision as true' do context 'passing skip_revision as true' do
before do before do
SiteSetting.stubs(:editing_grace_period).returns(1.minute.to_i) SiteSetting.editing_grace_period = 1.minute
subject.revise!(changed_by, { raw: 'yet another updated body' }, { revised_at: post.updated_at + 10.hours, skip_revision: true }) subject.revise!(changed_by, { raw: 'yet another updated body' }, { revised_at: post.updated_at + 10.hours, skip_revision: true })
post.reload post.reload
end end

View File

@ -94,8 +94,8 @@ HTML
describe "rel nofollow" do describe "rel nofollow" do
before do before do
SiteSetting.stubs(:add_rel_nofollow_to_user_content).returns(true) SiteSetting.add_rel_nofollow_to_user_content = true
SiteSetting.stubs(:exclude_rel_nofollow_domains).returns("foo.com|bar.com") SiteSetting.exclude_rel_nofollow_domains = "foo.com|bar.com"
end end
it "should inject nofollow in all user provided links" do it "should inject nofollow in all user provided links" do

View File

@ -29,10 +29,10 @@ describe Rtl do
end end
context 'user locale is not allowed' do context 'user locale is not allowed' do
before { SiteSetting.stubs(:allow_user_locale).returns(false) } before { SiteSetting.allow_user_locale = false }
context 'site default locale is RTL' do context 'site default locale is RTL' do
before { SiteSetting.stubs(:default_locale).returns('he') } before { SiteSetting.default_locale = 'he' }
it 'returns rtl class' do it 'returns rtl class' do
expect(Rtl.new(user).css_class).to eq('rtl') expect(Rtl.new(user).css_class).to eq('rtl')
@ -40,7 +40,7 @@ describe Rtl do
end end
context 'site default locale is LTR' do context 'site default locale is LTR' do
before { SiteSetting.stubs(:default_locale).returns('en') } before { SiteSetting.default_locale = 'en' }
context 'user locale is RTL' do context 'user locale is RTL' do
before { user.stubs(:locale).returns('he') } before { user.stubs(:locale).returns('he') }

View File

@ -121,7 +121,7 @@ describe Search do
end end
context 'hiding user profiles' do context 'hiding user profiles' do
before { SiteSetting.stubs(:hide_user_profiles_from_public).returns(true) } before { SiteSetting.hide_user_profiles_from_public = true }
it 'returns no result for anon' do it 'returns no result for anon' do
expect(result.users.length).to eq(0) expect(result.users.length).to eq(0)

View File

@ -7,13 +7,13 @@ describe SpamHandler do
it "works" do it "works" do
# max_new_accounts_per_registration_ip = 0 disables the check # max_new_accounts_per_registration_ip = 0 disables the check
SiteSetting.stubs(:max_new_accounts_per_registration_ip).returns(0) SiteSetting.max_new_accounts_per_registration_ip = 0
Fabricate(:user, ip_address: "42.42.42.42", trust_level: TrustLevel[1]) Fabricate(:user, ip_address: "42.42.42.42", trust_level: TrustLevel[1])
Fabricate(:user, ip_address: "42.42.42.42", trust_level: TrustLevel[0]) Fabricate(:user, ip_address: "42.42.42.42", trust_level: TrustLevel[0])
# only prevents registration for TL0 # only prevents registration for TL0
SiteSetting.stubs(:max_new_accounts_per_registration_ip).returns(2) SiteSetting.max_new_accounts_per_registration_ip = 2
Fabricate(:user, ip_address: "42.42.42.42", trust_level: TrustLevel[1]) Fabricate(:user, ip_address: "42.42.42.42", trust_level: TrustLevel[1])
Fabricate(:user, ip_address: "42.42.42.42", trust_level: TrustLevel[0]) Fabricate(:user, ip_address: "42.42.42.42", trust_level: TrustLevel[0])
@ -24,36 +24,36 @@ describe SpamHandler do
it "doesn't limit registrations since there is a TL2+ user with that IP" do it "doesn't limit registrations since there is a TL2+ user with that IP" do
# setup # setup
SiteSetting.stubs(:max_new_accounts_per_registration_ip).returns(0) SiteSetting.max_new_accounts_per_registration_ip = 0
Fabricate(:user, ip_address: "42.42.42.42", trust_level: TrustLevel[0]) Fabricate(:user, ip_address: "42.42.42.42", trust_level: TrustLevel[0])
Fabricate(:user, ip_address: "42.42.42.42", trust_level: TrustLevel[2]) Fabricate(:user, ip_address: "42.42.42.42", trust_level: TrustLevel[2])
# should not limit registration # should not limit registration
SiteSetting.stubs(:max_new_accounts_per_registration_ip).returns(1) SiteSetting.max_new_accounts_per_registration_ip = 1
Fabricate(:user, ip_address: "42.42.42.42", trust_level: TrustLevel[0]) Fabricate(:user, ip_address: "42.42.42.42", trust_level: TrustLevel[0])
end end
it "doesn't limit registrations since there is a staff member with that IP" do it "doesn't limit registrations since there is a staff member with that IP" do
# setup # setup
SiteSetting.stubs(:max_new_accounts_per_registration_ip).returns(0) SiteSetting.max_new_accounts_per_registration_ip = 0
Fabricate(:user, ip_address: "42.42.42.42", trust_level: TrustLevel[0]) Fabricate(:user, ip_address: "42.42.42.42", trust_level: TrustLevel[0])
Fabricate(:moderator, ip_address: "42.42.42.42", trust_level: TrustLevel[0]) Fabricate(:moderator, ip_address: "42.42.42.42", trust_level: TrustLevel[0])
Group.refresh_automatic_groups!(:staff) Group.refresh_automatic_groups!(:staff)
# should not limit registration # should not limit registration
SiteSetting.stubs(:max_new_accounts_per_registration_ip).returns(1) SiteSetting.max_new_accounts_per_registration_ip = 1
Fabricate(:user, ip_address: "42.42.42.42", trust_level: TrustLevel[0]) Fabricate(:user, ip_address: "42.42.42.42", trust_level: TrustLevel[0])
end end
it "doesn't limit registrations when the IP is whitelisted" do it "doesn't limit registrations when the IP is whitelisted" do
# setup # setup
SiteSetting.stubs(:max_new_accounts_per_registration_ip).returns(0) SiteSetting.max_new_accounts_per_registration_ip = 0
Fabricate(:user, ip_address: "42.42.42.42", trust_level: TrustLevel[0]) Fabricate(:user, ip_address: "42.42.42.42", trust_level: TrustLevel[0])
ScreenedIpAddress.stubs(:is_whitelisted?).with("42.42.42.42").returns(true) ScreenedIpAddress.stubs(:is_whitelisted?).with("42.42.42.42").returns(true)
# should not limit registration # should not limit registration
SiteSetting.stubs(:max_new_accounts_per_registration_ip).returns(1) SiteSetting.max_new_accounts_per_registration_ip = 1
Fabricate(:user, ip_address: "42.42.42.42", trust_level: TrustLevel[0]) Fabricate(:user, ip_address: "42.42.42.42", trust_level: TrustLevel[0])
end end

View File

@ -7,7 +7,7 @@ describe SuggestedTopicsBuilder do
let(:builder) { SuggestedTopicsBuilder.new(topic) } let(:builder) { SuggestedTopicsBuilder.new(topic) }
before do before do
SiteSetting.stubs(:suggested_topics).returns(5) SiteSetting.suggested_topics = 5
end end
context "splicing category results" do context "splicing category results" do

View File

@ -79,7 +79,7 @@ describe TextSentinel do
end end
it "allows all caps topics when loud posts are allowed" do it "allows all caps topics when loud posts are allowed" do
SiteSetting.stubs(:allow_uppercase_posts).returns(true) SiteSetting.allow_uppercase_posts = true
expect(TextSentinel.new(valid_string.upcase)).to be_valid expect(TextSentinel.new(valid_string.upcase)).to be_valid
end end
@ -126,8 +126,8 @@ describe TextSentinel do
context 'title_sentinel' do context 'title_sentinel' do
it "uses a sensible min entropy value when min title length is less than title_min_entropy" do it "uses a sensible min entropy value when min title length is less than title_min_entropy" do
SiteSetting.stubs(:min_topic_title_length).returns(3) SiteSetting.min_topic_title_length = 3
SiteSetting.stubs(:title_min_entropy).returns(10) SiteSetting.title_min_entropy = 10
expect(TextSentinel.title_sentinel('Hey')).to be_valid expect(TextSentinel.title_sentinel('Hey')).to be_valid
end end
@ -136,15 +136,15 @@ describe TextSentinel do
context 'body_sentinel' do context 'body_sentinel' do
it "uses a sensible min entropy value when min body length is less than min entropy" do it "uses a sensible min entropy value when min body length is less than min entropy" do
SiteSetting.stubs(:min_post_length).returns(3) SiteSetting.min_post_length = 3
SiteSetting.stubs(:body_min_entropy).returns(7) SiteSetting.body_min_entropy = 7
expect(TextSentinel.body_sentinel('Yup')).to be_valid expect(TextSentinel.body_sentinel('Yup')).to be_valid
end end
it "uses a sensible min entropy value when min pm body length is less than min entropy" do it "uses a sensible min entropy value when min pm body length is less than min entropy" do
SiteSetting.stubs(:min_post_length).returns(5) SiteSetting.min_post_length = 5
SiteSetting.stubs(:min_private_message_post_length).returns(3) SiteSetting.min_private_message_post_length = 3
SiteSetting.stubs(:body_min_entropy).returns(7) SiteSetting.body_min_entropy = 7
expect(TextSentinel.body_sentinel('Lol', private_message: true)).to be_valid expect(TextSentinel.body_sentinel('Lol', private_message: true)).to be_valid
end end
end end

View File

@ -14,7 +14,7 @@ describe TopicCreator do
before do before do
TopicCreator.any_instance.expects(:save_topic).returns(true) TopicCreator.any_instance.expects(:save_topic).returns(true)
TopicCreator.any_instance.expects(:watch_topic).returns(true) TopicCreator.any_instance.expects(:watch_topic).returns(true)
SiteSetting.stubs(:allow_duplicate_topic_titles?).returns(true) SiteSetting.allow_duplicate_topic_titles = true
end end
it "should be possible for an admin to create a topic" do it "should be possible for an admin to create a topic" do
@ -26,7 +26,7 @@ describe TopicCreator do
end end
context 'regular user' do context 'regular user' do
before { SiteSetting.stubs(:min_trust_to_create_topic).returns(TrustLevel[0]) } before { SiteSetting.min_trust_to_create_topic = TrustLevel[0] }
it "should be possible for a regular user to create a topic" do it "should be possible for a regular user to create a topic" do
expect(TopicCreator.create(user, Guardian.new(user), valid_attrs)).to be_valid expect(TopicCreator.create(user, Guardian.new(user), valid_attrs)).to be_valid
@ -57,7 +57,7 @@ describe TopicCreator do
before do before do
TopicCreator.any_instance.expects(:save_topic).returns(true) TopicCreator.any_instance.expects(:save_topic).returns(true)
TopicCreator.any_instance.expects(:watch_topic).returns(true) TopicCreator.any_instance.expects(:watch_topic).returns(true)
SiteSetting.stubs(:allow_duplicate_topic_titles?).returns(true) SiteSetting.allow_duplicate_topic_titles = true
end end
it "should be possible for a regular user to send private message" do it "should be possible for a regular user to send private message" do

View File

@ -19,7 +19,7 @@ describe PasswordValidator do
end end
context "min password length is 8" do context "min password length is 8" do
before { SiteSetting.stubs(:min_password_length).returns(8) } before { SiteSetting.min_password_length = 8 }
it "doesn't add an error when password is good" do it "doesn't add an error when password is good" do
@password = "weron235alsfn234" @password = "weron235alsfn234"
@ -56,7 +56,7 @@ describe PasswordValidator do
end end
context "min password length is 12" do context "min password length is 12" do
before { SiteSetting.stubs(:min_password_length).returns(12) } before { SiteSetting.min_password_length = 12 }
it "adds an error when password length is 11" do it "adds an error when password length is 11" do
@password = "gt38sdt92bv" @password = "gt38sdt92bv"
@ -68,19 +68,19 @@ describe PasswordValidator do
context "password is commonly used" do context "password is commonly used" do
before do before do
SiteSetting.stubs(:min_password_length).returns(8) SiteSetting.min_password_length = 8
CommonPasswords.stubs(:common_password?).returns(true) CommonPasswords.stubs(:common_password?).returns(true)
end end
it "adds an error when block_common_passwords is enabled" do it "adds an error when block_common_passwords is enabled" do
SiteSetting.stubs(:block_common_passwords).returns(true) SiteSetting.block_common_passwords = true
@password = "password" @password = "password"
validate validate
expect(record.errors[:password]).to include(password_error_message(:common)) expect(record.errors[:password]).to include(password_error_message(:common))
end end
it "doesn't add an error when block_common_passwords is disabled" do it "doesn't add an error when block_common_passwords is disabled" do
SiteSetting.stubs(:block_common_passwords).returns(false) SiteSetting.block_common_passwords = false
@password = "password" @password = "password"
validate validate
expect(record.errors[:password]).not_to be_present expect(record.errors[:password]).not_to be_present

View File

@ -2,7 +2,7 @@ require 'rails_helper'
require_dependency 'validators/post_validator' require_dependency 'validators/post_validator'
describe Validators::PostValidator do describe Validators::PostValidator do
let(:post) { build(:post) } let(:post) { build(:post, topic: Fabricate(:topic)) }
let(:validator) { Validators::PostValidator.new({}) } let(:validator) { Validators::PostValidator.new({}) }
context "#post_body_validator" do context "#post_body_validator" do
@ -144,7 +144,7 @@ describe Validators::PostValidator do
describe "unique_post_validator" do describe "unique_post_validator" do
before do before do
SiteSetting.stubs(:unique_posts_mins).returns(5) SiteSetting.unique_posts_mins = 5
end end
context "post is unique" do context "post is unique" do
@ -193,7 +193,7 @@ describe Validators::PostValidator do
context "admin editing a static page" do context "admin editing a static page" do
before do before do
post.acting_user = build(:admin) post.acting_user = build(:admin)
SiteSetting.stubs(:tos_topic_id).returns(post.topic_id) SiteSetting.tos_topic_id = post.topic_id
end end
include_examples "almost no validations" include_examples "almost no validations"

View File

@ -39,7 +39,7 @@ describe TopicTitleLengthValidator do
validate validate
expect(record.errors[:title]).to_not be_present expect(record.errors[:title]).to_not be_present
SiteSetting.stubs(:min_topic_title_length).returns(2) SiteSetting.min_topic_title_length = 2
record.title = 'aaa' record.title = 'aaa'
validate validate

View File

@ -6,7 +6,7 @@ describe UserFullNameValidator do
let(:record) { Fabricate.build(:user, name: @name) } let(:record) { Fabricate.build(:user, name: @name) }
context "name not required" do context "name not required" do
before { SiteSetting.stubs(:full_name_required).returns(false) } before { SiteSetting.full_name_required = false }
it "allows no name" do it "allows no name" do
@name = nil @name = nil
@ -22,7 +22,7 @@ describe UserFullNameValidator do
end end
context "name required" do context "name required" do
before { SiteSetting.stubs(:full_name_required).returns(true) } before { SiteSetting.full_name_required = true }
it "adds error for nil name" do it "adds error for nil name" do
@name = nil @name = nil

View File

@ -22,7 +22,7 @@ describe Admin::DashboardController do
context 'version checking is enabled' do context 'version checking is enabled' do
before do before do
SiteSetting.stubs(:version_checks).returns(true) SiteSetting.version_checks = true
end end
it 'returns discourse version info' do it 'returns discourse version info' do
@ -34,7 +34,7 @@ describe Admin::DashboardController do
context 'version checking is disabled' do context 'version checking is disabled' do
before do before do
SiteSetting.stubs(:version_checks).returns(false) SiteSetting.version_checks = false
end end
it 'does not return discourse version info' do it 'does not return discourse version info' do

View File

@ -42,7 +42,7 @@ describe Admin::ScreenedIpAddressesController do
Fabricate(:screened_ip_address, ip_address: "42.42.42.5", match_count: 1) Fabricate(:screened_ip_address, ip_address: "42.42.42.5", match_count: 1)
StaffActionLogger.any_instance.expects(:log_roll_up) StaffActionLogger.any_instance.expects(:log_roll_up)
SiteSetting.stubs(:min_ban_entries_for_roll_up).returns(3) SiteSetting.min_ban_entries_for_roll_up = 3
xhr :post, :roll_up xhr :post, :roll_up
expect(response).to be_success expect(response).to be_success
@ -62,7 +62,7 @@ describe Admin::ScreenedIpAddressesController do
Fabricate(:screened_ip_address, ip_address: "1.2.42.0/24", match_count: 1) Fabricate(:screened_ip_address, ip_address: "1.2.42.0/24", match_count: 1)
StaffActionLogger.any_instance.expects(:log_roll_up) StaffActionLogger.any_instance.expects(:log_roll_up)
SiteSetting.stubs(:min_ban_entries_for_roll_up).returns(5) SiteSetting.min_ban_entries_for_roll_up = 5
xhr :post, :roll_up xhr :post, :roll_up
expect(response).to be_success expect(response).to be_success

View File

@ -30,20 +30,21 @@ describe Admin::SiteSettingsController do
end end
it 'sets the value when the param is present' do it 'sets the value when the param is present' do
SiteSetting.expects(:'test_setting=').with('hello').once
xhr :put, :update, id: 'test_setting', test_setting: 'hello' xhr :put, :update, id: 'test_setting', test_setting: 'hello'
expect(SiteSetting.test_setting).to eq('hello')
end end
it 'allows value to be a blank string' do it 'allows value to be a blank string' do
SiteSetting.expects(:'test_setting=').with('').once
xhr :put, :update, id: 'test_setting', test_setting: '' xhr :put, :update, id: 'test_setting', test_setting: ''
expect(SiteSetting.test_setting).to eq('')
end end
it 'logs the change' do it 'logs the change' do
SiteSetting.stubs(:test_setting).returns('previous') SiteSetting.test_setting = 'previous'
SiteSetting.expects(:'test_setting=').with('hello').once
StaffActionLogger.any_instance.expects(:log_site_setting_change).with('test_setting', 'previous', 'hello') StaffActionLogger.any_instance.expects(:log_site_setting_change).with('test_setting', 'previous', 'hello')
xhr :put, :update, id: 'test_setting', test_setting: 'hello' xhr :put, :update, id: 'test_setting', test_setting: 'hello'
expect(SiteSetting.test_setting).to eq('hello')
end end
it 'does not allow changing of hidden settings' do it 'does not allow changing of hidden settings' do

View File

@ -177,8 +177,8 @@ describe TopicsController do
context "allow_user_locale disabled" do context "allow_user_locale disabled" do
context "accept-language header differs from default locale" do context "accept-language header differs from default locale" do
before do before do
SiteSetting.stubs(:allow_user_locale).returns(false) SiteSetting.allow_user_locale = false
SiteSetting.stubs(:default_locale).returns("en") SiteSetting.default_locale = "en"
set_accept_language("fr") set_accept_language("fr")
end end
@ -206,9 +206,9 @@ describe TopicsController do
context "set_locale_from_accept_language_header enabled" do context "set_locale_from_accept_language_header enabled" do
context "accept-language header differs from default locale" do context "accept-language header differs from default locale" do
before do before do
SiteSetting.stubs(:allow_user_locale).returns(true) SiteSetting.allow_user_locale = true
SiteSetting.stubs(:set_locale_from_accept_language_header).returns(true) SiteSetting.set_locale_from_accept_language_header = true
SiteSetting.stubs(:default_locale).returns("en") SiteSetting.default_locale = "en"
set_accept_language("fr") set_accept_language("fr")
end end
@ -234,8 +234,9 @@ describe TopicsController do
context "the preferred locale includes a region" do context "the preferred locale includes a region" do
it "returns the locale and region separated by an underscore" do it "returns the locale and region separated by an underscore" do
SiteSetting.stubs(:set_locale_from_accept_language_header).returns(true) SiteSetting.allow_user_locale = true
SiteSetting.stubs(:default_locale).returns("en") SiteSetting.set_locale_from_accept_language_header = true
SiteSetting.default_locale = "en"
set_accept_language("zh-CN") set_accept_language("zh-CN")
get :show, {topic_id: topic.id} get :show, {topic_id: topic.id}
@ -246,8 +247,8 @@ describe TopicsController do
context 'accept-language header is not set' do context 'accept-language header is not set' do
it 'uses the site default locale' do it 'uses the site default locale' do
SiteSetting.stubs(:allow_user_locale).returns(true) SiteSetting.allow_user_locale = true
SiteSetting.stubs(:default_locale).returns('en') SiteSetting.default_locale = 'en'
set_accept_language('') set_accept_language('')
get :show, {topic_id: topic.id} get :show, {topic_id: topic.id}

View File

@ -283,7 +283,7 @@ describe InvitesController do
context 'new registrations are disabled' do context 'new registrations are disabled' do
let(:topic) { Fabricate(:topic) } let(:topic) { Fabricate(:topic) }
let(:invite) { topic.invite_by_email(topic.user, "iceking@adventuretime.ooo") } let(:invite) { topic.invite_by_email(topic.user, "iceking@adventuretime.ooo") }
before { SiteSetting.stubs(:allow_new_registrations).returns(false) } before { SiteSetting.allow_new_registrations = false }
it "doesn't redeem the invite" do it "doesn't redeem the invite" do
Invite.any_instance.stubs(:redeem).never Invite.any_instance.stubs(:redeem).never

View File

@ -8,7 +8,7 @@ describe ListController do
@post = Fabricate(:post, user: @user) @post = Fabricate(:post, user: @user)
# forces tests down some code paths # forces tests down some code paths
SiteSetting.stubs(:top_menu).returns('latest,-video|new|unread|categories|category/beer') SiteSetting.top_menu = 'latest,-video|new|unread|categories|category/beer'
end end
describe 'titles for crawler layout' do describe 'titles for crawler layout' do

View File

@ -889,7 +889,7 @@ describe PostsController do
context "when edit history is not visible to the public" do context "when edit history is not visible to the public" do
before { SiteSetting.stubs(:edit_history_visible_to_public).returns(false) } before { SiteSetting.edit_history_visible_to_public = false }
it "ensures anonymous cannot see the revisions" do it "ensures anonymous cannot see the revisions" do
xhr :get, :revisions, post_id: post_revision.post_id, revision: post_revision.number xhr :get, :revisions, post_id: post_revision.post_id, revision: post_revision.number
@ -926,7 +926,7 @@ describe PostsController do
context "when edit history is visible to everyone" do context "when edit history is visible to everyone" do
before { SiteSetting.stubs(:edit_history_visible_to_public).returns(true) } before { SiteSetting.edit_history_visible_to_public = true }
it "ensures anyone can see the revisions" do it "ensures anyone can see the revisions" do
xhr :get, :revisions, post_id: post_revision.post_id, revision: post_revision.number xhr :get, :revisions, post_id: post_revision.post_id, revision: post_revision.number

View File

@ -36,7 +36,7 @@ describe SessionController do
# send welcome messages # send welcome messages
Fabricate(:admin) Fabricate(:admin)
# skip for now # skip for now
# SiteSetting.stubs("send_welcome_message").returns(false) # SiteSetting.send_welcome_message = false
end end
def get_sso(return_path) def get_sso(return_path)
@ -343,9 +343,9 @@ describe SessionController do
describe 'local attribute override from SSO payload' do describe 'local attribute override from SSO payload' do
before do before do
SiteSetting.stubs("sso_overrides_email").returns(true) SiteSetting.sso_overrides_email = true
SiteSetting.stubs("sso_overrides_username").returns(true) SiteSetting.sso_overrides_username = true
SiteSetting.stubs("sso_overrides_name").returns(true) SiteSetting.sso_overrides_name = true
@user = Fabricate(:user) @user = Fabricate(:user)
@ -525,7 +525,7 @@ describe SessionController do
describe 'local logins disabled' do describe 'local logins disabled' do
it 'fails' do it 'fails' do
SiteSetting.stubs(:enable_local_logins).returns(false) SiteSetting.enable_local_logins = false
xhr :post, :create, login: user.username, password: 'myawesomepassword' xhr :post, :create, login: user.username, password: 'myawesomepassword'
expect(response.status.to_i).to eq(500) expect(response.status.to_i).to eq(500)
end end
@ -617,7 +617,7 @@ describe SessionController do
let(:permitted_ip_address) { '111.234.23.11' } let(:permitted_ip_address) { '111.234.23.11' }
before do before do
Fabricate(:screened_ip_address, ip_address: permitted_ip_address, action_type: ScreenedIpAddress.actions[:allow_admin]) Fabricate(:screened_ip_address, ip_address: permitted_ip_address, action_type: ScreenedIpAddress.actions[:allow_admin])
SiteSetting.stubs(:use_admin_ip_whitelist).returns(true) SiteSetting.use_admin_ip_whitelist = true
end end
it 'is successful for admin at the ip address' do it 'is successful for admin at the ip address' do

View File

@ -16,7 +16,7 @@ describe SimilarTopicsController do
it "returns no results if the title length is below the minimum" do it "returns no results if the title length is below the minimum" do
Topic.expects(:similar_to).never Topic.expects(:similar_to).never
SiteSetting.stubs(:min_title_similar_length).returns(100) SiteSetting.min_title_similar_length = 100
xhr :get, :index, title: title, raw: raw xhr :get, :index, title: title, raw: raw
json = ::JSON.parse(response.body) json = ::JSON.parse(response.body)
expect(json["similar_topics"].size).to eq(0) expect(json["similar_topics"].size).to eq(0)
@ -24,7 +24,7 @@ describe SimilarTopicsController do
it "returns no results if the body length is below the minimum" do it "returns no results if the body length is below the minimum" do
Topic.expects(:similar_to).never Topic.expects(:similar_to).never
SiteSetting.stubs(:min_body_similar_length).returns(100) SiteSetting.min_body_similar_length = 100
xhr :get, :index, title: title, raw: raw xhr :get, :index, title: title, raw: raw
json = ::JSON.parse(response.body) json = ::JSON.parse(response.body)
expect(json["similar_topics"].size).to eq(0) expect(json["similar_topics"].size).to eq(0)
@ -33,7 +33,7 @@ describe SimilarTopicsController do
describe "minimum_topics_similar" do describe "minimum_topics_similar" do
before do before do
SiteSetting.stubs(:minimum_topics_similar).returns(30) SiteSetting.minimum_topics_similar = 30
end end
after do after do
@ -69,4 +69,3 @@ describe SimilarTopicsController do
end end
end end

View File

@ -54,9 +54,9 @@ describe StaticController do
context 'show' do context 'show' do
before do before do
post = create_post post = create_post
SiteSetting.stubs(:tos_topic_id).returns(post.topic.id) SiteSetting.tos_topic_id = post.topic.id
SiteSetting.stubs(:guidelines_topic_id).returns(post.topic.id) SiteSetting.guidelines_topic_id = post.topic.id
SiteSetting.stubs(:privacy_topic_id).returns(post.topic.id) SiteSetting.privacy_topic_id = post.topic.id
end end
context "with a static file that's present" do context "with a static file that's present" do
@ -87,7 +87,7 @@ describe StaticController do
end end
context "when #{setting_name} site setting is set" do context "when #{setting_name} site setting is set" do
before { SiteSetting.stubs(setting_name).returns('http://example.com/page') } before { SiteSetting.public_send("#{setting_name}=", 'http://example.com/page') }
it "redirects to the #{setting_name}" do it "redirects to the #{setting_name}" do
expect(subject).to redirect_to('http://example.com/page') expect(subject).to redirect_to('http://example.com/page')
@ -110,7 +110,7 @@ describe StaticController do
end end
it "should display the login template when login is required" do it "should display the login template when login is required" do
SiteSetting.stubs(:login_required).returns(true) SiteSetting.login_required = true
xhr :get, :show, id: 'login' xhr :get, :show, id: 'login'
expect(response).to be_success expect(response).to be_success
end end

View File

@ -996,7 +996,7 @@ describe TopicsController do
context "allow_uncategorized_topics is false" do context "allow_uncategorized_topics is false" do
before do before do
SiteSetting.stubs(:allow_uncategorized_topics).returns(false) SiteSetting.allow_uncategorized_topics = false
end end
it "can add a category to an uncategorized topic" do it "can add a category to an uncategorized topic" do

View File

@ -14,7 +14,7 @@ describe ApplicationHelper do
describe "mobile_view?" do describe "mobile_view?" do
context "enable_mobile_theme is true" do context "enable_mobile_theme is true" do
before do before do
SiteSetting.stubs(:enable_mobile_theme).returns(true) SiteSetting.enable_mobile_theme = true
end end
it "is true if mobile_view is '1' in the session" do it "is true if mobile_view is '1' in the session" do
@ -67,7 +67,7 @@ describe ApplicationHelper do
context "enable_mobile_theme is false" do context "enable_mobile_theme is false" do
before do before do
SiteSetting.stubs(:enable_mobile_theme).returns(false) SiteSetting.enable_mobile_theme = false
end end
it "is false if mobile_view is '1' in the session" do it "is false if mobile_view is '1' in the session" do

View File

@ -18,14 +18,9 @@ describe Jobs::EnqueueDigestEmails do
let!(:unapproved_user) { Fabricate(:active_user, approved: false, last_emailed_at: 8.days.ago, last_seen_at: 10.days.ago) } let!(:unapproved_user) { Fabricate(:active_user, approved: false, last_emailed_at: 8.days.ago, last_seen_at: 10.days.ago) }
before do before do
@original_value = SiteSetting.must_approve_users
SiteSetting.must_approve_users = true SiteSetting.must_approve_users = true
end end
after do
SiteSetting.must_approve_users = @original_value
end
it 'should enqueue the right digest emails' do it 'should enqueue the right digest emails' do
expect(Jobs::EnqueueDigestEmails.new.target_user_ids.include?(unapproved_user.id)).to eq(false) expect(Jobs::EnqueueDigestEmails.new.target_user_ids.include?(unapproved_user.id)).to eq(false)
@ -123,7 +118,7 @@ describe Jobs::EnqueueDigestEmails do
end end
it "enqueues the digest email job" do it "enqueues the digest email job" do
SiteSetting.stubs(:disable_digest_emails?).returns(false) SiteSetting.disable_digest_emails = false
Jobs.expects(:enqueue).with(:user_email, type: :digest, user_id: user.id) Jobs.expects(:enqueue).with(:user_email, type: :digest, user_id: user.id)
Jobs::EnqueueDigestEmails.new.execute({}) Jobs::EnqueueDigestEmails.new.execute({})
end end

View File

@ -2,7 +2,7 @@ require 'rails_helper'
describe Jobs::PendingFlagsReminder do describe Jobs::PendingFlagsReminder do
context "notify_about_flags_after is 0" do context "notify_about_flags_after is 0" do
before { SiteSetting.stubs(:notify_about_flags_after).returns(0) } before { SiteSetting.notify_about_flags_after = 0 }
it "never notifies" do it "never notifies" do
PostAction.stubs(:flagged_posts_count).returns(1) PostAction.stubs(:flagged_posts_count).returns(1)

View File

@ -2,7 +2,7 @@ require "rails_helper"
describe Jobs::PendingQueuedPostReminder do describe Jobs::PendingQueuedPostReminder do
context "notify_about_queued_posts_after is 0" do context "notify_about_queued_posts_after is 0" do
before { SiteSetting.stubs(:notify_about_queued_posts_after).returns(0) } before { SiteSetting.notify_about_queued_posts_after = 0 }
it "never emails" do it "never emails" do
described_class.any_instance.expects(:should_notify_ids).never described_class.any_instance.expects(:should_notify_ids).never

View File

@ -43,7 +43,7 @@ describe Jobs::PendingUsersReminder do
context 'must_approve_users is false' do context 'must_approve_users is false' do
before do before do
SiteSetting.stubs(:must_approve_users).returns(false) SiteSetting.must_approve_users = false
end end
it "doesn't send a message to anyone when there are pending users" do it "doesn't send a message to anyone when there are pending users" do

View File

@ -162,7 +162,7 @@ describe Jobs::UserEmail do
end end
context 'user is anonymous' do context 'user is anonymous' do
before { SiteSetting.stubs(:allow_anonymous_posting).returns(true) } before { SiteSetting.allow_anonymous_posting = true }
it "doesn't send email for a pm from a regular user" do it "doesn't send email for a pm from a regular user" do
Email::Sender.any_instance.expects(:send).never Email::Sender.any_instance.expects(:send).never
@ -332,7 +332,7 @@ describe Jobs::UserEmail do
end end
context 'user is anonymous' do context 'user is anonymous' do
before { SiteSetting.stubs(:allow_anonymous_posting).returns(true) } before { SiteSetting.allow_anonymous_posting = true }
it "doesn't send email for a pm from a regular user" do it "doesn't send email for a pm from a regular user" do
Email::Sender.any_instance.expects(:send).never Email::Sender.any_instance.expects(:send).never

View File

@ -128,37 +128,37 @@ describe AdminDashboardData do
shared_examples 'problem detection for login providers' do shared_examples 'problem detection for login providers' do
context 'when disabled' do context 'when disabled' do
it 'returns nil' do it 'returns nil' do
SiteSetting.stubs(enable_setting).returns(false) SiteSetting.public_send("#{enable_setting}=", false)
expect(subject).to be_nil expect(subject).to be_nil
end end
end end
context 'when enabled' do context 'when enabled' do
before do before do
SiteSetting.stubs(enable_setting).returns(true) SiteSetting.public_send("#{enable_setting}=", true)
end end
it 'returns nil when key and secret are set' do it 'returns nil when key and secret are set' do
SiteSetting.stubs(key).returns('12313213') SiteSetting.public_send("#{key}=", '12313213')
SiteSetting.stubs(secret).returns('12312313123') SiteSetting.public_send("#{secret}=", '12312313123')
expect(subject).to be_nil expect(subject).to be_nil
end end
it 'returns a string when key is not set' do it 'returns a string when key is not set' do
SiteSetting.stubs(key).returns('') SiteSetting.public_send("#{key}=", '')
SiteSetting.stubs(secret).returns('12312313123') SiteSetting.public_send("#{secret}=", '12312313123')
expect(subject).to_not be_nil expect(subject).to_not be_nil
end end
it 'returns a string when secret is not set' do it 'returns a string when secret is not set' do
SiteSetting.stubs(key).returns('123123') SiteSetting.public_send("#{key}=", '123123')
SiteSetting.stubs(secret).returns('') SiteSetting.public_send("#{secret}=", '')
expect(subject).to_not be_nil expect(subject).to_not be_nil
end end
it 'returns a string when key and secret are not set' do it 'returns a string when key and secret are not set' do
SiteSetting.stubs(key).returns('') SiteSetting.public_send("#{key}=", '')
SiteSetting.stubs(secret).returns('') SiteSetting.public_send("#{secret}=", '')
expect(subject).to_not be_nil expect(subject).to_not be_nil
end end
end end
@ -200,7 +200,7 @@ describe AdminDashboardData do
['a', ''].repeated_permutation(keys.size) do |*values| ['a', ''].repeated_permutation(keys.size) do |*values|
hash = Hash[keys.zip(values)] hash = Hash[keys.zip(values)]
hash.each do |key,value| hash.each do |key,value|
SiteSetting.stubs(key).returns(value) SiteSetting.public_send("#{key}=", value)
end end
yield hash yield hash
end end
@ -209,8 +209,8 @@ describe AdminDashboardData do
context 'when setting is enabled' do context 'when setting is enabled' do
let(:setting_enabled) { true } let(:setting_enabled) { true }
before do before do
SiteSetting.stubs(setting_key).returns(setting_enabled) SiteSetting.public_send("#{setting_key}=", setting_enabled)
SiteSetting.stubs(bucket_key).returns(bucket_value) SiteSetting.public_send("#{bucket_key}=", bucket_value)
end end
context 'when bucket is blank' do context 'when bucket is blank' do
@ -226,7 +226,7 @@ describe AdminDashboardData do
context 'when bucket is filled in' do context 'when bucket is filled in' do
let(:bucket_value) { 'a' } let(:bucket_value) { 'a' }
before do before do
SiteSetting.stubs(:s3_use_iam_profile).returns(use_iam_profile) SiteSetting.public_send("s3_use_iam_profile=", use_iam_profile)
end end
context 'when using iam profile' do context 'when using iam profile' do
@ -257,7 +257,7 @@ describe AdminDashboardData do
context 'when setting is not enabled' do context 'when setting is not enabled' do
before do before do
SiteSetting.stubs(setting_key).returns(false) SiteSetting.public_send("#{setting_key}=", false)
end end
it "always returns nil" do it "always returns nil" do

View File

@ -94,7 +94,7 @@ describe CategoryList do
context 'fixed_category_positions is enabled' do context 'fixed_category_positions is enabled' do
before do before do
SiteSetting.stubs(:fixed_category_positions).returns(true) SiteSetting.fixed_category_positions = true
end end
it "returns categories in specified order" do it "returns categories in specified order" do
@ -114,7 +114,7 @@ describe CategoryList do
context 'fixed_category_positions is disabled' do context 'fixed_category_positions is disabled' do
before do before do
SiteSetting.stubs(:fixed_category_positions).returns(false) SiteSetting.fixed_category_positions = false
end end
it "returns categories in order of activity" do it "returns categories in order of activity" do

View File

@ -476,7 +476,7 @@ describe Category do
before do before do
post = create_post(user: @category.user, category: @category.id) post = create_post(user: @category.user, category: @category.id)
SiteSetting.stubs(:editing_grace_period).returns(1.minute.to_i) SiteSetting.editing_grace_period = 1.minute
post.revise(post.user, { raw: 'updated body' }, revised_at: post.updated_at + 2.minutes) post.revise(post.user, { raw: 'updated body' }, revised_at: post.updated_at + 2.minutes)
Category.update_stats Category.update_stats

View File

@ -245,7 +245,7 @@ describe Invite do
context "invite trust levels" do context "invite trust levels" do
it "returns the trust level in default_invitee_trust_level" do it "returns the trust level in default_invitee_trust_level" do
SiteSetting.stubs(:default_invitee_trust_level).returns(TrustLevel[3]) SiteSetting.default_invitee_trust_level = TrustLevel[3]
expect(invite.redeem.trust_level).to eq(TrustLevel[3]) expect(invite.redeem.trust_level).to eq(TrustLevel[3])
end end
end end
@ -253,7 +253,7 @@ describe Invite do
context 'inviting when must_approve_users? is enabled' do context 'inviting when must_approve_users? is enabled' do
it 'correctly activates accounts' do it 'correctly activates accounts' do
invite.invited_by = Fabricate(:admin) invite.invited_by = Fabricate(:admin)
SiteSetting.stubs(:must_approve_users).returns(true) SiteSetting.must_approve_users = true
user = invite.redeem user = invite.redeem
expect(user.approved?).to eq(true) expect(user.approved?).to eq(true)
end end

View File

@ -319,7 +319,7 @@ describe PostAction do
it "returns the correct flag counts" do it "returns the correct flag counts" do
post = create_post post = create_post
SiteSetting.stubs(:flags_required_to_hide_post).returns(7) SiteSetting.flags_required_to_hide_post = 7
# A post with no flags has 0 for flag counts # A post with no flags has 0 for flag counts
expect(PostAction.flag_counts_for(post.id)).to eq([0, 0]) expect(PostAction.flag_counts_for(post.id)).to eq([0, 0])
@ -367,7 +367,7 @@ describe PostAction do
post = create_post post = create_post
walterwhite = Fabricate(:walter_white) walterwhite = Fabricate(:walter_white)
SiteSetting.stubs(:flags_required_to_hide_post).returns(2) SiteSetting.flags_required_to_hide_post = 2
Discourse.stubs(:site_contact_user).returns(admin) Discourse.stubs(:site_contact_user).returns(admin)
PostAction.act(eviltrout, post, PostActionType.types[:spam]) PostAction.act(eviltrout, post, PostActionType.types[:spam])

View File

@ -204,7 +204,7 @@ describe Post do
context "validation" do context "validation" do
before do before do
SiteSetting.stubs(:newuser_max_images).returns(1) SiteSetting.newuser_max_images = 1
end end
context 'newuser' do context 'newuser' do
@ -252,7 +252,7 @@ describe Post do
context "validation" do context "validation" do
before do before do
SiteSetting.stubs(:newuser_max_attachments).returns(1) SiteSetting.newuser_max_attachments = 1
end end
context 'newuser' do context 'newuser' do
@ -376,7 +376,7 @@ describe Post do
context "validation" do context "validation" do
before do before do
SiteSetting.stubs(:newuser_max_links).returns(1) SiteSetting.newuser_max_links = 1
end end
context 'newuser' do context 'newuser' do
@ -453,8 +453,8 @@ describe Post do
context 'new user' do context 'new user' do
before do before do
SiteSetting.stubs(:newuser_max_mentions_per_post).returns(1) SiteSetting.newuser_max_mentions_per_post = 1
SiteSetting.stubs(:max_mentions_per_post).returns(5) SiteSetting.max_mentions_per_post = 5
end end
it "allows a new user to have newuser_max_mentions_per_post mentions" do it "allows a new user to have newuser_max_mentions_per_post mentions" do
@ -468,8 +468,8 @@ describe Post do
context "not a new user" do context "not a new user" do
before do before do
SiteSetting.stubs(:newuser_max_mentions_per_post).returns(0) SiteSetting.newuser_max_mentions_per_post = 0
SiteSetting.stubs(:max_mentions_per_post).returns(1) SiteSetting.max_mentions_per_post = 1
end end
it "allows vmax_mentions_per_post mentions" do it "allows vmax_mentions_per_post mentions" do
@ -546,7 +546,7 @@ describe Post do
describe 'ninja editing & edit windows' do describe 'ninja editing & edit windows' do
before { SiteSetting.stubs(:editing_grace_period).returns(1.minute.to_i) } before { SiteSetting.editing_grace_period = 1.minute.to_i }
it 'works' do it 'works' do
revised_at = post.updated_at + 2.minutes revised_at = post.updated_at + 2.minutes
@ -741,7 +741,7 @@ describe Post do
let!(:p3) { Fabricate(:post, post_args.merge(score: 5, percent_rank: 0.99)) } let!(:p3) { Fabricate(:post, post_args.merge(score: 5, percent_rank: 0.99)) }
it "returns the OP and posts above the threshold in summary mode" do it "returns the OP and posts above the threshold in summary mode" do
SiteSetting.stubs(:summary_percent_filter).returns(66) SiteSetting.summary_percent_filter = 66
expect(Post.summary.order(:post_number)).to eq([p1, p2]) expect(Post.summary.order(:post_number)).to eq([p1, p2])
end end
@ -816,14 +816,14 @@ describe Post do
end end
it "when tl3_links_no_follow is false, should not add nofollow for trust level 3 and higher" do it "when tl3_links_no_follow is false, should not add nofollow for trust level 3 and higher" do
SiteSetting.stubs(:tl3_links_no_follow).returns(false) SiteSetting.tl3_links_no_follow = false
post.user.trust_level = 3 post.user.trust_level = 3
post.save post.save
expect(post.cooked).not_to match(/nofollow/) expect(post.cooked).not_to match(/nofollow/)
end end
it "when tl3_links_no_follow is true, should add nofollow for trust level 3 and higher" do it "when tl3_links_no_follow is true, should add nofollow for trust level 3 and higher" do
SiteSetting.stubs(:tl3_links_no_follow).returns(true) SiteSetting.tl3_links_no_follow = true
post.user.trust_level = 3 post.user.trust_level = 3
post.save post.save
expect(post.cooked).to match(/nofollow noopener/) expect(post.cooked).to match(/nofollow noopener/)
@ -927,7 +927,7 @@ describe Post do
end end
describe ".unhide!" do describe ".unhide!" do
before { SiteSetting.stubs(:unique_posts_mins).returns(5) } before { SiteSetting.unique_posts_mins = 5 }
it "will unhide the first post & make the topic visible" do it "will unhide the first post & make the topic visible" do
hidden_topic = Fabricate(:topic, visible: false) hidden_topic = Fabricate(:topic, visible: false)

View File

@ -246,7 +246,7 @@ describe ScreenedIpAddress do
end end
context "use_admin_ip_whitelist is true" do context "use_admin_ip_whitelist is true" do
before { SiteSetting.stubs(:use_admin_ip_whitelist).returns(true) } before { SiteSetting.use_admin_ip_whitelist = true }
it "returns false when user is nil" do it "returns false when user is nil" do
expect(described_class.block_admin_login?(nil, '123.12.12.12')).to eq(false) expect(described_class.block_admin_login?(nil, '123.12.12.12')).to eq(false)
@ -277,7 +277,7 @@ describe ScreenedIpAddress do
end end
context "use_admin_ip_whitelist is true" do context "use_admin_ip_whitelist is true" do
before { SiteSetting.stubs(:use_admin_ip_whitelist).returns(true) } before { SiteSetting.use_admin_ip_whitelist = true }
it "returns false when user is nil" do it "returns false when user is nil" do
expect(described_class.block_admin_login?(nil, @permitted_ip_address)).to eq(false) expect(described_class.block_admin_login?(nil, @permitted_ip_address)).to eq(false)

View File

@ -96,8 +96,8 @@ describe TopicEmbed do
response = nil response = nil
before(:each) do before do
SiteSetting.stubs(:embed_classname_whitelist).returns 'emoji , foo' SiteSetting.embed_classname_whitelist = 'emoji, foo'
file.stubs(:read).returns contents file.stubs(:read).returns contents
TopicEmbed.stubs(:open).returns file TopicEmbed.stubs(:open).returns file
response = TopicEmbed.find_remote(url) response = TopicEmbed.find_remote(url)
@ -155,7 +155,7 @@ describe TopicEmbed do
response = nil response = nil
before(:each) do before(:each) do
SiteSetting.stubs(:embed_classname_whitelist).returns ' ' SiteSetting.embed_classname_whitelist = ''
file.stubs(:read).returns contents file.stubs(:read).returns contents
TopicEmbed.stubs(:open).returns file TopicEmbed.stubs(:open).returns file
response = TopicEmbed.find_remote(url) response = TopicEmbed.find_remote(url)

View File

@ -185,8 +185,8 @@ describe Topic do
context 'private message title' do context 'private message title' do
before do before do
SiteSetting.stubs(:min_topic_title_length).returns(15) SiteSetting.min_topic_title_length = 15
SiteSetting.stubs(:min_private_message_title_length).returns(3) SiteSetting.min_private_message_title_length = 3
end end
it 'allows shorter titles' do it 'allows shorter titles' do
@ -327,7 +327,7 @@ describe Topic do
context 'category validation' do context 'category validation' do
context 'allow_uncategorized_topics is false' do context 'allow_uncategorized_topics is false' do
before do before do
SiteSetting.stubs(:allow_uncategorized_topics).returns(false) SiteSetting.allow_uncategorized_topics = false
end end
it "does not allow nil category" do it "does not allow nil category" do
@ -348,7 +348,7 @@ describe Topic do
context 'allow_uncategorized_topics is true' do context 'allow_uncategorized_topics is true' do
before do before do
SiteSetting.stubs(:allow_uncategorized_topics).returns(true) SiteSetting.allow_uncategorized_topics = true
end end
it "passes for topics with nil category" do it "passes for topics with nil category" do
@ -538,7 +538,7 @@ describe Topic do
context 'rate limits' do context 'rate limits' do
it "rate limits topic invitations" do it "rate limits topic invitations" do
SiteSetting.stubs(:max_topic_invitations_per_day).returns(2) SiteSetting.max_topic_invitations_per_day = 2
RateLimiter.stubs(:disabled?).returns(false) RateLimiter.stubs(:disabled?).returns(false)
RateLimiter.clear_all! RateLimiter.clear_all!
@ -1085,7 +1085,7 @@ describe Topic do
context 'when allow_uncategorized_topics is false' do context 'when allow_uncategorized_topics is false' do
before do before do
SiteSetting.stubs(:allow_uncategorized_topics).returns(false) SiteSetting.allow_uncategorized_topics = false
end end
let!(:topic) { Fabricate(:topic, category: Fabricate(:category)) } let!(:topic) { Fabricate(:topic, category: Fabricate(:category)) }
@ -1649,7 +1649,7 @@ describe Topic do
end end
describe ".count_exceeds_minimun?" do describe ".count_exceeds_minimun?" do
before { SiteSetting.stubs(:minimum_topics_similar).returns(20) } before { SiteSetting.minimum_topics_similar = 20 }
context "when Topic count is geater than minimum_topics_similar" do context "when Topic count is geater than minimum_topics_similar" do
it "should be true" do it "should be true" do
@ -1718,11 +1718,11 @@ describe Topic do
end end
it "doesn't validate the title again if it isn't changing" do it "doesn't validate the title again if it isn't changing" do
SiteSetting.stubs(:min_topic_title_length).returns(5) SiteSetting.min_topic_title_length = 5
topic = Fabricate(:topic, title: "Short") topic = Fabricate(:topic, title: "Short")
expect(topic).to be_valid expect(topic).to be_valid
SiteSetting.stubs(:min_topic_title_length).returns(15) SiteSetting.min_topic_title_length = 15
topic.last_posted_at = 1.minute.ago topic.last_posted_at = 1.minute.ago
expect(topic.save).to eq(true) expect(topic.save).to eq(true)
end end

View File

@ -15,22 +15,22 @@ describe TrustLevel3Requirements do
describe "requirements" do describe "requirements" do
it "time_period uses site setting" do it "time_period uses site setting" do
SiteSetting.stubs(:tl3_time_period).returns(80) SiteSetting.tl3_time_period = 80
expect(tl3_requirements.time_period).to eq(80) expect(tl3_requirements.time_period).to eq(80)
end end
it "min_days_visited uses site setting" do it "min_days_visited uses site setting" do
SiteSetting.stubs(:tl3_requires_days_visited).returns(66) SiteSetting.tl3_requires_days_visited = 66
expect(tl3_requirements.min_days_visited).to eq(66) expect(tl3_requirements.min_days_visited).to eq(66)
end end
it "min_topics_replied_to uses site setting" do it "min_topics_replied_to uses site setting" do
SiteSetting.stubs(:tl3_requires_topics_replied_to).returns(12) SiteSetting.tl3_requires_topics_replied_to = 12
expect(tl3_requirements.min_topics_replied_to).to eq(12) expect(tl3_requirements.min_topics_replied_to).to eq(12)
end end
it "min_topics_viewed depends on site setting and number of topics created" do it "min_topics_viewed depends on site setting and number of topics created" do
SiteSetting.stubs(:tl3_requires_topics_viewed).returns(75) SiteSetting.tl3_requires_topics_viewed = 75
described_class.stubs(:num_topics_in_time_period).returns(31) described_class.stubs(:num_topics_in_time_period).returns(31)
expect(tl3_requirements.min_topics_viewed).to eq(23) expect(tl3_requirements.min_topics_viewed).to eq(23)
end end
@ -43,7 +43,7 @@ describe TrustLevel3Requirements do
end end
it "min_posts_read depends on site setting and number of posts created" do it "min_posts_read depends on site setting and number of posts created" do
SiteSetting.stubs(:tl3_requires_posts_read).returns(66) SiteSetting.tl3_requires_posts_read = 66
described_class.stubs(:num_posts_in_time_period).returns(1234) described_class.stubs(:num_posts_in_time_period).returns(1234)
expect(tl3_requirements.min_posts_read).to eq(814) expect(tl3_requirements.min_posts_read).to eq(814)
end end
@ -56,27 +56,27 @@ describe TrustLevel3Requirements do
end end
it "min_topics_viewed_all_time depends on site setting" do it "min_topics_viewed_all_time depends on site setting" do
SiteSetting.stubs(:tl3_requires_topics_viewed_all_time).returns(75) SiteSetting.tl3_requires_topics_viewed_all_time = 75
expect(tl3_requirements.min_topics_viewed_all_time).to eq(75) expect(tl3_requirements.min_topics_viewed_all_time).to eq(75)
end end
it "min_posts_read_all_time depends on site setting" do it "min_posts_read_all_time depends on site setting" do
SiteSetting.stubs(:tl3_requires_posts_read_all_time).returns(1001) SiteSetting.tl3_requires_posts_read_all_time = 1001
expect(tl3_requirements.min_posts_read_all_time).to eq(1001) expect(tl3_requirements.min_posts_read_all_time).to eq(1001)
end end
it "max_flagged_posts depends on site setting" do it "max_flagged_posts depends on site setting" do
SiteSetting.stubs(:tl3_requires_max_flagged).returns(3) SiteSetting.tl3_requires_max_flagged = 3
expect(tl3_requirements.max_flagged_posts).to eq(3) expect(tl3_requirements.max_flagged_posts).to eq(3)
end end
it "min_likes_given depends on site setting" do it "min_likes_given depends on site setting" do
SiteSetting.stubs(:tl3_requires_likes_given).returns(30) SiteSetting.tl3_requires_likes_given = 30
expect(tl3_requirements.min_likes_given).to eq(30) expect(tl3_requirements.min_likes_given).to eq(30)
end end
it "min_likes_received depends on site setting" do it "min_likes_received depends on site setting" do
SiteSetting.stubs(:tl3_requires_likes_received).returns(20) SiteSetting.tl3_requires_likes_received = 20
expect(tl3_requirements.min_likes_received).to eq(20) expect(tl3_requirements.min_likes_received).to eq(20)
expect(tl3_requirements.min_likes_received_days).to eq(7) expect(tl3_requirements.min_likes_received_days).to eq(7)
expect(tl3_requirements.min_likes_received_users).to eq(5) expect(tl3_requirements.min_likes_received_users).to eq(5)

View File

@ -29,7 +29,7 @@ describe Upload do
context ".create_thumbnail!" do context ".create_thumbnail!" do
it "does not create a thumbnail when disabled" do it "does not create a thumbnail when disabled" do
SiteSetting.stubs(:create_thumbnails?).returns(false) SiteSetting.create_thumbnails = false
OptimizedImage.expects(:create_for).never OptimizedImage.expects(:create_for).never
upload.create_thumbnail!(100, 100) upload.create_thumbnail!(100, 100)
end end

View File

@ -143,7 +143,7 @@ describe UserProfile do
end end
context 'tl3_links_no_follow is false' do context 'tl3_links_no_follow is false' do
before { SiteSetting.stubs(:tl3_links_no_follow).returns(false) } before { SiteSetting.tl3_links_no_follow = false }
it 'includes the link without nofollow if the user is trust level 3 or higher' do it 'includes the link without nofollow if the user is trust level 3 or higher' do
user.trust_level = TrustLevel[3] user.trust_level = TrustLevel[3]
@ -169,7 +169,7 @@ describe UserProfile do
end end
context 'tl3_links_no_follow is true' do context 'tl3_links_no_follow is true' do
before { SiteSetting.stubs(:tl3_links_no_follow).returns(true) } before { SiteSetting.tl3_links_no_follow = true }
it 'includes the link with nofollow if the user is trust level 3 or higher' do it 'includes the link with nofollow if the user is trust level 3 or higher' do
user.trust_level = TrustLevel[3] user.trust_level = TrustLevel[3]

View File

@ -66,7 +66,7 @@ describe User do
let(:admin) { Fabricate(:admin) } let(:admin) { Fabricate(:admin) }
it "enqueues a 'signup after approval' email if must_approve_users is true" do it "enqueues a 'signup after approval' email if must_approve_users is true" do
SiteSetting.stubs(:must_approve_users).returns(true) SiteSetting.must_approve_users = true
Jobs.expects(:enqueue).with( Jobs.expects(:enqueue).with(
:critical_user_email, has_entries(type: :signup_after_approval) :critical_user_email, has_entries(type: :signup_after_approval)
) )
@ -74,7 +74,7 @@ describe User do
end end
it "doesn't enqueue a 'signup after approval' email if must_approve_users is false" do it "doesn't enqueue a 'signup after approval' email if must_approve_users is false" do
SiteSetting.stubs(:must_approve_users).returns(false) SiteSetting.must_approve_users = false
Jobs.expects(:enqueue).never Jobs.expects(:enqueue).never
user.approve(admin) user.approve(admin)
end end
@ -648,8 +648,8 @@ describe User do
let!(:third_visit_date) { 5.hours.from_now } let!(:third_visit_date) { 5.hours.from_now }
before do before do
SiteSetting.stubs(:active_user_rate_limit_secs).returns(0) SiteSetting.active_user_rate_limit_secs = 0
SiteSetting.stubs(:previous_visit_timeout_hours).returns(1) SiteSetting.previous_visit_timeout_hours = 1
end end
it "should act correctly" do it "should act correctly" do
@ -969,7 +969,7 @@ describe User do
before do before do
# To make testing easier, say 1 reply is too much # To make testing easier, say 1 reply is too much
SiteSetting.stubs(:newuser_max_replies_per_topic).returns(1) SiteSetting.newuser_max_replies_per_topic = 1
UserActionCreator.enable UserActionCreator.enable
end end

View File

@ -11,12 +11,12 @@ describe BasicPostSerializer do
let(:json) { serializer.as_json } let(:json) { serializer.as_json }
it "returns the name it when `enable_names` is true" do it "returns the name it when `enable_names` is true" do
SiteSetting.stubs(:enable_names?).returns(true) SiteSetting.enable_names = true
expect(json[:name]).to be_present expect(json[:name]).to be_present
end end
it "doesn't return the name it when `enable_names` is false" do it "doesn't return the name it when `enable_names` is false" do
SiteSetting.stubs(:enable_names?).returns(false) SiteSetting.enable_names = false
expect(json[:name]).to be_blank expect(json[:name]).to be_blank
end end

View File

@ -70,12 +70,12 @@ describe PostSerializer do
let(:json) { serializer.as_json } let(:json) { serializer.as_json }
it "returns the display_username it when `enable_names` is on" do it "returns the display_username it when `enable_names` is on" do
SiteSetting.stubs(:enable_names).returns(true) SiteSetting.enable_names = true
expect(json[:display_username]).to be_present expect(json[:display_username]).to be_present
end end
it "doesn't return the display_username it when `enable_names` is off" do it "doesn't return the display_username it when `enable_names` is off" do
SiteSetting.stubs(:enable_names).returns(false) SiteSetting.enable_names = false
expect(json[:display_username]).to be_blank expect(json[:display_username]).to be_blank
end end
end end

View File

@ -60,7 +60,7 @@ describe UserSerializer do
context "with `enable_names` false" do context "with `enable_names` false" do
before do before do
SiteSetting.stubs(:enable_names?).returns(false) SiteSetting.enable_names = false
end end
it "has a name" do it "has a name" do
@ -192,7 +192,7 @@ describe UserSerializer do
end end
it "serializes the fields listed in public_user_custom_fields site setting" do it "serializes the fields listed in public_user_custom_fields site setting" do
SiteSetting.stubs(:public_user_custom_fields).returns('public_field') SiteSetting.public_user_custom_fields = 'public_field'
expect(json[:custom_fields]['public_field']).to eq(user.custom_fields['public_field']) expect(json[:custom_fields]['public_field']).to eq(user.custom_fields['public_field'])
expect(json[:custom_fields]['secret_field']).to eq(nil) expect(json[:custom_fields]['secret_field']).to eq(nil)
end end

View File

@ -156,7 +156,7 @@ describe SpamRule::AutoBlock do
end end
it "doesn't send a pm to moderators if notify_mods_when_user_blocked is false" do it "doesn't send a pm to moderators if notify_mods_when_user_blocked is false" do
SiteSetting.stubs(:notify_mods_when_user_blocked).returns(false) SiteSetting.notify_mods_when_user_blocked = false
GroupMessage.expects(:create).never GroupMessage.expects(:create).never
subject.block_user subject.block_user
end end
@ -236,7 +236,7 @@ describe SpamRule::AutoBlock do
end end
it 'returns false if num_users_to_block_new_user is 0' do it 'returns false if num_users_to_block_new_user is 0' do
SiteSetting.stubs(:num_users_to_block_new_user).returns(0) SiteSetting.num_users_to_block_new_user = 0
subject.stubs(:num_spam_flags_against_user).returns(100) subject.stubs(:num_spam_flags_against_user).returns(100)
subject.stubs(:num_users_who_flagged_spam_against_user).returns(100) subject.stubs(:num_users_who_flagged_spam_against_user).returns(100)
expect(subject.block?).to be_falsey expect(subject.block?).to be_falsey

View File

@ -10,14 +10,14 @@ describe SpamRule::FlagSockpuppets do
subject(:perform) { rule.perform } subject(:perform) { rule.perform }
it 'does nothing if flag_sockpuppets is disabled' do it 'does nothing if flag_sockpuppets is disabled' do
SiteSetting.stubs(:flag_sockpuppets).returns(false) SiteSetting.flag_sockpuppets = false
rule.expects(:reply_is_from_sockpuppet?).never rule.expects(:reply_is_from_sockpuppet?).never
rule.expects(:flag_sockpuppet_users).never rule.expects(:flag_sockpuppet_users).never
expect(perform).to eq(false) expect(perform).to eq(false)
end end
context 'flag_sockpuppets is enabled' do context 'flag_sockpuppets is enabled' do
before { SiteSetting.stubs(:flag_sockpuppets).returns(true) } before { SiteSetting.flag_sockpuppets = true }
it 'flags posts when it should' do it 'flags posts when it should' do
rule.expects(:reply_is_from_sockpuppet?).returns(:true) rule.expects(:reply_is_from_sockpuppet?).returns(:true)

View File

@ -39,7 +39,7 @@ describe PostActionNotifier do
context "edit notifications are disabled" do context "edit notifications are disabled" do
before { SiteSetting.stubs(:disable_edit_notifications).returns(true) } before { SiteSetting.disable_edit_notifications = true }
it 'notifies a user of the revision made by another user' do it 'notifies a user of the revision made by another user' do

View File

@ -1,5 +1,5 @@
require 'spec_helper' require 'rails_helper'
require 'discourse_imgur/imgur' require_relative 'discourse_imgur/imgur'
# /!\ WARNING /!\ # /!\ WARNING /!\
# This plugin has been extracted from the Discourse source code and has not been tested. # This plugin has been extracted from the Discourse source code and has not been tested.
@ -14,9 +14,9 @@ describe Imgur do
let(:image_info) { FastImage.new(file) } let(:image_info) { FastImage.new(file) }
let(:params) { [SiteSetting.imgur_endpoint, { image: Base64.encode64(file.read) }, { 'Authorization' => "ClientID #{SiteSetting.imgur_client_id}" }] } let(:params) { [SiteSetting.imgur_endpoint, { image: Base64.encode64(file.read) }, { 'Authorization' => "ClientID #{SiteSetting.imgur_client_id}" }] }
before(:each) do before do
SiteSetting.stubs(:imgur_endpoint).returns("imgur_endpoint") SiteSetting.imgur_endpoint = "imgur_endpoint"
SiteSetting.stubs(:imgur_client_id).returns("imgur_client_id") SiteSetting.imgur_client_id = "imgur_client_id"
end end
it 'returns the url of the Imgur upload if successful' do it 'returns the url of the Imgur upload if successful' do