From 0e5d490b059724559b58f034e2f0de6dd5ef0ebb Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Sat, 28 Jan 2017 10:55:49 +0800 Subject: [PATCH] No need for special helper to reset SiteSetting state. * SiteSetting in tests uses a local provider that resets it. --- spec/integration/groups_spec.rb | 4 ++-- spec/integration/spam_rules_spec.rb | 13 +++++++------ spec/models/topic_spec.rb | 8 ++++---- spec/support/helpers.rb | 14 -------------- 4 files changed, 13 insertions(+), 26 deletions(-) diff --git a/spec/integration/groups_spec.rb b/spec/integration/groups_spec.rb index bc721bf2e3d..788d72c1b1f 100644 --- a/spec/integration/groups_spec.rb +++ b/spec/integration/groups_spec.rb @@ -15,9 +15,9 @@ describe "Groups" do end context 'when group directory is disabled' do - site_setting(:enable_group_directory, false) - it 'should deny access' do + SiteSetting.enable_group_directory = false + get "/groups.json" expect(response).to be_forbidden end diff --git a/spec/integration/spam_rules_spec.rb b/spec/integration/spam_rules_spec.rb index c1c22b4ff7d..bb28573e8f5 100644 --- a/spec/integration/spam_rules_spec.rb +++ b/spec/integration/spam_rules_spec.rb @@ -5,15 +5,17 @@ require 'rails_helper' describe SpamRulesEnforcer do describe 'auto-blocking users based on flagging' do - site_setting(:flags_required_to_hide_post, 0) - site_setting(:num_spam_flags_to_block_new_user, 2) - site_setting(:num_users_to_block_new_user, 2) - let!(:admin) { Fabricate(:admin) } # needed to send a system message let!(:moderator) { Fabricate(:moderator) } let(:user1) { Fabricate(:user) } let(:user2) { Fabricate(:user) } + before do + SiteSetting.flags_required_to_hide_post = 0 + SiteSetting.num_spam_flags_to_block_new_user = 2 + SiteSetting.num_users_to_block_new_user = 2 + end + context 'spammer is a new user' do let(:spammer) { Fabricate(:user, trust_level: TrustLevel[0]) } @@ -86,9 +88,8 @@ describe SpamRulesEnforcer do end context 'flags_required_to_hide_post takes effect too' do - site_setting(:flags_required_to_hide_post, 2) - it 'should block the spammer' do + SiteSetting.flags_required_to_hide_post = 2 PostAction.act(user2, spam_post, PostActionType.types[:spam]) expect(spammer.reload).to be_blocked expect(Guardian.new(spammer).can_create_topic?(nil)).to be false diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index b0db2dc92cd..46b0126e0db 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -15,9 +15,9 @@ describe Topic do describe 'censored words' do describe 'when title contains censored words' do - site_setting(:censored_words, 'pineapple|pen') - it 'should not be valid' do + SiteSetting.censored_words = 'pineapple|pen' + topic.title = 'pen PinEapple apple pen ' expect(topic).to_not be_valid @@ -29,9 +29,9 @@ describe Topic do end describe 'when title matches censored pattern' do - site_setting(:censored_pattern, 'orange.*') - it 'should not be valid' do + SiteSetting.censored_pattern = 'orange.*' + topic.title = 'I have orangEjuice orange monkey orange stuff' expect(topic).to_not be_valid diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb index 5b7c124463e..9238cf9771d 100644 --- a/spec/support/helpers.rb +++ b/spec/support/helpers.rb @@ -1,20 +1,6 @@ module Helpers extend ActiveSupport::Concern - class_methods do - def site_setting(setting_name, value) - original_value = SiteSetting.public_send(setting_name.to_sym) - - self.before do - SiteSetting.public_send("#{setting_name}=", value) - end - - self.after do - SiteSetting.public_send("#{setting_name}=", original_value) - end - end - end - def self.next_seq @next_seq = (@next_seq || 0) + 1 end