Ask Your Question
2

How can the presence of translation be validated using the mobility gem in Minitest?

asked 2022-02-24 11:00:00 +0000

woof gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2021-09-27 23:00:00 +0000

david gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-02-24 11:00:00 +0000

Seen: 14 times

Last updated: Sep 27 '21