Skip to content
Browse files

Fix numeric values and undefined keys

  • Loading branch information...
1 parent f615746 commit d61d851a8594f86e9c988ba3b20bcc92dd5f9209 @gmalette gmalette committed
Showing with 15 additions and 1 deletion.
  1. +2 −1 lib/data_magic.rb
  2. +13 −0 spec/lib/translation_spec.rb
View
3 lib/data_magic.rb
@@ -20,6 +20,7 @@ def self.included(cls)
def data_for(key, additional={})
DataMagic.load('default.yml') unless DataMagic.yml
data = DataMagic.yml[key.to_s]
+ raise ArgumentError, "Undefined key #{key}" unless data
prep_data data.merge(additional).clone
end
@@ -28,7 +29,7 @@ def data_for(key, additional={})
def prep_data(data)
data.each do |key, value|
unless value.nil?
- next unless value.respond_to? '[]'
+ next if !value.respond_to?('[]') || value.is_a?(Numeric)
data[key] = translate(value[1..-1]) if value[0,1] == "~"
end
end
View
13 spec/lib/translation_spec.rb
@@ -250,6 +250,19 @@ def set_field_value(value)
end
end
+ context "with numeric values" do
+ it "doesn't translate values" do
+ set_field_value(1)
+ example.data_for("key").should have_field_value 1
+ end
+ end
+
+ context "with values not in the yaml" do
+ it "throws a ArgumentError" do
+ expect { example.data_for("inexistant_key") }.to raise_error ArgumentError
+ end
+ end
+
context "providing date values" do
it "should provide today's date" do
set_field_value '~today'

0 comments on commit d61d851

Please sign in to comment.
Something went wrong with that request. Please try again.