ファイル
btrc-hub/backend/spec/support/ainu_locale_contract.rb
T
2026-10-17 16:47:08 +09:00

26 行
975 B
Ruby

RSpec.shared_context 'Ainu locale contract' do
let(:ainu_locale) do
instance_double(Locale, language_code: 'ain', script_code: 'Kana', deprecated_at: nil)
end
before do
# Keep description contracts independent of locale activation and backfill.
Language.connection.execute(<<~SQL)
INSERT IGNORE INTO languages (code, name, created_at)
VALUES ('ain', 'Ainu', CURRENT_TIMESTAMP)
SQL
Script.find_or_create_by!(code: 'Kana') { _1.name = 'Kana' }
allow(Locale).to receive(:find_by).and_call_original
allow(Locale).to receive(:find_by).with(code: 'ain-Kana').and_return(ainu_locale)
end
def add_ainu_name tag, name
TagName.insert_all!([{
tag_id: tag.id, language_code: 'ain', script_code: 'Kana', name:,
primary_flg: true, auto_generated: false,
created_at: Time.current, updated_at: Time.current }])
tag.tag_names.reset
TagName.find_by!(tag_id: tag.id, language_code: 'ain', name:)
end
end