add tests

This commit is contained in:
2026-01-22 15:54:43 +01:00
parent 5674e6b21a
commit 0de8e1ad14
10 changed files with 220 additions and 47 deletions
+25 -3
View File
@@ -1,7 +1,29 @@
require "test_helper"
class CommentTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
test "should be valid with a user, body, and commentable" do
user = users(:one)
entry = entries(:one)
comment = Comment.new(user: user, body: "This is a comment.", commentable: entry)
assert comment.valid?
end
test "should be invalid without a body" do
user = users(:one)
entry = entries(:one)
comment = Comment.new(user: user, commentable: entry)
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)
assert_not comment.valid?
end
test "should be invalid without a commentable" do
user = users(:one)
comment = Comment.new(user: user, body: "This is a comment.")
assert_not comment.valid?
end
end
+39 -3
View File
@@ -1,7 +1,43 @@
require "test_helper"
class EntryTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
test "should be valid with a category" do
entry = Entry.new(category: :word)
assert entry.valid?
end
test "should be invalid without a category" do
entry = Entry.new(category: nil)
assert_not entry.valid?
end
test "can be a word" do
entry = Entry.new(category: :word)
assert entry.word?
end
test "can be a phrase" do
entry = Entry.new(category: :phrase)
assert entry.phrase?
end
test "can be a proper_name" do
entry = Entry.new(category: :proper_name)
assert entry.proper_name?
end
test "can be a title" do
entry = Entry.new(category: :title)
assert entry.title?
end
test "can be a reference" do
entry = Entry.new(category: :reference)
assert entry.reference?
end
test "can be other" do
entry = Entry.new(category: :other)
assert entry.other?
end
end
+32 -3
View File
@@ -1,7 +1,36 @@
require "test_helper"
class EntryVersionTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
test "should be valid with all attributes" do
version = EntryVersion.new(
entry: entries(:one),
user: users(:one),
changes_made: { "fi" => "uusi sana" }
)
assert version.valid?
end
test "should be invalid without changes_made" do
version = EntryVersion.new(
entry: entries(:one),
user: users(:one)
)
assert_not version.valid?
end
test "should be invalid without an entry" do
version = EntryVersion.new(
user: users(:one),
changes_made: { "fi" => "uusi sana" }
)
assert_not version.valid?
end
test "should be invalid without a user" do
version = EntryVersion.new(
entry: entries(:one),
changes_made: { "fi" => "uusi sana" }
)
assert_not version.valid?
end
end
+59 -3
View File
@@ -1,7 +1,63 @@
require "test_helper"
class SuggestedMeaningTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
test "should be valid with all attributes" do
meaning = SuggestedMeaning.new(
entry: entries(:one),
language_code: supported_languages(:one).code,
alternative_translation: "New Translation",
submitted_by: users(:one)
)
assert meaning.valid?
end
test "should be invalid without a language_code" do
meaning = SuggestedMeaning.new(
entry: entries(:one),
alternative_translation: "New Translation",
submitted_by: users(:one)
)
assert_not meaning.valid?
end
test "should be invalid without an alternative_translation" do
meaning = SuggestedMeaning.new(
entry: entries(:one),
language_code: supported_languages(:one).code,
submitted_by: users(:one)
)
assert_not meaning.valid?
end
test "should have a default status of pending" do
meaning = SuggestedMeaning.new(
entry: entries(:one),
language_code: supported_languages(:one).code,
alternative_translation: "New Translation",
submitted_by: users(:one)
)
assert meaning.pending?
end
test "can be accepted" do
meaning = SuggestedMeaning.new(
entry: entries(:one),
language_code: supported_languages(:one).code,
alternative_translation: "New Translation",
submitted_by: users(:one),
status: :accepted
)
assert meaning.accepted?
end
test "can be rejected" do
meaning = SuggestedMeaning.new(
entry: entries(:one),
language_code: supported_languages(:one).code,
alternative_translation: "New Translation",
submitted_by: users(:one),
status: :rejected
)
assert meaning.rejected?
end
end
+10 -3
View File
@@ -1,7 +1,14 @@
require "test_helper"
class SupportedLanguageTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
test "should be valid with all attributes" do
language = SupportedLanguage.new(code: "es", name: "Spanish", native_name: "Español")
assert language.valid?
end
test "should be invalid with a duplicate code" do
SupportedLanguage.create(code: "de", name: "German", native_name: "Deutsch")
language = SupportedLanguage.new(code: "de", name: "German", native_name: "Deutsch")
assert_not language.valid?
end
end
+30 -3
View File
@@ -1,7 +1,34 @@
require "test_helper"
class UserTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
test "should be valid with an email and password" do
user = User.new(email: "test@example.com", password: "password")
assert user.valid?
end
test "should be invalid without an email" do
user = User.new(password: "password")
assert_not user.valid?
end
test "should be invalid with a duplicate email" do
User.create(email: "test@example.com", password: "password")
user = User.new(email: "test@example.com", password: "password")
assert_not user.valid?
end
test "should have a default role of contributor" do
user = User.new(email: "test@example.com", password: "password")
assert user.contributor?
end
test "can be a reviewer" do
user = User.new(email: "test@example.com", password: "password", role: :reviewer)
assert user.reviewer?
end
test "can be an admin" do
user = User.new(email: "test@example.com", password: "password", role: :admin)
assert user.admin?
end
end