Skip to content
Browse files

allow for anonymous arrays and nodes

  • Loading branch information...
1 parent 9397114 commit 3efcd30ecde03beba04217a892db98185fd9d344 @mattetti committed
Showing with 40 additions and 5 deletions.
  1. +3 −0 CHANGELOG.md
  2. +3 −3 lib/response.rb
  3. +1 −1 lib/weasel_diesel/version.rb
  4. +33 −1 spec/json_response_description_spec.rb
View
3 CHANGELOG.md
@@ -3,6 +3,9 @@
All changes can be seen on GitHub and git tags are used to isolate each
release.
+1.2.2:
+* Added support for anonymous top level arrays.
+
*1.2.1*:
* Modified the way an empty string param is cast/verified. If a param is
View
6 lib/response.rb
@@ -34,7 +34,7 @@ def nodes
# @param [String, Symbol] name the name of the element.
# @param [Hash] opts the element options.
# @see Vector#initialize
- def array(name, type=nil)
+ def array(name=nil, type=nil)
vector = Vector.new(name, type)
yield(vector) if block_given?
@arrays << vector
@@ -101,7 +101,7 @@ def to_hash
end
# The Response element class describing each element of a service response.
- # Instances are usually not instiated directly but via the Response#element accessor.
+ # Instances are usually not instantiated directly but via the Response#element accessor.
#
# @see WeaselDiesel::Response#element
# @api public
@@ -273,7 +273,7 @@ def element(opts={})
#
# @param [Symbol, String] name the name of the element.
# @param [Hash] opts the options for the newly created element.
- def object(name, opts={}, &block)
+ def object(name=nil, opts={}, &block)
element(opts.merge(:name => name), &block)
end
View
2 lib/weasel_diesel/version.rb
@@ -1,3 +1,3 @@
class WeaselDiesel
- VERSION = "1.2.1"
+ VERSION = "1.2.2"
end
View
34 spec/json_response_description_spec.rb
@@ -176,7 +176,7 @@
@response = @service.response
end
- it "should have a properly structured reponse" do
+ it "should have a properly structured response" do
top_object = @service.response.elements.first
top_object.should_not be_nil
name_node = top_object.properties.find{|o| o.name == :name}
@@ -185,3 +185,35 @@
end
end
+
+
+describe "WeaselDiesel top level array response description" do
+
+=begin
+'[ { "name":"Bob" }, { "name": "Judy" } ]'
+=end
+
+ before :all do
+ @service = describe_service 'tl_array' do |service|
+ service.formats :json
+ service.response do |response|
+ # anonymous array response
+ response.array do |arr|
+ arr.object do |node|
+ node.string :name
+ end
+ end
+ end
+ end
+ end
+
+ it "should have a properly structured response" do
+ top_object = @service.response.nodes.first
+ top_object.should_not be_nil
+ top_object.should be_an_instance_of(WeaselDiesel::Response::Vector)
+ top_object.elements.first.should_not be_nil
+ top_object.elements.first.attributes.first.name.should eq(:name)
+ top_object.elements.first.attributes.first.type.should eq(:string)
+ end
+
+end

0 comments on commit 3efcd30

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