mirror of
https://github.com/discourse/discourse.git
synced 2025-06-02 04:08:41 +08:00
few components with rspec3 syntax
This commit is contained in:
@ -10,7 +10,7 @@ describe AllowedIpAddressValidator do
|
||||
it 'should add an error' do
|
||||
ScreenedIpAddress.stubs(:should_block?).returns(true)
|
||||
validate
|
||||
record.errors[:ip_address].should be_present
|
||||
expect(record.errors[:ip_address]).to be_present
|
||||
end
|
||||
end
|
||||
|
||||
@ -18,7 +18,7 @@ describe AllowedIpAddressValidator do
|
||||
it 'should add an error' do
|
||||
SpamHandler.stubs(:should_prevent_registration_from_ip?).returns(true)
|
||||
validate
|
||||
record.errors[:ip_address].should be_present
|
||||
expect(record.errors[:ip_address]).to be_present
|
||||
end
|
||||
end
|
||||
|
||||
@ -26,7 +26,7 @@ describe AllowedIpAddressValidator do
|
||||
it "shouldn't add an error" do
|
||||
ScreenedIpAddress.stubs(:should_block?).returns(false)
|
||||
validate
|
||||
record.errors[:ip_address].should_not be_present
|
||||
expect(record.errors[:ip_address]).not_to be_present
|
||||
end
|
||||
end
|
||||
|
||||
@ -35,7 +35,7 @@ describe AllowedIpAddressValidator do
|
||||
ScreenedIpAddress.expects(:should_block?).never
|
||||
record.ip_address = nil
|
||||
validate
|
||||
record.errors[:ip_address].should_not be_present
|
||||
expect(record.errors[:ip_address]).not_to be_present
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -5,16 +5,16 @@ describe EmailSettingValidator do
|
||||
subject(:validator) { described_class.new }
|
||||
|
||||
it "returns true for blank values" do
|
||||
validator.valid_value?('').should == true
|
||||
validator.valid_value?(nil).should == true
|
||||
expect(validator.valid_value?('')).to eq(true)
|
||||
expect(validator.valid_value?(nil)).to eq(true)
|
||||
end
|
||||
|
||||
it "returns true if value is a valid email address" do
|
||||
validator.valid_value?('vader@example.com').should == true
|
||||
expect(validator.valid_value?('vader@example.com')).to eq(true)
|
||||
end
|
||||
|
||||
it "returns false if value is not a valid email address" do
|
||||
validator.valid_value?('my house').should == false
|
||||
expect(validator.valid_value?('my house')).to eq(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -10,13 +10,13 @@ describe EmailValidator do
|
||||
it "doesn't add an error when email doesn't match a blocked email" do
|
||||
ScreenedEmail.stubs(:should_block?).with(record.email).returns(false)
|
||||
validate
|
||||
record.errors[:email].should_not be_present
|
||||
expect(record.errors[:email]).not_to be_present
|
||||
end
|
||||
|
||||
it "adds an error when email matches a blocked email" do
|
||||
ScreenedEmail.stubs(:should_block?).with(record.email).returns(true)
|
||||
validate
|
||||
record.errors[:email].should be_present
|
||||
expect(record.errors[:email]).to be_present
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -5,12 +5,12 @@ describe IntegerSettingValidator do
|
||||
|
||||
shared_examples "for all IntegerSettingValidator opts" do
|
||||
it "returns false for blank values" do
|
||||
validator.valid_value?('').should == false
|
||||
validator.valid_value?(nil).should == false
|
||||
expect(validator.valid_value?('')).to eq(false)
|
||||
expect(validator.valid_value?(nil)).to eq(false)
|
||||
end
|
||||
|
||||
it "returns false if value is not a valid integer" do
|
||||
validator.valid_value?('two').should == false
|
||||
expect(validator.valid_value?('two')).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
@ -20,10 +20,10 @@ describe IntegerSettingValidator do
|
||||
include_examples "for all IntegerSettingValidator opts"
|
||||
|
||||
it "returns true if value is a valid integer" do
|
||||
validator.valid_value?(1).should == true
|
||||
validator.valid_value?(-1).should == true
|
||||
validator.valid_value?('1').should == true
|
||||
validator.valid_value?('-1').should == true
|
||||
expect(validator.valid_value?(1)).to eq(true)
|
||||
expect(validator.valid_value?(-1)).to eq(true)
|
||||
expect(validator.valid_value?('1')).to eq(true)
|
||||
expect(validator.valid_value?('-1')).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
@ -33,18 +33,18 @@ describe IntegerSettingValidator do
|
||||
include_examples "for all IntegerSettingValidator opts"
|
||||
|
||||
it "returns true if value is equal to min" do
|
||||
validator.valid_value?(2).should == true
|
||||
validator.valid_value?('2').should == true
|
||||
expect(validator.valid_value?(2)).to eq(true)
|
||||
expect(validator.valid_value?('2')).to eq(true)
|
||||
end
|
||||
|
||||
it "returns true if value is greater than min" do
|
||||
validator.valid_value?(3).should == true
|
||||
validator.valid_value?('3').should == true
|
||||
expect(validator.valid_value?(3)).to eq(true)
|
||||
expect(validator.valid_value?('3')).to eq(true)
|
||||
end
|
||||
|
||||
it "returns false if value is less than min" do
|
||||
validator.valid_value?(1).should == false
|
||||
validator.valid_value?('1').should == false
|
||||
expect(validator.valid_value?(1)).to eq(false)
|
||||
expect(validator.valid_value?('1')).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
@ -54,18 +54,18 @@ describe IntegerSettingValidator do
|
||||
include_examples "for all IntegerSettingValidator opts"
|
||||
|
||||
it "returns true if value is equal to max" do
|
||||
validator.valid_value?(3).should == true
|
||||
validator.valid_value?('3').should == true
|
||||
expect(validator.valid_value?(3)).to eq(true)
|
||||
expect(validator.valid_value?('3')).to eq(true)
|
||||
end
|
||||
|
||||
it "returns true if value is less than max" do
|
||||
validator.valid_value?(2).should == true
|
||||
validator.valid_value?('2').should == true
|
||||
expect(validator.valid_value?(2)).to eq(true)
|
||||
expect(validator.valid_value?('2')).to eq(true)
|
||||
end
|
||||
|
||||
it "returns false if value is greater than min" do
|
||||
validator.valid_value?(4).should == false
|
||||
validator.valid_value?('4').should == false
|
||||
expect(validator.valid_value?(4)).to eq(false)
|
||||
expect(validator.valid_value?('4')).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
@ -75,14 +75,14 @@ describe IntegerSettingValidator do
|
||||
include_examples "for all IntegerSettingValidator opts"
|
||||
|
||||
it "returns true if value is in range" do
|
||||
validator.valid_value?(-1).should == true
|
||||
validator.valid_value?(0).should == true
|
||||
validator.valid_value?(3).should == true
|
||||
expect(validator.valid_value?(-1)).to eq(true)
|
||||
expect(validator.valid_value?(0)).to eq(true)
|
||||
expect(validator.valid_value?(3)).to eq(true)
|
||||
end
|
||||
|
||||
it "returns false if value is out of range" do
|
||||
validator.valid_value?(4).should == false
|
||||
validator.valid_value?(-2).should == false
|
||||
expect(validator.valid_value?(4)).to eq(false)
|
||||
expect(validator.valid_value?(-2)).to eq(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -10,19 +10,19 @@ describe IpAddressFormatValidator do
|
||||
it "should not add an error for #{arg}" do
|
||||
record.ip_address = arg
|
||||
validate
|
||||
record.errors[:ip_address].should_not be_present
|
||||
expect(record.errors[:ip_address]).not_to be_present
|
||||
end
|
||||
end
|
||||
|
||||
it 'should add an error for nil IP address' do
|
||||
record.ip_address = nil
|
||||
validate
|
||||
record.errors[:ip_address].should be_present
|
||||
expect(record.errors[:ip_address]).to be_present
|
||||
end
|
||||
|
||||
it 'should add an error for invalid IP address' do
|
||||
record.ip_address = '99.99.99'
|
||||
validate
|
||||
record.errors[:ip_address].should be_present
|
||||
expect(record.errors[:ip_address]).to be_present
|
||||
end
|
||||
end
|
||||
|
@ -20,25 +20,25 @@ describe PasswordValidator do
|
||||
it "doesn't add an error when password is good" do
|
||||
@password = "weron235alsfn234"
|
||||
validate
|
||||
record.errors[:password].should_not be_present
|
||||
expect(record.errors[:password]).not_to be_present
|
||||
end
|
||||
|
||||
it "adds an error when password is too short" do
|
||||
@password = "p"
|
||||
validate
|
||||
record.errors[:password].should be_present
|
||||
expect(record.errors[:password]).to be_present
|
||||
end
|
||||
|
||||
it "adds an error when password is blank" do
|
||||
@password = ''
|
||||
validate
|
||||
record.errors[:password].should be_present
|
||||
expect(record.errors[:password]).to be_present
|
||||
end
|
||||
|
||||
it "adds an error when password is nil" do
|
||||
@password = nil
|
||||
validate
|
||||
record.errors[:password].should be_present
|
||||
expect(record.errors[:password]).to be_present
|
||||
end
|
||||
end
|
||||
|
||||
@ -48,7 +48,7 @@ describe PasswordValidator do
|
||||
it "adds an error when password length is 11" do
|
||||
@password = "gt38sdt92bv"
|
||||
validate
|
||||
record.errors[:password].should be_present
|
||||
expect(record.errors[:password]).to be_present
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -62,14 +62,14 @@ describe PasswordValidator do
|
||||
SiteSetting.stubs(:block_common_passwords).returns(true)
|
||||
@password = "password"
|
||||
validate
|
||||
record.errors[:password].should be_present
|
||||
expect(record.errors[:password]).to be_present
|
||||
end
|
||||
|
||||
it "doesn't add an error when block_common_passwords is disabled" do
|
||||
SiteSetting.stubs(:block_common_passwords).returns(false)
|
||||
@password = "password"
|
||||
validate
|
||||
record.errors[:password].should_not be_present
|
||||
expect(record.errors[:password]).not_to be_present
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -80,7 +80,7 @@ describe PasswordValidator do
|
||||
it "doesn't add an error if password is not required" do
|
||||
@password = nil
|
||||
validate
|
||||
record.errors[:password].should_not be_present
|
||||
expect(record.errors[:password]).not_to be_present
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -64,7 +64,7 @@ describe Validators::PostValidator do
|
||||
|
||||
it "should not add an error" do
|
||||
validator.unique_post_validator(post)
|
||||
post.errors.count.should == 0
|
||||
expect(post.errors.count).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
@ -81,7 +81,7 @@ describe Validators::PostValidator do
|
||||
it "should not add an error if post.skip_unique_check is true" do
|
||||
post.skip_unique_check = true
|
||||
validator.unique_post_validator(post)
|
||||
post.errors.count.should == 0
|
||||
expect(post.errors.count).to eq(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -25,45 +25,45 @@ describe "A record validated with QualityTitleValidator" do
|
||||
|
||||
it "allows a regular title with a few ascii characters" do
|
||||
topic.title = valid_title
|
||||
topic.should be_valid
|
||||
expect(topic).to be_valid
|
||||
end
|
||||
|
||||
it "allows non ascii" do
|
||||
topic.title = "Iñtërnâtiônàlizætiøn"
|
||||
topic.should be_valid
|
||||
expect(topic).to be_valid
|
||||
end
|
||||
|
||||
it 'allows Chinese characters' do
|
||||
topic.title = '现在发现使用中文标题没法发帖子了'
|
||||
topic.should be_valid
|
||||
expect(topic).to be_valid
|
||||
end
|
||||
|
||||
it "allows anything in a private message" do
|
||||
topic.stubs(:private_message? => true)
|
||||
[short_title, long_title, xxxxx_title].each do |bad_title|
|
||||
topic.title = bad_title
|
||||
topic.should be_valid
|
||||
expect(topic).to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
it "strips a title when identifying length" do
|
||||
topic.title = short_title.center(SiteSetting.min_topic_title_length + 1, ' ')
|
||||
topic.should_not be_valid
|
||||
expect(topic).not_to be_valid
|
||||
end
|
||||
|
||||
it "doesn't allow a long title" do
|
||||
topic.title = long_title
|
||||
topic.should_not be_valid
|
||||
expect(topic).not_to be_valid
|
||||
end
|
||||
|
||||
it "doesn't allow a short title" do
|
||||
topic.title = short_title
|
||||
topic.should_not be_valid
|
||||
expect(topic).not_to be_valid
|
||||
end
|
||||
|
||||
it "doesn't allow a title of one repeated character" do
|
||||
topic.title = xxxxx_title
|
||||
topic.should_not be_valid
|
||||
expect(topic).not_to be_valid
|
||||
end
|
||||
|
||||
# describe "with a name" do
|
||||
|
@ -5,8 +5,8 @@ describe StringSettingValidator do
|
||||
describe '#valid_value?' do
|
||||
shared_examples "for all StringSettingValidator opts" do
|
||||
it "returns true for blank values" do
|
||||
validator.valid_value?('').should == true
|
||||
validator.valid_value?(nil).should == true
|
||||
expect(validator.valid_value?('')).to eq(true)
|
||||
expect(validator.valid_value?(nil)).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
@ -16,21 +16,21 @@ describe StringSettingValidator do
|
||||
include_examples "for all StringSettingValidator opts"
|
||||
|
||||
it "returns true if value matches the regex" do
|
||||
validator.valid_value?('The bacon is delicious').should == true
|
||||
expect(validator.valid_value?('The bacon is delicious')).to eq(true)
|
||||
end
|
||||
|
||||
it "returns false if the value doesn't match the regex" do
|
||||
validator.valid_value?('The vegetables are delicious').should == false
|
||||
expect(validator.valid_value?('The vegetables are delicious')).to eq(false)
|
||||
end
|
||||
|
||||
it "test some other regexes" do
|
||||
v = described_class.new(regex: '^(chocolate|banana)$')
|
||||
v.valid_value?('chocolate').should == true
|
||||
v.valid_value?('chocolates').should == false
|
||||
expect(v.valid_value?('chocolate')).to eq(true)
|
||||
expect(v.valid_value?('chocolates')).to eq(false)
|
||||
|
||||
v = described_class.new(regex: '^[\w]+$')
|
||||
v.valid_value?('the_file').should == true
|
||||
v.valid_value?('the_file.bat').should == false
|
||||
expect(v.valid_value?('the_file')).to eq(true)
|
||||
expect(v.valid_value?('the_file.bat')).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
@ -40,12 +40,12 @@ describe StringSettingValidator do
|
||||
include_examples "for all StringSettingValidator opts"
|
||||
|
||||
it "returns true if length is ok" do
|
||||
validator.valid_value?('ok').should == true
|
||||
validator.valid_value?('yep long enough').should == true
|
||||
expect(validator.valid_value?('ok')).to eq(true)
|
||||
expect(validator.valid_value?('yep long enough')).to eq(true)
|
||||
end
|
||||
|
||||
it "returns false if too short" do
|
||||
validator.valid_value?('x').should == false
|
||||
expect(validator.valid_value?('x')).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
@ -55,43 +55,43 @@ describe StringSettingValidator do
|
||||
include_examples "for all StringSettingValidator opts"
|
||||
|
||||
it "returns true if length is ok" do
|
||||
validator.valid_value?('Z').should == true
|
||||
validator.valid_value?('abcde').should == true
|
||||
expect(validator.valid_value?('Z')).to eq(true)
|
||||
expect(validator.valid_value?('abcde')).to eq(true)
|
||||
end
|
||||
|
||||
it "returns false if too long" do
|
||||
validator.valid_value?('banana').should == false
|
||||
expect(validator.valid_value?('banana')).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
context 'combinations of options' do
|
||||
it "min and regex" do
|
||||
v = described_class.new(regex: '^[\w]+$', min: 3)
|
||||
v.valid_value?('chocolate').should == true
|
||||
v.valid_value?('hi').should == false
|
||||
v.valid_value?('game.exe').should == false
|
||||
expect(v.valid_value?('chocolate')).to eq(true)
|
||||
expect(v.valid_value?('hi')).to eq(false)
|
||||
expect(v.valid_value?('game.exe')).to eq(false)
|
||||
end
|
||||
|
||||
it "max and regex" do
|
||||
v = described_class.new(regex: '^[\w]+$', max: 5)
|
||||
v.valid_value?('chocolate').should == false
|
||||
v.valid_value?('a_b_c').should == true
|
||||
v.valid_value?('a b c').should == false
|
||||
expect(v.valid_value?('chocolate')).to eq(false)
|
||||
expect(v.valid_value?('a_b_c')).to eq(true)
|
||||
expect(v.valid_value?('a b c')).to eq(false)
|
||||
end
|
||||
|
||||
it "min and max" do
|
||||
v = described_class.new(min: 3, max: 5)
|
||||
v.valid_value?('chocolate').should == false
|
||||
v.valid_value?('a').should == false
|
||||
v.valid_value?('a b c').should == true
|
||||
v.valid_value?('a b').should == true
|
||||
expect(v.valid_value?('chocolate')).to eq(false)
|
||||
expect(v.valid_value?('a')).to eq(false)
|
||||
expect(v.valid_value?('a b c')).to eq(true)
|
||||
expect(v.valid_value?('a b')).to eq(true)
|
||||
end
|
||||
|
||||
it "min, max, and regex" do
|
||||
v = described_class.new(min: 3, max: 12, regex: 'bacon')
|
||||
v.valid_value?('go bacon!').should == true
|
||||
v.valid_value?('sprinkle bacon on your cereal').should == false
|
||||
v.valid_value?('ba').should == false
|
||||
expect(v.valid_value?('go bacon!')).to eq(true)
|
||||
expect(v.valid_value?('sprinkle bacon on your cereal')).to eq(false)
|
||||
expect(v.valid_value?('ba')).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -5,17 +5,17 @@ describe UsernameSettingValidator do
|
||||
subject(:validator) { described_class.new }
|
||||
|
||||
it "returns true for blank values" do
|
||||
validator.valid_value?('').should == true
|
||||
validator.valid_value?(nil).should == true
|
||||
expect(validator.valid_value?('')).to eq(true)
|
||||
expect(validator.valid_value?(nil)).to eq(true)
|
||||
end
|
||||
|
||||
it "returns true if value matches an existing user's username" do
|
||||
Fabricate(:user, username: 'vader')
|
||||
validator.valid_value?('vader').should == true
|
||||
expect(validator.valid_value?('vader')).to eq(true)
|
||||
end
|
||||
|
||||
it "returns false if value does not match a user's username" do
|
||||
validator.valid_value?('no way').should == false
|
||||
expect(validator.valid_value?('no way')).to eq(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user