Add ability to manage which websites can credit you in link previews (#31819)
This commit is contained in:
parent
3929e3c6d2
commit
e0c27a5047
92 changed files with 381 additions and 160 deletions
46
spec/validators/lines_validator_spec.rb
Normal file
46
spec/validators/lines_validator_spec.rb
Normal file
|
@ -0,0 +1,46 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe LinesValidator do
|
||||
let(:record_class) do
|
||||
Class.new do
|
||||
include ActiveModel::Validations
|
||||
|
||||
attr_accessor :text
|
||||
|
||||
validates :text, lines: { maximum: 5 }
|
||||
end
|
||||
end
|
||||
|
||||
let(:record) { record_class.new }
|
||||
|
||||
describe '#validate_each' do
|
||||
context 'with a nil value' do
|
||||
it 'does not add errors' do
|
||||
record.text = nil
|
||||
|
||||
expect(record).to be_valid
|
||||
expect(record.errors).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
context 'with lines below the limit' do
|
||||
it 'does not add errors' do
|
||||
record.text = "hoge\n" * 5
|
||||
|
||||
expect(record).to be_valid
|
||||
expect(record.errors).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
context 'with more lines than limit' do
|
||||
it 'adds an error' do
|
||||
record.text = "hoge\n" * 6
|
||||
|
||||
expect(record).to_not be_valid
|
||||
expect(record.errors.where(:text)).to_not be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue