DRY supported_languages

This commit is contained in:
2026-01-23 21:55:06 +01:00
parent a7713b962f
commit b3726e0777
8 changed files with 46 additions and 23 deletions
+20 -8
View File
@@ -1,29 +1,41 @@
require "test_helper"
class CommentTest < ActiveSupport::TestCase
test "should be valid with a user, body, and commentable" do
user = users(:admin_user)
test "should be valid with a user, body, commentable, and language code" do
user = users(:contributor_user)
entry = entries(:one)
comment = Comment.new(user: user, body: "This is a comment.", commentable: entry)
language = supported_languages(:one)
comment = Comment.new(user: user, body: "This is a comment.", commentable: entry, language: language)
assert comment.valid?
end
test "should be valid without a language code" do
user = users(:contributor_user)
entry = entries(:one)
comment = Comment.new(user: user, body: "General note.", commentable: entry, language_code: nil)
assert comment.valid?
end
test "should be invalid without a body" do
user = users(:admin_user)
user = users(:contributor_user)
entry = entries(:one)
comment = Comment.new(user: user, commentable: entry)
language = supported_languages(:one)
comment = Comment.new(user: user, commentable: entry, language: language)
assert_not comment.valid?
end
test "should be invalid without a user" do
entry = entries(:one)
comment = Comment.new(body: "This is a comment.", commentable: entry)
language = supported_languages(:one)
comment = Comment.new(body: "This is a comment.", commentable: entry, language: language)
assert_not comment.valid?
end
test "should be invalid without a commentable" do
user = users(:admin_user)
comment = Comment.new(user: user, body: "This is a comment.")
user = users(:contributor_user)
language = supported_languages(:one)
comment = Comment.new(user: user, body: "This is a comment.", language: language)
assert_not comment.valid?
end
end