Skip to content

Commit

Permalink
fix locales generator spec
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Bob committed Nov 21, 2024
1 parent 0a860d1 commit 681aaf2
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions spec/features/avo/generators/locales_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@

RSpec.feature "locales generator", type: :feature do
it "generates the files" do
# Backup the en locale
en_locale_backup = Rails.root.join("config", "locales", "avo.en.yml.bak")
FileUtils.cp(Rails.root.join("config", "locales", "avo.en.yml"), en_locale_backup)
# Define locales to backup
backup_locales = %w[en pt]

locales = %w[en fr nn nb pt-BR pt ro tr ar ja es]
# Backup locales
backup_files = {}
backup_locales.each do |locale|
original_file = Rails.root.join("config", "locales", "avo.#{locale}.yml")
backup_file = Rails.root.join("config", "locales", "avo.#{locale}.yml.bak")
FileUtils.cp(original_file, backup_file) if File.exist?(original_file)
backup_files[locale] = { original: original_file, backup: backup_file }
end

locales = %w[ar de en es fr it ja nb nl nn pl pt-BR pt ro ru tr uk zh]

files = locales.map do |locale|
Rails.root.join("config", "locales", "avo.#{locale}.yml").to_s
Expand All @@ -17,11 +25,13 @@
files << Rails.root.join("config", "locales", "pagy", "#{locale}.yml").to_s
end

Rails::Generators.invoke("avo:locales", ["-q"], {destination_root: Rails.root})
Rails::Generators.invoke("avo:locales", ["-q"], { destination_root: Rails.root })

check_files_and_clean_up files

# Restore the en locale
FileUtils.mv(en_locale_backup, Rails.root.join("config", "locales", "avo.en.yml"))
# Restore locales from backup
backup_files.each do |locale, paths|
FileUtils.mv(paths[:backup], paths[:original]) if File.exist?(paths[:backup])
end
end
end

0 comments on commit 681aaf2

Please sign in to comment.