Skip to content

Commit

Permalink
change i18n directory check (#899)
Browse files Browse the repository at this point in the history
Source of the issue is that for a directory object, blank? returns true
if the directory is empty.

* change i18n directory check
* added test for i18n_dir = '' in addition to i18n_dir = nil, removed whitespaces, updated changelog
*  if somebody had used "blank" ("") before and they upgrade to this fix, then they probably will be surprised.
  • Loading branch information
hakongit authored and justin808 committed Oct 25, 2017
1 parent 991b50a commit 820ac3c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Changes since last non-beta release.
- Fix to add missing dependency to run generator spec individually: [PR 962](https://github.com/shakacode/react_on_rails/pull/962) by [tricknotes](https://github.com/tricknotes)

*Please add entries here for your pull requests.*
- Fixes check for i18n_dir in LocalesToJs returning false when i18n_dir was set. [PR 899](https://github.com/shakacode/react_on_rails/pull/899) by [hakongit](https://github.com/hakongit)

### [10.0.0] - 2017-10-08
#### Created
Expand Down
5 changes: 4 additions & 1 deletion lib/react_on_rails/locales_to_js.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
module ReactOnRails
class LocalesToJs
def initialize
return if i18n_dir.blank?
if !i18n_dir.nil? && !File.directory?(i18n_dir)
raise "config.i18n_dir is set and it is not a directory. Did you set config.i18n_dir in the react_on_rails initializer?"
end
return if i18n_yml_dir.nil?
return unless obsolete?
@translations, @defaults = generate_translations
convert
Expand Down
7 changes: 7 additions & 0 deletions spec/react_on_rails/locales_to_js_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ module ReactOnRails
let(:translations_path) { "#{i18n_dir}/translations.js" }
let(:default_path) { "#{i18n_dir}/default.js" }

it "with i18n_dir set to ''" do
ReactOnRails.configure do |config|
config.i18n_dir = ''
end
expect { ReactOnRails::LocalesToJs.new }.to raise_error(/config.i18n_dir is set and it is not a directory. Did you set config.i18n_dir in the react_on_rails initializer?/)
end

shared_examples "locale to js" do
context "with obsolete js files" do
before do
Expand Down

0 comments on commit 820ac3c

Please sign in to comment.