Skip to content

Commit

Permalink
[MINOR] Code formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
blackwinter committed Oct 11, 2012
1 parent 918ea63 commit f24d463
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 35 deletions.
24 changes: 12 additions & 12 deletions lib/wadl/address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,33 +89,33 @@ def bind!(args = {})
if fragment.respond_to?(:to_str)
# This fragment is a string which might contain {} substitutions.
# Make any substitutions available to the provided path variables.
self.class.embedded_param_names(fragment).each { |param_name|
value = path_var_values[param_name] || path_var_values[param_name.to_sym]
self.class.embedded_param_names(fragment).each { |name|
value = path_var_values[name] || path_var_values[name.to_sym]

value = if param = path_params[param_name]
value = if param = path_params[name]
path_params_to_delete << param
param % value
else
Param.default.format(value, param_name)
Param.default.format(value, name)
end

fragment.gsub!("{#{param_name}}", value)
fragment.gsub!("{#{name}}", value)
}
else
# This fragment is an array of Param objects (style 'matrix'
# or 'plain') which may be bound to strings. As substitutions
# happen, the array will become a mixed array of Param objects
# and strings.
fragment.each_with_index { |param, i|
if param.respond_to?(:name)
name = param.name
next unless param.respond_to?(:name)

value = path_var_values[name] || path_var_values[name.to_sym]
value = param % value
fragment[i] = value if value
name = param.name

path_params_to_delete << param
end
value = path_var_values[name] || path_var_values[name.to_sym]
value = param % value
fragment[i] = value if value

path_params_to_delete << param
}
end
}
Expand Down
46 changes: 23 additions & 23 deletions test/wadl_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def wadl(wadl)
EOT
end

# Null test to shut the compiler up.
# Null test to shut the compiler up. (Ruby < 1.9)
def test_null
end

Expand Down Expand Up @@ -251,10 +251,12 @@ def test_matrix_values
assert_equal(lights.uri(:path => { :light3 => true }), off_uri)
end

class RequestFormatTests < WADLTest
end

class RequestFormatTests < WADLTest

def setup
@wadl = wadl(<<-EOT)
def setup
@wadl = wadl(<<-EOT)
<resources base="http://www.example.com/">
<resource id="top" path="palette">
<param style="form" name="api_key" />
Expand All @@ -279,32 +281,30 @@ def setup
</representation>
</request>
</method>
EOT

@color = @wadl.find_resource('top').bind(:query => { :api_key => 'foobar' }).find_resource('color')
end
EOT

def test_query_vars
graphic = @color.find_method('get_graphic')
path = { :color => 'blue' }
query = { :shade => 'light' }
@color = @wadl.find_resource('top').bind(:query => { :api_key => 'foobar' }).find_resource('color')
end

assert_equal(graphic.request.uri(@color, :path => path, :query => query),
'http://www.example.com/palette/colors/blue?shade=light')
def test_query_vars
graphic = @color.find_method('get_graphic')
path = { :color => 'blue' }
query = { :shade => 'light' }

assert_raises(ArgumentError) { graphic.request.uri(@color, path) }
end
assert_equal(graphic.request.uri(@color, :path => path, :query => query),
'http://www.example.com/palette/colors/blue?shade=light')

def test_representation
graphic = @color.find_method('set_graphic')
representation = graphic.request.find_form
assert_raises(ArgumentError) { graphic.request.uri(@color, path) }
end

assert_equal(representation % { :new_graphic => 'foobar', 'filename' => 'blue.jpg' },
'new_graphic=foobar&filename=blue.jpg')
def test_representation
graphic = @color.find_method('set_graphic')
representation = graphic.request.find_form

assert_raises(ArgumentError) { representation % { :new_graphic => 'foobar' } }
end
assert_equal(representation % { :new_graphic => 'foobar', 'filename' => 'blue.jpg' },
'new_graphic=foobar&filename=blue.jpg')

assert_raises(ArgumentError) { representation % { :new_graphic => 'foobar' } }
end

end

0 comments on commit f24d463

Please sign in to comment.