To validate the presence of translation using the mobility gem in Minitest, you can define a test case that checks if the translated value is present in the database. Here's an example:
require 'test_helper'
class MyModelTest < ActiveSupport::TestCase
test "should save translated value" do
object = MyModel.create(title: "Hello", title_fr: "Bonjour")
assert_equal "Hello", object.title
assert_equal "Bonjour", object.title_fr
end
end
In this example, we create an instance of MyModel
with the title
attribute set to "Hello" and the title_fr
attribute set to "Bonjour". We then use assert_equal
to validate that the correct values are saved in the database.
If the translated value is not present, the test will fail and you'll need to investigate the cause of the error.
Asked: 2022-02-24 11:00:00 +0000
Seen: 14 times
Last updated: Sep 27 '21