representable 2.4.0.rc3 → 2.4.0.rc4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +7 -2
  3. data/Rakefile +6 -0
  4. data/lib/representable.rb +21 -17
  5. data/lib/representable/binding.rb +3 -2
  6. data/lib/representable/definition.rb +1 -1
  7. data/lib/representable/deprecations.rb +31 -5
  8. data/lib/representable/deserializer.rb +24 -34
  9. data/lib/representable/hash/collection.rb +9 -2
  10. data/lib/representable/hash_methods.rb +2 -2
  11. data/lib/representable/parse_strategies.rb +6 -7
  12. data/lib/representable/pipeline.rb +12 -1
  13. data/lib/representable/pipeline_factories.rb +9 -2
  14. data/lib/representable/serializer.rb +3 -3
  15. data/lib/representable/version.rb +1 -1
  16. data/test-with-deprecations/as_test.rb +65 -0
  17. data/test-with-deprecations/benchmarking.rb +83 -0
  18. data/test-with-deprecations/binding_test.rb +46 -0
  19. data/test-with-deprecations/blaaaaaaaa_test.rb +69 -0
  20. data/test-with-deprecations/cached_test.rb +147 -0
  21. data/test-with-deprecations/class_test.rb +119 -0
  22. data/test-with-deprecations/coercion_test.rb +52 -0
  23. data/test-with-deprecations/config/inherit_test.rb +135 -0
  24. data/test-with-deprecations/config_test.rb +122 -0
  25. data/test-with-deprecations/decorator_scope_test.rb +28 -0
  26. data/test-with-deprecations/decorator_test.rb +96 -0
  27. data/test-with-deprecations/default_test.rb +34 -0
  28. data/test-with-deprecations/defaults_options_test.rb +93 -0
  29. data/test-with-deprecations/definition_test.rb +264 -0
  30. data/test-with-deprecations/example.rb +310 -0
  31. data/test-with-deprecations/examples/object.rb +31 -0
  32. data/test-with-deprecations/exec_context_test.rb +93 -0
  33. data/test-with-deprecations/features_test.rb +70 -0
  34. data/test-with-deprecations/filter_test.rb +57 -0
  35. data/test-with-deprecations/for_collection_test.rb +74 -0
  36. data/test-with-deprecations/generic_test.rb +116 -0
  37. data/test-with-deprecations/getter_setter_test.rb +21 -0
  38. data/test-with-deprecations/hash_bindings_test.rb +87 -0
  39. data/test-with-deprecations/hash_test.rb +160 -0
  40. data/test-with-deprecations/heritage_test.rb +62 -0
  41. data/test-with-deprecations/if_test.rb +79 -0
  42. data/test-with-deprecations/include_exclude_test.rb +88 -0
  43. data/test-with-deprecations/inherit_test.rb +159 -0
  44. data/test-with-deprecations/inline_test.rb +272 -0
  45. data/test-with-deprecations/instance_test.rb +266 -0
  46. data/test-with-deprecations/is_representable_test.rb +77 -0
  47. data/test-with-deprecations/json_test.rb +355 -0
  48. data/test-with-deprecations/lonely_test.rb +239 -0
  49. data/test-with-deprecations/mongoid_test.rb +31 -0
  50. data/test-with-deprecations/nested_test.rb +115 -0
  51. data/test-with-deprecations/object_test.rb +60 -0
  52. data/{test/---deserialize-pipeline_test.rb → test-with-deprecations/parse_pipeline_test.rb} +29 -2
  53. data/test-with-deprecations/parse_strategy_test.rb +279 -0
  54. data/{test → test-with-deprecations}/pass_options_test.rb +0 -0
  55. data/test-with-deprecations/pipeline_test.rb +277 -0
  56. data/test-with-deprecations/populator_test.rb +105 -0
  57. data/test-with-deprecations/prepare_test.rb +67 -0
  58. data/test-with-deprecations/private_options_test.rb +18 -0
  59. data/test-with-deprecations/reader_writer_test.rb +19 -0
  60. data/test-with-deprecations/realistic_benchmark.rb +115 -0
  61. data/test-with-deprecations/render_nil_test.rb +21 -0
  62. data/test-with-deprecations/represent_test.rb +88 -0
  63. data/test-with-deprecations/representable_test.rb +511 -0
  64. data/test-with-deprecations/schema_test.rb +148 -0
  65. data/test-with-deprecations/serialize_deserialize_test.rb +33 -0
  66. data/test-with-deprecations/skip_test.rb +81 -0
  67. data/test-with-deprecations/stringify_hash_test.rb +41 -0
  68. data/test-with-deprecations/test_helper.rb +135 -0
  69. data/test-with-deprecations/test_helper_test.rb +25 -0
  70. data/test-with-deprecations/uncategorized_test.rb +67 -0
  71. data/test-with-deprecations/user_options_test.rb +15 -0
  72. data/test-with-deprecations/wrap_test.rb +152 -0
  73. data/test-with-deprecations/xml_bindings_test.rb +62 -0
  74. data/test-with-deprecations/xml_test.rb +503 -0
  75. data/test-with-deprecations/yaml_test.rb +162 -0
  76. data/test/as_test.rb +3 -3
  77. data/test/cached_test.rb +2 -2
  78. data/test/class_test.rb +5 -5
  79. data/test/exec_context_test.rb +2 -2
  80. data/test/filter_test.rb +1 -1
  81. data/test/getter_setter_test.rb +4 -4
  82. data/test/if_test.rb +2 -2
  83. data/test/include_exclude_test.rb +88 -0
  84. data/test/instance_test.rb +15 -15
  85. data/test/lonely_test.rb +18 -2
  86. data/test/object_test.rb +4 -4
  87. data/test/parse_pipeline_test.rb +64 -0
  88. data/test/parse_strategy_test.rb +3 -3
  89. data/test/pipeline_test.rb +8 -12
  90. data/test/prepare_test.rb +2 -3
  91. data/test/reader_writer_test.rb +3 -3
  92. data/test/representable_test.rb +12 -48
  93. data/test/serialize_deserialize_test.rb +9 -9
  94. data/test/skip_test.rb +11 -11
  95. data/test/test_helper.rb +2 -0
  96. data/test/uncategorized_test.rb +10 -10
  97. data/test/user_options_test.rb +15 -0
  98. data/test/wrap_test.rb +1 -1
  99. metadata +65 -4
