Skip to content

Commit

Permalink
Make sure to raise exception on Rails app loading if the click.yml is…
Browse files Browse the repository at this point in the history
… missing or empty. Make sure to raise exception if no base language was defined in click.yml
  • Loading branch information
Luca Guidi committed Jul 16, 2008
1 parent 14a040f commit c7613ff
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lib/click_to_globalize.rb
Expand Up @@ -53,12 +53,15 @@ def all #:nodoc:

# Hash representation of config_file.
def configuration
@@configuration ||= YAML::load_file(config_file)
@@configuration ||= begin
result = YAML::load_file(config_file)
raise NoConfiguredLocalesError unless result
result
end
end

# Load all the locales in config_file.
def load_locales
raise NoConfiguredLocalesError unless configuration
configuration['locales'].symbolize_keys!
end

Expand Down
2 changes: 1 addition & 1 deletion test/click_to_globalize_test.rb
Expand Up @@ -106,7 +106,7 @@ def test_should_load_locales_from_configuration_file

def test_should_raise_exception_for_missing_configured_languages
uses_config_file 'empty.yml' do
assert_raise(NoConfiguredLocalesError) { Locale.load_locales }
assert_raise(NoConfiguredLocalesError) { Locale.configuration }
end
end

Expand Down
14 changes: 14 additions & 0 deletions test/config/no_default.yml
@@ -0,0 +1,14 @@
# Click to Globalize
#
# Add all the locales you wish to be available in your application.
#
# You can configure the base language (optional):
# default: :english
# This is equivalent to:
# Locale.set_base_language('en-US')
#
# You may also wish to use Textile or Markdown.
#
locales:
english: en-US
italian: it-IT

0 comments on commit c7613ff

Please sign in to comment.