Skip to content

Commit

Permalink
Recondition Tolk::Translation#value to accommodate string values that…
Browse files Browse the repository at this point in the history
… are invalid YAML.
  • Loading branch information
Craig Davey committed Apr 22, 2010
1 parent b3263c8 commit d2e11dd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
10 changes: 5 additions & 5 deletions app/models/tolk/translation.rb
Expand Up @@ -31,8 +31,8 @@ def text=(value)
end

def value
if text.is_a?(String)
YAML.load text
if text.is_a?(String) && /^\d+$/.match(text)
text.to_i
else
text
end
Expand All @@ -48,12 +48,12 @@ def fix_text_type
rescue ArgumentError
nil
end

end

self.text = nil if primary_translation.text.class != self.text.class
end

true
end

Expand Down
5 changes: 5 additions & 0 deletions test/unit/translation_test.rb
Expand Up @@ -27,6 +27,11 @@ def setup
assert_equal "Hello World", tolk_translations(:hello_world_en).value
end

test "translation with string value with variables" do
text = "{{attribute}} {{message}}"
assert_equal text, Tolk::Translation.new(:text => text).value
end

test "translation with numeric value" do
assert_equal 1, tolk_translations(:human_format_precision_en).value
end
Expand Down

0 comments on commit d2e11dd

Please sign in to comment.