mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Add RSpec 4 compatibility (#17652)
* Remove outdated option
04078317ba
* Use the non-globally exposed RSpec syntax
https://github.com/rspec/rspec-core/pull/2803
* Use the non-globally exposed RSpec syntax, cont
https://github.com/rspec/rspec-core/pull/2803
* Comply to strict predicate matchers
See:
- https://github.com/rspec/rspec-expectations/pull/1195
- https://github.com/rspec/rspec-expectations/pull/1196
- https://github.com/rspec/rspec-expectations/pull/1277
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe AllowedIpAddressValidator do
|
||||
RSpec.describe AllowedIpAddressValidator do
|
||||
|
||||
let(:record) { Fabricate.build(:user, trust_level: TrustLevel[0], ip_address: '99.232.23.123') }
|
||||
let(:validator) { described_class.new(attributes: :ip_address) }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe CensoredWordsValidator do
|
||||
RSpec.describe CensoredWordsValidator do
|
||||
let(:value) { 'some new bad text' }
|
||||
let(:record) { Fabricate(:post, raw: 'this is a test') }
|
||||
let(:attribute) { :raw }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe CssColorValidator do
|
||||
RSpec.describe CssColorValidator do
|
||||
subject { described_class.new }
|
||||
|
||||
it "validates hex colors" do
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe EmailAddressValidator do
|
||||
RSpec.describe EmailAddressValidator do
|
||||
it 'should match valid emails' do
|
||||
['test@discourse.org', 'good_user@discourse.org', 'incoming+%{reply_key}@discourse.org'].each do |email|
|
||||
expect(EmailAddressValidator.valid_value?(email)).to eq(true)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe EmailSettingValidator do
|
||||
RSpec.describe EmailSettingValidator do
|
||||
describe '#valid_value?' do
|
||||
subject(:validator) { described_class.new }
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe EmailValidator do
|
||||
RSpec.describe EmailValidator do
|
||||
def blocks?(email)
|
||||
user = Fabricate.build(:user, email: email)
|
||||
validator = EmailValidator.new(attributes: :email)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe ExternalSystemAvatarsValidator do
|
||||
RSpec.describe ExternalSystemAvatarsValidator do
|
||||
subject { described_class.new }
|
||||
|
||||
it "disallows disabling external system avatars when Unicode usernames are enabled" do
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe GroupSettingValidator do
|
||||
RSpec.describe GroupSettingValidator do
|
||||
describe '#valid_value?' do
|
||||
subject(:validator) { described_class.new }
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe HostListSettingValidator do
|
||||
RSpec.describe HostListSettingValidator do
|
||||
subject(:validator) { described_class.new() }
|
||||
|
||||
describe '#valid_value?' do
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe IntegerSettingValidator do
|
||||
RSpec.describe IntegerSettingValidator do
|
||||
describe '#valid_value?' do
|
||||
|
||||
shared_examples "for all IntegerSettingValidator opts" do
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe IpAddressFormatValidator do
|
||||
RSpec.describe IpAddressFormatValidator do
|
||||
|
||||
let(:record) { Fabricate.build(:screened_ip_address, ip_address: '99.232.23.123') }
|
||||
let(:validator) { described_class.new(attributes: :ip_address) }
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# encoding: UTF-8
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe MaxEmojisValidator do
|
||||
RSpec.describe MaxEmojisValidator do
|
||||
|
||||
# simulate Rails behavior (singleton)
|
||||
def validate
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe MaxUsernameLengthValidator do
|
||||
RSpec.describe MaxUsernameLengthValidator do
|
||||
it "checks for minimum range" do
|
||||
User.update_all('username = username || username')
|
||||
SiteSetting.min_username_length = 9
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe MinUsernameLengthValidator do
|
||||
RSpec.describe MinUsernameLengthValidator do
|
||||
it "checks for maximum range" do
|
||||
SiteSetting.max_username_length = 10
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe PasswordValidator do
|
||||
RSpec.describe PasswordValidator do
|
||||
|
||||
def password_error_message(key)
|
||||
I18n.t("activerecord.errors.models.user.attributes.password.#{key.to_s}")
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe PostValidator do
|
||||
RSpec.describe PostValidator do
|
||||
fab!(:topic) { Fabricate(:topic) }
|
||||
let(:post) { build(:post, topic: topic) }
|
||||
let(:validator) { PostValidator.new({}) }
|
||||
|
||||
@@ -10,7 +10,7 @@ module QualityTitleValidatorSpec
|
||||
end
|
||||
end
|
||||
|
||||
describe "A record validated with QualityTitleValidator" do
|
||||
RSpec.describe "A record validated with QualityTitleValidator" do
|
||||
let(:valid_title) { "hello this is my cool topic! welcome: all;" }
|
||||
let(:short_title) { valid_title.slice(0, SiteSetting.min_topic_title_length - 1) }
|
||||
let(:long_title) { valid_title.center(SiteSetting.max_topic_title_length + 1, 'x') }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe RegexSettingValidator do
|
||||
RSpec.describe RegexSettingValidator do
|
||||
describe '#valid_value?' do
|
||||
subject(:validator) { described_class.new }
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe RegexpListValidator do
|
||||
RSpec.describe RegexpListValidator do
|
||||
subject { described_class.new }
|
||||
|
||||
it "allows lists of valid regular expressions" do
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe ReplyByEmailAddressValidator do
|
||||
RSpec.describe ReplyByEmailAddressValidator do
|
||||
|
||||
describe '#valid_value?' do
|
||||
subject(:validator) { described_class.new }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe ReplyByEmailEnabledValidator do
|
||||
RSpec.describe ReplyByEmailEnabledValidator do
|
||||
|
||||
describe '#valid_value?' do
|
||||
subject(:validator) { described_class.new }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe SearchTokenizeChineseValidator do
|
||||
RSpec.describe SearchTokenizeChineseValidator do
|
||||
it 'does not allow search_tokenize_chinese to be enabled when search_tokenize_japanese is enabled' do
|
||||
SiteSetting.search_tokenize_japanese = true
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe SearchTokenizeJapaneseValidator do
|
||||
RSpec.describe SearchTokenizeJapaneseValidator do
|
||||
it 'does not allow search_tokenize_japanese to be enabled when search_tokenize_chinese is enabled' do
|
||||
SiteSetting.search_tokenize_chinese = true
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe SelectableAvatarsModeValidator do
|
||||
RSpec.describe SelectableAvatarsModeValidator do
|
||||
describe '#valid_value?' do
|
||||
subject(:validator) { described_class.new }
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe StringSettingValidator do
|
||||
RSpec.describe StringSettingValidator do
|
||||
|
||||
describe '#valid_value?' do
|
||||
shared_examples "for all StringSettingValidator opts" do
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe TimezoneValidator do
|
||||
RSpec.describe TimezoneValidator do
|
||||
describe "#valid?" do
|
||||
context "when timezone is ok" do
|
||||
it "returns true" do
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# encoding: UTF-8
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe TopicTitleLengthValidator do
|
||||
RSpec.describe TopicTitleLengthValidator do
|
||||
|
||||
# simulate Rails behavior (singleton)
|
||||
def validate
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe UnicodeUsernameAllowlistValidator do
|
||||
RSpec.describe UnicodeUsernameAllowlistValidator do
|
||||
subject { described_class.new }
|
||||
|
||||
it "allows an empty allowlist" do
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe UnicodeUsernameValidator do
|
||||
RSpec.describe UnicodeUsernameValidator do
|
||||
subject { described_class.new }
|
||||
|
||||
it "disallows Unicode usernames when external system avatars are disabled" do
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe UploadValidator do
|
||||
RSpec.describe UploadValidator do
|
||||
subject(:validator) { described_class.new }
|
||||
|
||||
describe 'validate' do
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe UserFullNameValidator do
|
||||
RSpec.describe UserFullNameValidator do
|
||||
let(:validator) { described_class.new(attributes: :name) }
|
||||
subject(:validate) { validator.validate_each(record, :name, @name) }
|
||||
let(:record) { Fabricate.build(:user, name: @name) }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe UsernameSettingValidator do
|
||||
RSpec.describe UsernameSettingValidator do
|
||||
describe '#valid_value?' do
|
||||
subject(:validator) { described_class.new }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user