@@ -0,0 +1,162 @@
1
+ require 'test_helper'
2
+
3
+ class YamlTest < MiniTest::Spec
4
+ def self.yaml_representer(&block)
5
+ Module.new do
6
+ include Representable::YAML
7
+ instance_exec &block
8
+ end
9
+ end
10
+
11
+ def yaml_representer(&block)
12
+ self.class.yaml_representer(&block)
13
+ end
14
+
15
+
16
+ describe "property" do
17
+ let (:yaml) { yaml_representer do property :best_song end }
18
+
19
+ let (:album) { Album.new.tap do |album|
20
+ album.best_song = "Liar"
21
+ end }
22
+
23
+ describe "#to_yaml" do
24
+ it "renders plain property" do
25
+ album.extend(yaml).to_yaml.must_equal(
26
+ "---
27
+ best_song: Liar
28
+ ")
29
+ end
30
+
31
+ it "always renders values into strings" do
32
+ Album.new.tap { |a| a.best_song = 8675309 }.extend(yaml).to_yaml.must_equal(
33
+ "---
34
+ best_song: 8675309
35
+ "
36
+ )
37
+ end
38
+ end
39
+
40
+
41
+ describe "#from_yaml" do
42
+ it "parses plain property" do
43
+ album.extend(yaml).from_yaml(
44
+ "---
45
+ best_song: This Song Is Recycled
46
+ ").best_song.must_equal "This Song Is Recycled"
47
+ end
48
+ end
49
+
50
+
51
+ describe "with :class and :extend" do
52
+ yaml_song = yaml_representer do property :name end
53
+ let (:yaml_album) { Module.new do
54
+ include Representable::YAML
55
+ property :best_song, :extend => yaml_song, :class => Song
56
+ end }
57
+
58
+ let (:album) { Album.new.tap do |album|
59
+ album.best_song = Song.new("Liar")
60
+ end }
61
+
62
+
63
+ describe "#to_yaml" do
64
+ it "renders embedded typed property" do
65
+ album.extend(yaml_album).to_yaml.must_equal "---
66
+ best_song:
67
+ name: Liar
68
+ "
69
+ end
70
+ end
71
+
72
+ describe "#from_yaml" do
73
+ it "parses embedded typed property" do
74
+ album.extend(yaml_album).from_yaml("---
75
+ best_song:
76
+ name: Go With Me
77
+ ").must_equal Album.new(nil,Song.new("Go With Me"))
78
+ end
79
+ end
80
+ end
81
+ end
82
+
83
+
84
+ describe "collection" do
85
+ let (:yaml) { yaml_representer do collection :songs end }
86
+
87
+ let (:album) { Album.new.tap do |album|
88
+ album.songs = ["Jackhammer", "Terrible Man"]
89
+ end }
90
+
91
+
92
+ describe "#to_yaml" do
93
+ it "renders a block style list per default" do
94
+ album.extend(yaml).to_yaml.must_equal "---
95
+ songs:
96
+ - Jackhammer
97
+ - Terrible Man
98
+ "
99
+ end
100
+
101
+ it "renders a flow style list when :style => :flow set" do
102
+ yaml = yaml_representer { collection :songs, :style => :flow }
103
+ album.extend(yaml).to_yaml.must_equal "---
104
+ songs: [Jackhammer, Terrible Man]
105
+ "
106
+ end
107
+ end
108
+
109
+
110
+ describe "#from_yaml" do
111
+ it "parses a block style list" do
112
+ album.extend(yaml).from_yaml("---
113
+ songs:
114
+ - Off Key Melody
115
+ - Sinking").must_equal Album.new(["Off Key Melody", "Sinking"])
116
+
117
+ end
118
+
119
+ it "parses a flow style list" do
120
+ album.extend(yaml).from_yaml("---
121
+ songs: [Off Key Melody, Sinking]").must_equal Album.new(["Off Key Melody", "Sinking"])
122
+ end
123
+ end
124
+
125
+
126
+ describe "with :class and :extend" do
127
+ let (:yaml_album) { Module.new do
128
+ include Representable::YAML
129
+ collection :songs, :class => Song do
130
+ property :name
131
+ property :track
132
+ end
133
+ end }
134
+
135
+ let (:album) { Album.new([Song.new("Liar", 1), Song.new("What I Know", 2)]) }
136
+
137
+
138
+ describe "#to_yaml" do
139
+ it "renders collection of typed property" do
140
+ album.extend(yaml_album).to_yaml.must_equal "---
141
+ songs:
142
+ - name: Liar
143
+ track: 1
144
+ - name: What I Know
145
+ track: 2
146
+ "
147
+ end
148
+ end
149
+
150
+ describe "#from_yaml" do
151
+ it "parses collection of typed property" do
152
+ album.extend(yaml_album).from_yaml("---
153
+ songs:
154
+ - name: One Shot Deal
155
+ track: 4
156
+ - name: Three Way Dance
157
+ track: 5").must_equal Album.new([Song.new("One Shot Deal", 4), Song.new("Three Way Dance", 5)])
158
+ end
159
+ end
160
+ end
161
+ end
162
+ end
data/test/as_test.rb CHANGED
@@ -33,11 +33,11 @@ class AsTest < MiniTest::Spec
33
33
 
34
34
  describe "lambda arguments" do
35
35
  representer! do
36
- property :name, :as => lambda { |*args| args.inspect }
36
+ property :name, :as => lambda { |options| options[:user_options].inspect }
37
37
  end
38
38
 
39
- it { render(song, :volume => 1).must_equal_document({"[{:volume=>1}]" => "Revolution"}) }
40
- it { parse(song, {"[{:volume=>1}]" => "Wie Es Geht"}, :volume => 1).name.must_equal "Wie Es Geht" }
39
+ it { render(song, user_options:{volume: 1}).must_equal_document({"{:volume=>1}" => "Revolution"}) }
40
+ it { parse(song, {"{:volume=>1}" => "Wie Es Geht"}, user_options: {volume: 1}).name.must_equal "Wie Es Geht" }
41
41
  end
42
42
  end
43
43
  end
data/test/cached_test.rb CHANGED
@@ -14,7 +14,7 @@ class CachedTest < MiniTest::Spec
14
14
  include Representable::Hash
15
15
  feature Representable::Cached
16
16
 
17
- property :title, render_filter: lambda { |input, options| "#{input}:#{options[:user_options]}" }, pass_options: true
17
+ property :title, render_filter: lambda { |input, options| "#{input}:#{options[:options][:user_options]}" }
18
18
  property :composer, class: Model::Artist do
19
19
  property :name
20
20
  end
@@ -41,7 +41,7 @@ class CachedTest < MiniTest::Spec
41
41
  album2 = Model::Album.new("Louder And Even More Dangerous", [song2, song])
42
42
 
43
43
  # makes sure options are passed correctly.
44
- representer.to_hash(volume: 9).must_equal({"name"=>"Live And Dangerous",
44
+ representer.to_hash(user_options: {volume: 9}).must_equal({"name"=>"Live And Dangerous",
45
45
  "songs"=>[{"title"=>"Jailbreak:{:volume=>9}"}, {"title"=>"Southbound:{:volume=>9}"}, {"title"=>"Emerald:{:volume=>9}"}]}) # called in Deserializer/Serializer
46
46
 
47
47
  # representer becomes reusable as it is stateless.
data/test/class_test.rb CHANGED
@@ -5,7 +5,7 @@ class ClassTest < BaseTest
5
5
  class RepresentingSong
6
6
  attr_reader :name
7
7
 
8
- def from_hash(doc, *args)
8
+ def from_hash(doc, *)
9
9
  @name = doc["__name__"]
10
10
 
11
11
  self # DISCUSS: do we wanna be able to return whatever we want here? this is a trick to replace the actual object
@@ -66,10 +66,10 @@ class ClassTest < BaseTest
66
66
 
67
67
  representer!(:inject => :klass) do
68
68
  _klass = klass
69
- property :song, :class => lambda { |fragment, args| _klass.args=([fragment,args]); _klass }
69
+ property :song, :class => lambda { |options| _klass.args=([options[:fragment],options[:user_options]]); _klass }
70
70
  end
71
71
 
72
- it { representer.prepare(OpenStruct.new).from_hash({"song" => {"name" => "Captured"}}, :volume => true).song.class.args.
72
+ it { representer.prepare(OpenStruct.new).from_hash({"song" => {"name" => "Captured"}}, user_options: {volume: true}).song.class.args.
73
73
  must_equal([{"name"=>"Captured"}, {:volume=>true}]) }
74
74
  end
75
75
 
@@ -87,10 +87,10 @@ class ClassTest < BaseTest
87
87
 
88
88
  representer!(:inject => :klass) do
89
89
  _klass = klass
90
- collection :songs, :class => lambda { |fragment, i, args| _klass.args=([fragment,i,args]); _klass }
90
+ collection :songs, :class => lambda { |options| _klass.args=([options[:fragment],options[:index],options[:user_options]]); _klass }
91
91
  end
92
92
 
93
- it { representer.prepare(OpenStruct.new).from_hash({"songs" => [{"name" => "Captured"}]}, :volume => true).songs.first.class.args.
93
+ it { representer.prepare(OpenStruct.new).from_hash({"songs" => [{"name" => "Captured"}]}, user_options: {volume: true}).songs.first.class.args.
94
94
  must_equal([{"name"=>"Captured"}, 0, {:volume=>true}]) }
95
95
  end
96
96
 
@@ -36,7 +36,7 @@ class ExecContextTest < MiniTest::Spec
36
36
  property :name,
37
37
  :as => lambda { |*| self.class }, # to actually test
38
38
  :exec_context => :binding,
39
- :setter => lambda { |v, *args| represented.name = v # to make parsing work.
39
+ :setter => lambda { |options| represented.name = options[:fragment] # to make parsing work.
40
40
  }
41
41
  end
42
42
 
@@ -81,7 +81,7 @@ class ExecContextTest < MiniTest::Spec
81
81
  property :name,
82
82
  :as => lambda { |*| self.class }, # to actually test
83
83
  :exec_context => :binding,
84
- :setter => lambda { |v, *args| represented.name = v # to make parsing work.
84
+ :setter => lambda { |options| represented.name = options[:fragment ] # to make parsing work.
85
85
  }
86
86
  end
87
87
 
data/test/filter_test.rb CHANGED
@@ -16,7 +16,7 @@ class FilterTest < MiniTest::Spec
16
16
 
17
17
  property :track,
18
18
  :parse_filter => lambda { |input, options| "#{input.downcase},#{options[:doc]}" },
19
- :render_filter => lambda { |val, options| "#{val.upcase},#{options[:doc]},#{options[:user_options]}" }
19
+ :render_filter => lambda { |val, options| "#{val.upcase},#{options[:doc]},#{options[:options][:user_options]}" }
20
20
  end
21
21
 
22
22
  # gets doc and options.
@@ -3,19 +3,19 @@ require 'test_helper'
3
3
  class GetterSetterTest < BaseTest
4
4
  representer! do
5
5
  property :name, # key under :name.
6
- :getter => lambda { |args| "#{args[:welcome]} #{song_name}" },
7
- :setter => lambda { |val, args| self.song_name = "#{args[:welcome]} #{val}" }
6
+ :getter => lambda { |options| "#{options[:user_options][:welcome]} #{song_name}" },
7
+ :setter => lambda { |options| self.song_name = "#{options[:user_options][:welcome]} #{options[:input]}" }
8
8
  end
9
9
 
10
10
  subject { Struct.new(:song_name).new("Mony Mony").extend(representer) }
11
11
 
12
12
  it "uses :getter when rendering" do
13
13
  subject.instance_eval { def name; raise; end }
14
- subject.to_hash(:welcome => "Hi").must_equal({"name" => "Hi Mony Mony"})
14
+ subject.to_hash(user_options: {welcome: "Hi"}).must_equal({"name" => "Hi Mony Mony"})
15
15
  end
16
16
 
17
17
  it "uses :setter when parsing" do
18
18
  subject.instance_eval { def name=(*); raise; end; self }
19
- subject.from_hash({"name" => "Eyes Without A Face"}, :welcome => "Hello").song_name.must_equal "Hello Eyes Without A Face"
19
+ subject.from_hash({"name" => "Eyes Without A Face"}, user_options: {welcome: "Hello"}).song_name.must_equal "Hello Eyes Without A Face"
20
20
  end
21
21
  end
data/test/if_test.rb CHANGED
@@ -64,7 +64,7 @@ class IfTest < MiniTest::Spec
64
64
 
65
65
  describe "propagating user options to the block" do
66
66
  representer! do
67
- property :name, :if => lambda { |opts| opts[:include_name] }
67
+ property :name, :if => lambda { |opts| opts[:user_options][:include_name] }
68
68
  end
69
69
  subject { OpenStruct.new(:name => "Outbound").extend(representer) }
70
70
 
@@ -73,7 +73,7 @@ class IfTest < MiniTest::Spec
73
73
  end
74
74
 
75
75
  it "passes user options to block" do
76
- subject.to_hash(:include_name => true).must_equal({"name" => "Outbound"})
76
+ subject.to_hash(user_options: { include_name: true }).must_equal({"name" => "Outbound"})
77
77
  end
78
78
  end
79
79
  end
@@ -0,0 +1,88 @@
1
+ require "test_helper"
2
+
3
+ class IncludeExcludeTest < Minitest::Spec
4
+ Song = Struct.new(:title, :artist, :id)
5
+ Artist = Struct.new(:name, :id, :songs)
6
+
7
+ representer!(decorator: true) do
8
+ property :title
9
+ property :artist, class: Artist do
10
+ property :name
11
+ property :id
12
+
13
+ collection :songs, class: Song do
14
+ property :title
15
+ property :id
16
+ end
17
+ end
18
+ end
19
+
20
+ let (:song) { Song.new("Listless", Artist.new("7yearsbadluck", 1 )) }
21
+ let (:decorator) { representer.new(song) }
22
+
23
+ describe "#from_hash" do
24
+ it "accepts :exclude option" do
25
+ decorator.from_hash({"title"=>"Don't Smile In Trouble", "artist"=>{"id"=>2}}, exclude: [:title])
26
+
27
+ song.title.must_equal "Listless"
28
+ song.artist.must_equal Artist.new(nil, 2)
29
+ end
30
+
31
+ it "accepts :include option" do
32
+ decorator.from_hash({"title"=>"Don't Smile In Trouble", "artist"=>{"id"=>2}}, include: [:title])
33
+
34
+ song.title.must_equal "Don't Smile In Trouble"
35
+ song.artist.must_equal Artist.new("7yearsbadluck", 1)
36
+ end
37
+
38
+ it "accepts nested :exclude/:include option" do
39
+ decorator.from_hash({"title"=>"Don't Smile In Trouble", "artist"=>{"name"=>"Foo", "id"=>2, "songs"=>[{"id"=>1, "title"=>"Listless"}]}},
40
+ exclude: [:title],
41
+ artist: {
42
+ exclude: [:id],
43
+ songs: { include: [:title] }
44
+ }
45
+ )
46
+
47
+ song.title.must_equal "Listless"
48
+ song.artist.must_equal Artist.new("Foo", nil, [Song.new("Listless", nil, nil)])
49
+ end
50
+ end
51
+
52
+ describe "#to_hash" do
53
+ it "accepts :exclude option" do
54
+ decorator.to_hash(exclude: [:title]).must_equal({"artist"=>{"name"=>"7yearsbadluck", "id"=>1}})
55
+ end
56
+
57
+ it "accepts :include option" do
58
+ decorator.to_hash(include: [:title]).must_equal({"title"=>"Listless"})
59
+ end
60
+
61
+ it "accepts nested :exclude/:include option" do
62
+ decorator = representer.new(Song.new("Listless", Artist.new("7yearsbadluck", 1, [Song.new("C.O.A.B.I.E.T.L.")])))
63
+
64
+ decorator.to_hash(
65
+ exclude: [:title],
66
+ artist: {
67
+ exclude: [:id],
68
+ songs: { include: [:title] }
69
+ }
70
+ ).must_equal({"artist"=>{"name"=>"7yearsbadluck", "songs"=>[{"title"=>"C.O.A.B.I.E.T.L."}]}})
71
+ end
72
+ end
73
+
74
+ it "xdoes not propagate private options to nested objects" do
75
+ Cover = Struct.new(:title, :original)
76
+
77
+ cover_rpr = Module.new do
78
+ include Representable::Hash
79
+ property :title
80
+ property :original, extend: self
81
+ end
82
+
83
+ # FIXME: we should test all representable-options (:include, :exclude, ?)
84
+
85
+ Cover.new("Roxanne", Cover.new("Roxanne (Don't Put On The Red Light)")).extend(cover_rpr).
86
+ to_hash(:include => [:original]).must_equal({"original"=>{"title"=>"Roxanne (Don't Put On The Red Light)"}})
87
+ end
88
+ end
@@ -10,7 +10,7 @@ class InstanceTest < BaseTest
10
10
 
11
11
  describe "lambda { fragment } (new way of class: lambda { nil })" do
12
12
  representer! do
13
- property :title, :instance => lambda { |fragment, args| fragment }
13
+ property :title, :instance => lambda { |options| options[:fragment] }
14
14
  end
15
15
 
16
16
  it "skips creating new instance" do
@@ -21,7 +21,7 @@ class InstanceTest < BaseTest
21
21
  end
22
22
  end
23
23
 
24
- song = OpenStruct.new.extend(representer).from_hash(hash = {"title" => object})
24
+ song = OpenStruct.new.extend(representer).from_hash({"title" => object})
25
25
  song.title.must_equal object
26
26
  end
27
27
  end
@@ -32,7 +32,7 @@ class InstanceTest < BaseTest
32
32
  describe "property with :instance" do
33
33
  representer!(:inject => :song_representer) do
34
34
  property :song,
35
- :instance => lambda { |fragment, *args| fragment["id"] == song.id ? song : Song.find(fragment["id"]) },
35
+ :instance => lambda { |options| options[:fragment]["id"] == song.id ? song : Song.find(options[:fragment]["id"]) },
36
36
  :extend => song_representer
37
37
  end
38
38
 
@@ -47,8 +47,8 @@ class InstanceTest < BaseTest
47
47
  describe "collection with :instance" do
48
48
  representer!(:inject => :song_representer) do
49
49
  collection :songs,
50
- :instance => lambda { |fragment, i, *args|
51
- fragment["id"] == songs[i].id ? songs[i] : Song.find(fragment["id"])
50
+ :instance => lambda { |options|
51
+ options[:fragment]["id"] == songs[options[:index]].id ? songs[options[:index]] : Song.find(options[:fragment]["id"])
52
52
  }, # let's not allow returning nil anymore. make sure we can still do everything as with nil. also, let's remove parse_strategy: sync.
53
53
 
54
54
  :extend => song_representer
@@ -68,11 +68,11 @@ class InstanceTest < BaseTest
68
68
 
69
69
  describe "property with lambda receiving fragment and args" do
70
70
  representer!(:inject => :song_representer) do
71
- property :song, :instance => lambda { |fragment, args| Struct.new(:args, :id).new([fragment, args]) }, :extend => song_representer
71
+ property :song, :instance => lambda { |options| Struct.new(:args, :id).new([options[:fragment], options[:user_options]]) }, :extend => song_representer
72
72
  end
73
73
 
74
74
  it { OpenStruct.new(:song => Song.new(1, "The Answer Is Still No")).extend(representer).
75
- from_hash({"song" => {"id" => 1}}, {:volume => 1}).song.args.must_equal([{"id"=>1}, {:volume=>1}]) }
75
+ from_hash({"song" => {"id" => 1}}, user_options: { volume: 1 }).song.args.must_equal([{"id"=>1}, {:volume=>1}]) }
76
76
  end
77
77
 
78
78
  # TODO: raise and test instance:{nil}
@@ -100,8 +100,8 @@ class InstanceTest < BaseTest
100
100
  describe "sync" do
101
101
  representer!(:inject => :song_representer) do
102
102
  collection :songs,
103
- :instance => lambda { |fragment, i, *args|
104
- songs[i]
103
+ :instance => lambda { |options|
104
+ songs[options[:index]]
105
105
  },
106
106
  :extend => song_representer,
107
107
  # :parse_strategy => :sync
@@ -130,10 +130,10 @@ class InstanceTest < BaseTest
130
130
  describe "update existing elements, only" do
131
131
  representer!(:inject => :song_representer) do
132
132
  collection :songs,
133
- :instance => lambda { |fragment, i, *args|
133
+ :instance => lambda { |options|
134
134
 
135
135
  #fragment["id"] == songs[i].id ? songs[i] : Song.find(fragment["id"])
136
- songs.find { |s| s.id == fragment["id"] }
136
+ songs.find { |s| s.id == options[:fragment]["id"] }
137
137
  }, # let's not allow returning nil anymore. make sure we can still do everything as with nil. also, let's remove parse_strategy: sync.
138
138
 
139
139
  :extend => song_representer,
@@ -164,7 +164,7 @@ class InstanceTest < BaseTest
164
164
  describe "add incoming elements, only" do
165
165
  representer!(:inject => :song_representer) do
166
166
  collection :songs,
167
- :instance => lambda { |fragment, i, *args|
167
+ :instance => lambda { |options|
168
168
  songs << song=Song.new(2)
169
169
  song
170
170
  }, # let's not allow returning nil anymore. make sure we can still do everything as with nil. also, let's remove parse_strategy: sync.
@@ -195,8 +195,8 @@ class InstanceTest < BaseTest
195
195
  describe "replace existing element" do
196
196
  representer!(:inject => :song_representer) do
197
197
  collection :songs,
198
- :instance => lambda { |fragment, i, *args|
199
- id = fragment.delete("replace_id")
198
+ :instance => lambda { |options|
199
+ id = options[:fragment].delete("replace_id")
200
200
  replaced = songs.find { |s| s.id == id }
201
201
  songs[songs.index(replaced)] = song=Song.new(3)
202
202
  song
@@ -249,7 +249,7 @@ class InstanceTest < BaseTest
249
249
  describe "new syntax for instance: true" do
250
250
  representer!(:inject => :song_representer) do
251
251
  property :song, :pass_options => true,
252
- :extend => song_representer, :instance => lambda { |fragment, args| args.binding.get(represented: args.represented) }
252
+ :extend => song_representer, :instance => lambda { |options| options[:binding].get(represented: options[:represented]) }
253
253
  end
254
254
 
255
255
  it "uses Binding#get instead of creating an instance, but deprecates" do