Permalink
Browse files

Merge pull request #8 from gmalette/fix-numeric-and-nil-values

Fix numeric values and undefined keys
  • Loading branch information...
2 parents f615746 + d61d851 commit 0c6404a17477de4e4be902ad24634cddb9ec627b @cheezy committed Jul 16, 2013
Showing with 15 additions and 1 deletion.
  1. +2 −1 lib/data_magic.rb
  2. +13 −0 spec/lib/translation_spec.rb
View
@@ -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
@@ -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 0c6404a

Please sign in to comment.