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
+2 -2
View File
@@ -3,11 +3,11 @@
one:
entry: one
user: one
changes_made:
changes_made: "{}"
change_type: MyString
two:
entry: two
user: two
changes_made:
changes_made: "{}"
change_type: MyString
+4 -8
View File
@@ -2,26 +2,22 @@
one:
entry: one
language_code: MyString
language_code: "en"
alternative_translation: MyString
context: MyText
reasoning: MyText
source: MyString
region: MyString
status: 1
status: :pending
submitted_by: one
reviewed_by: one
reviewed_at: 2026-01-22 13:38:22
two:
entry: two
language_code: MyString
language_code: "fi"
alternative_translation: MyString
context: MyText
reasoning: MyText
source: MyString
region: MyString
status: 1
status: :pending
submitted_by: two
reviewed_by: two
reviewed_at: 2026-01-22 13:38:22
+9 -9
View File
@@ -1,15 +1,15 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
code: MyString
name: MyString
native_name: MyString
code: "en"
name: "English"
native_name: "English"
sort_order: 1
active: false
active: true
two:
code: MyString
name: MyString
native_name: MyString
sort_order: 1
active: false
code: "fi"
name: "Finnish"
native_name: "Suomi"
sort_order: 2
active: true
+10 -10
View File
@@ -1,23 +1,23 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
email: MyString
password_digest: MyString
name: MyString
email: "one@example.com"
password_digest: <%= BCrypt::Password.create('password') %>
name: "User One"
role: 1
primary_language: MyString
invitation_token: MyString
primary_language: "en"
invitation_token: "one"
invitation_sent_at: 2026-01-22 13:38:37
invitation_accepted_at: 2026-01-22 13:38:37
invited_by: one
two:
email: MyString
password_digest: MyString
name: MyString
email: "two@example.com"
password_digest: <%= BCrypt::Password.create('password') %>
name: "User Two"
role: 1
primary_language: MyString
invitation_token: MyString
primary_language: "fi"
invitation_token: "two"
invitation_sent_at: 2026-01-22 13:38:37
invitation_accepted_at: 2026-01-22 13:38:37
invited_by: two
+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