Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix numeric values and undefined keys #8

Merged
merged 1 commit into from Jul 16, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/data_magic.rb
Expand Up @@ -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

Expand All @@ -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
Expand Down
13 changes: 13 additions & 0 deletions spec/lib/translation_spec.rb
Expand Up @@ -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'
Expand Down