File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ require 'test_helper'
2+
3+ class EditsValidationsTest < ActiveSupport ::TestCase
4+ def setup
5+ @klass = Class . new do
6+ include ActiveModel ::Validations
7+ include EditsValidations
8+
9+ def self . name
10+ 'EditsValidationsTest' # otherwise, ActiveModel::Name will error out
11+ end
12+
13+ def initialize ( comment )
14+ super ( )
15+ @comment = comment
16+ end
17+
18+ attr_accessor :comment
19+ end
20+ end
21+
22+ test 'max_edit_comment_length should correctly validate comment length' do
23+ max_length = 5
24+
25+ SiteSetting [ 'MaxEditCommentLength' ] = max_length
26+
27+ [ 'a' * max_length , 'b' * ( max_length + 1 ) ] . each do |comment |
28+ instance = @klass . new ( comment )
29+
30+ is_valid = instance . valid?
31+
32+ if comment . length <= max_length
33+ assert is_valid
34+ assert instance . errors . none?
35+ else
36+ assert_not is_valid
37+ assert instance . errors [ :base ] . any?
38+ end
39+ end
40+ end
41+ end
You can’t perform that action at this time.
0 commit comments