Skip to content

Commit

Permalink
Fix nil exception, when reading empty translated values
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin B committed Jul 30, 2016
1 parent 4045d9a commit 24f523e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
18 changes: 9 additions & 9 deletions .idea/awesome_hstore_translate.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ def read_translated_attribute(attr, locale = I18n.locale)

translations = read_raw_attribute(attr)

locales.uniq.each do |cur|
if translations.has_key?(cur.to_s) && !translations[cur.to_s].empty?
return translations[cur.to_s]
if translations
locales.uniq.each do |cur|
if translations.has_key?(cur.to_s) && !translations[cur.to_s].empty?
return translations[cur.to_s]
end
end
end

Expand Down
5 changes: 5 additions & 0 deletions test/awesome_hstore_translate_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,9 @@ def test_find_by_query_with_translated_value
res = PageWithFallbacks.find_by(title: 'Another English title')
assert_equal(exp.id, res.id)
end

def test_with_empty_translated_value
new = PageWithFallbacks.new
assert_nil(new.title)
end
end

0 comments on commit 24f523e

Please sign in to comment.