Permalink
Browse files

Fixes issue #106 with common primitives not being converted to a Stri…

…ng during template expansion.
  • Loading branch information...
sporkmonger committed Feb 19, 2013
1 parent be57d0a commit ac9d34f1fad8e63b3ee1338c1cddaec60545eb90
Showing with 17 additions and 1 deletion.
  1. +5 −1 lib/addressable/template.rb
  2. +12 −0 spec/addressable/template_spec.rb
@@ -597,7 +597,11 @@ def transform_capture(mapping, capture, processor=nil)
value = mapping[name]
unless value == nil || value == {}
allow_reserved = %w(+ #).include?(operator)
- value = value.to_s if Numeric === value || Symbol === value
+ # Common primitives where the .to_s output is well-defined
+ if Numeric === value || Symbol === value ||
+ value == true || value == false
+ value = value.to_s
+ end
length = modifier.gsub(':', '').to_i if modifier =~ /^:\d+/
unless (Hash === value) ||
@@ -14,6 +14,18 @@
end
end
+describe "Type conversion" do
+ subject{
+ {:var => true, :hello => 1234, :nothing => nil, :sym => :symbolic}
+ }
+ it_behaves_like 'expands', {
+ '{var}' => 'true',
+ '{hello}' => '1234',
+ '{nothing}' => '',
+ '{sym}' => 'symbolic'
+ }
+end
+
describe "Level 1:" do
subject{
{:var => "value", :hello => "Hello World!"}

0 comments on commit ac9d34f

Please sign in to comment.