Skip to content

Commit

Permalink
Add translation model tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CuddlyBunion341 committed Oct 22, 2024
1 parent 35afd18 commit 1f28c17
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/models/translation_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require 'test_helper'

module Moirai
class TranslationTest < ActiveSupport::TestCase
def setup
@valid_translation = Translation.new(key: 'hello', locale: 'en', file_path: '/valid/path/to/file')
@invalid_translation = Translation.new(key: 'hello', locale: 'en', file_path: '/invalid/path/to/file')
end

test "should be valid with valid attributes" do
File.stub :exist?, true do
assert @valid_translation.valid?
end
end

test "should be invalid without key" do
@valid_translation.key = nil
assert_not @valid_translation.valid?
assert_includes @valid_translation.errors[:key], "can't be blank"
end

test "should be invalid without locale" do
@valid_translation.locale = nil
assert_not @valid_translation.valid?
assert_includes @valid_translation.errors[:locale], "can't be blank"
end

test "should be invalid without file_path" do
@valid_translation.file_path = nil
assert_not @valid_translation.valid?
assert_includes @valid_translation.errors[:file_path], "can't be blank"
end

test "should be invalid if file_path does not exist" do
File.stub :exist?, false do
assert_not @invalid_translation.valid?
assert_includes @invalid_translation.errors[:file_path], "must exist"
end
end
end
end

0 comments on commit 1f28c17

Please sign in to comment.