Skip to content

Commit 7478e26

Browse files
committed
added test for EditsValidations model concern
1 parent 7a28016 commit 7478e26

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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

0 commit comments

Comments
 (0)