add controller tests

This commit is contained in:
2026-01-23 12:20:31 +01:00
parent dea0ef508a
commit 35c29749fb
16 changed files with 515 additions and 51 deletions
+3 -3
View File
@@ -2,14 +2,14 @@ require "test_helper"
class CommentTest < ActiveSupport::TestCase
test "should be valid with a user, body, and commentable" do
user = users(:one)
user = users(:admin_user)
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)
user = users(:admin_user)
entry = entries(:one)
comment = Comment.new(user: user, commentable: entry)
assert_not comment.valid?
@@ -22,7 +22,7 @@ class CommentTest < ActiveSupport::TestCase
end
test "should be invalid without a commentable" do
user = users(:one)
user = users(:admin_user)
comment = Comment.new(user: user, body: "This is a comment.")
assert_not comment.valid?
end
+3 -3
View File
@@ -4,7 +4,7 @@ class EntryVersionTest < ActiveSupport::TestCase
test "should be valid with all attributes" do
version = EntryVersion.new(
entry: entries(:one),
user: users(:one),
user: users(:admin_user),
changes_made: { "fi" => "uusi sana" }
)
assert version.valid?
@@ -13,14 +13,14 @@ class EntryVersionTest < ActiveSupport::TestCase
test "should be invalid without changes_made" do
version = EntryVersion.new(
entry: entries(:one),
user: users(:one)
user: users(:admin_user)
)
assert_not version.valid?
end
test "should be invalid without an entry" do
version = EntryVersion.new(
user: users(:one),
user: users(:admin_user),
changes_made: { "fi" => "uusi sana" }
)
assert_not version.valid?
+6 -6
View File
@@ -6,7 +6,7 @@ class SuggestedMeaningTest < ActiveSupport::TestCase
entry: entries(:one),
language_code: supported_languages(:one).code,
alternative_translation: "New Translation",
submitted_by: users(:one)
submitted_by: users(:contributor_user)
)
assert meaning.valid?
end
@@ -15,7 +15,7 @@ class SuggestedMeaningTest < ActiveSupport::TestCase
meaning = SuggestedMeaning.new(
entry: entries(:one),
alternative_translation: "New Translation",
submitted_by: users(:one)
submitted_by: users(:contributor_user)
)
assert_not meaning.valid?
end
@@ -24,7 +24,7 @@ class SuggestedMeaningTest < ActiveSupport::TestCase
meaning = SuggestedMeaning.new(
entry: entries(:one),
language_code: supported_languages(:one).code,
submitted_by: users(:one)
submitted_by: users(:contributor_user)
)
assert_not meaning.valid?
end
@@ -34,7 +34,7 @@ class SuggestedMeaningTest < ActiveSupport::TestCase
entry: entries(:one),
language_code: supported_languages(:one).code,
alternative_translation: "New Translation",
submitted_by: users(:one)
submitted_by: users(:contributor_user)
)
assert meaning.pending?
end
@@ -44,7 +44,7 @@ class SuggestedMeaningTest < ActiveSupport::TestCase
entry: entries(:one),
language_code: supported_languages(:one).code,
alternative_translation: "New Translation",
submitted_by: users(:one),
submitted_by: users(:contributor_user),
status: :accepted
)
assert meaning.accepted?
@@ -55,7 +55,7 @@ class SuggestedMeaningTest < ActiveSupport::TestCase
entry: entries(:one),
language_code: supported_languages(:one).code,
alternative_translation: "New Translation",
submitted_by: users(:one),
submitted_by: users(:contributor_user),
status: :rejected
)
assert meaning.rejected?
+2 -3
View File
@@ -2,13 +2,12 @@ require "test_helper"
class SupportedLanguageTest < ActiveSupport::TestCase
test "should be valid with all attributes" do
language = SupportedLanguage.new(code: "es", name: "Spanish", native_name: "Español")
language = SupportedLanguage.new(code: "sv", name: "Swedish", native_name: "Svenska")
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")
language = SupportedLanguage.new(code: supported_languages(:one).code, name: "English", native_name: "English")
assert_not language.valid?
end
end
+6 -6
View File
@@ -2,7 +2,7 @@ require "test_helper"
class UserTest < ActiveSupport::TestCase
test "should be valid with an email and password" do
user = User.new(email: "test@example.com", password: "password123456")
user = User.new(email: "new-user@example.com", password: "password123456")
assert user.valid?
end
@@ -12,23 +12,23 @@ class UserTest < ActiveSupport::TestCase
end
test "should be invalid with a duplicate email" do
User.create(email: "test@example.com", password: "password123456")
user = User.new(email: "test@example.com", password: "password123456")
existing_user = users(:admin_user)
user = User.new(email: existing_user.email, password: "password123456")
assert_not user.valid?
end
test "should have a default role of contributor" do
user = User.new(email: "test@example.com", password: "password123456")
user = User.new(email: "new-user@example.com", password: "password123456")
assert user.contributor?
end
test "can be a reviewer" do
user = User.new(email: "test@example.com", password: "password123456", role: :reviewer)
user = User.new(email: "new-user@example.com", password: "password123456", role: :reviewer)
assert user.reviewer?
end
test "can be an admin" do
user = User.new(email: "test@example.com", password: "password123456", role: :admin)
user = User.new(email: "new-user@example.com", password: "password123456", role: :admin)
assert user.admin?
end