@@ -17,11 +17,12 @@ class ParseStrategySyncTest < BaseTest
1717
1818 representer! ( :module => mod , :name => :song_representer ) do
1919 property :title
20- self . representation_wrap = :song if format == :xml
2120 end
2221
2322 representer! ( :inject => :song_representer , :module => mod ) do
24- property :song , :parse_strategy => :sync , :extend => song_representer
23+ options = { :parse_strategy => :sync , :extend => song_representer }
24+ options [ :as ] = :song if format == :xml
25+ property :song , options
2526 end
2627
2728 let ( :hit ) { hit = OpenStruct . new ( :song => song ) . extend ( representer ) }
@@ -46,19 +47,20 @@ class ParseStrategySyncTest < BaseTest
4647 for_formats (
4748 :hash => [ Representable ::Hash , { "songs" => [ { "title" => "Resist Stance" } ] } , { "songs" => [ { "title" => "Suffer" } ] } ] ,
4849 #:json => [Representable::JSON, "{\"song\":{\"name\":\"Alive\"}}", "{\"song\":{\"name\":\"You've Taken Everything\"}}"],
49- :xml => [ Representable ::XML , "<open_struct><song><title>Resist Stance</title></song></open_struct>" , "<open_struct><songs ><title>Suffer</title></songs ></open_struct>" ] ,
50+ :xml => [ Representable ::XML , "<open_struct><song><title>Resist Stance</title></song></open_struct>" , "<open_struct><song ><title>Suffer</title></song ></open_struct>" ] ,
5051 :yaml => [ Representable ::YAML , "---\n songs:\n - title: Resist Stance\n " , "---\n songs:\n - title: Suffer\n " ] ,
5152 ) do |format , mod , output , input |
5253
5354 describe "[#{ format } ] collection with :parse_strategy: :sync" do # TODO: introduce :representable option?
5455 let ( :format ) { format }
5556 representer! ( :module => mod , :name => :song_representer ) do
5657 property :title
57- self . representation_wrap = :song if format == :xml
5858 end
5959
6060 representer! ( :inject => :song_representer , :module => mod ) do
61- collection :songs , :parse_strategy => :sync , :extend => song_representer
61+ options = { :parse_strategy => :sync , :extend => song_representer }
62+ options [ :as ] = :song if format == :xml
63+ collection :songs , options
6264 end
6365
6466 let ( :album ) { OpenStruct . new ( :songs => [ song ] ) . extend ( representer ) }
@@ -71,12 +73,10 @@ class ParseStrategySyncTest < BaseTest
7173 collection_id = album . songs . object_id
7274 song = album . songs . first
7375 song_id = song . object_id
74-
7576 parse ( album , input )
76-
7777 album . songs . first . title . must_equal "Suffer"
7878 song . title . must_equal "Suffer"
79- # album.songs.object_id.must_equal collection_id # TODO: don't replace!
79+ album . songs . object_id . must_equal collection_id # TODO: don't replace!
8080 song . object_id . must_equal song_id
8181 end
8282 end
0 commit comments