Misc coverage improvements for validators (#23928)
This commit is contained in:
		@@ -23,6 +23,11 @@ RSpec.describe Import, type: :model do
 | 
			
		||||
      expect(import).to model_have_error_on_field(:data)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'is invalid with malformed data' do
 | 
			
		||||
      import = Import.create(account: account, type: type, data: StringIO.new('\"test'))
 | 
			
		||||
      expect(import).to model_have_error_on_field(:data)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'is invalid with too many rows in data' do
 | 
			
		||||
      import = Import.create(account: account, type: type, data: StringIO.new("foo@bar.com\n" * (ImportService::ROWS_PROCESSING_LIMIT + 10)))
 | 
			
		||||
      expect(import).to model_have_error_on_field(:data)
 | 
			
		||||
 
 | 
			
		||||
@@ -2,5 +2,22 @@
 | 
			
		||||
 | 
			
		||||
require 'rails_helper'
 | 
			
		||||
 | 
			
		||||
RSpec.describe OneTimeKey, type: :model do
 | 
			
		||||
describe OneTimeKey do
 | 
			
		||||
  describe 'validations' do
 | 
			
		||||
    context 'with an invalid signature' do
 | 
			
		||||
      let(:one_time_key) { Fabricate.build(:one_time_key, signature: 'wrong!') }
 | 
			
		||||
 | 
			
		||||
      it 'is invalid' do
 | 
			
		||||
        expect(one_time_key).to_not be_valid
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    context 'with an invalid key' do
 | 
			
		||||
      let(:one_time_key) { Fabricate.build(:one_time_key, key: 'wrong!') }
 | 
			
		||||
 | 
			
		||||
      it 'is invalid' do
 | 
			
		||||
        expect(one_time_key).to_not be_valid
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 
 | 
			
		||||
@@ -41,6 +41,22 @@ describe EmailMxValidator do
 | 
			
		||||
      expect(user.errors).to_not have_received(:add)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'adds an error if the TagManager fails to normalize domain' do
 | 
			
		||||
      double = instance_double(TagManager)
 | 
			
		||||
      allow(TagManager).to receive(:instance).and_return(double)
 | 
			
		||||
      allow(double).to receive(:normalize_domain).with('example.com').and_raise(Addressable::URI::InvalidURIError)
 | 
			
		||||
 | 
			
		||||
      user = double(email: 'foo@example.com', errors: double(add: nil))
 | 
			
		||||
      subject.validate(user)
 | 
			
		||||
      expect(user.errors).to have_received(:add)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'adds an error if the domain email portion is blank' do
 | 
			
		||||
      user = double(email: 'foo@', errors: double(add: nil))
 | 
			
		||||
      subject.validate(user)
 | 
			
		||||
      expect(user.errors).to have_received(:add)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it 'adds an error if the email domain name contains empty labels' do
 | 
			
		||||
      resolver = double
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user