representable 3.3.0 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +10 -0
  3. data/Gemfile +0 -1
  4. data/README.md +1 -7
  5. data/lib/representable/json.rb +11 -14
  6. data/lib/representable/version.rb +1 -1
  7. data/representable.gemspec +1 -2
  8. metadata +3 -65
  9. data/test/as_test.rb +0 -60
  10. data/test/benchmarking.rb +0 -78
  11. data/test/binding_test.rb +0 -54
  12. data/test/cached_test.rb +0 -177
  13. data/test/class_test.rb +0 -132
  14. data/test/coercion_test.rb +0 -73
  15. data/test/config/inherit_test.rb +0 -130
  16. data/test/config_test.rb +0 -120
  17. data/test/decorator_scope_test.rb +0 -30
  18. data/test/decorator_test.rb +0 -109
  19. data/test/default_test.rb +0 -34
  20. data/test/defaults_options_test.rb +0 -121
  21. data/test/definition_test.rb +0 -253
  22. data/test/examples/example.rb +0 -314
  23. data/test/examples/object.rb +0 -28
  24. data/test/exec_context_test.rb +0 -88
  25. data/test/features_test.rb +0 -89
  26. data/test/filter_test.rb +0 -66
  27. data/test/for_collection_test.rb +0 -71
  28. data/test/generic_test.rb +0 -109
  29. data/test/getter_setter_test.rb +0 -26
  30. data/test/hash_bindings_test.rb +0 -96
  31. data/test/hash_test.rb +0 -197
  32. data/test/heritage_test.rb +0 -64
  33. data/test/if_test.rb +0 -83
  34. data/test/include_exclude_test.rb +0 -96
  35. data/test/inherit_test.rb +0 -246
  36. data/test/inline_test.rb +0 -281
  37. data/test/instance_test.rb +0 -289
  38. data/test/is_representable_test.rb +0 -79
  39. data/test/json_test.rb +0 -379
  40. data/test/lonely_test.rb +0 -241
  41. data/test/nested_test.rb +0 -112
  42. data/test/object_test.rb +0 -60
  43. data/test/option_test.rb +0 -38
  44. data/test/parse_pipeline_test.rb +0 -68
  45. data/test/pipeline_test.rb +0 -309
  46. data/test/populator_test.rb +0 -108
  47. data/test/prepare_test.rb +0 -64
  48. data/test/private_options_test.rb +0 -19
  49. data/test/reader_writer_test.rb +0 -19
  50. data/test/realistic_benchmark.rb +0 -96
  51. data/test/render_nil_test.rb +0 -21
  52. data/test/represent_test.rb +0 -84
  53. data/test/representable_test.rb +0 -526
  54. data/test/schema_test.rb +0 -175
  55. data/test/serialize_deserialize_test.rb +0 -33
  56. data/test/skip_test.rb +0 -92
  57. data/test/stringify_hash_test.rb +0 -39
  58. data/test/test_helper.rb +0 -153
  59. data/test/test_helper_test.rb +0 -25
  60. data/test/uncategorized_test.rb +0 -72
  61. data/test/user_options_test.rb +0 -24
  62. data/test/wrap_test.rb +0 -162
  63. data/test/xml_assertions.rb +0 -29
  64. data/test/xml_bindings_test.rb +0 -55
  65. data/test/xml_namespace_test.rb +0 -193
  66. data/test/xml_test.rb +0 -584
  67. data/test/yaml_test.rb +0 -209
data/test/yaml_test.rb DELETED
@@ -1,209 +0,0 @@
1
- require "test_helper"
2
-
3
- class YamlPublicMethodsTest < Minitest::Spec
4
- #---
5
- # from_yaml
6
- class BandRepresenter < Representable::Decorator
7
- include Representable::YAML
8
- property :id
9
- property :name
10
- end
11
-
12
- let(:data) do
13
- %{---
14
- id: 1
15
- name: Rancid
16
- }
17
- end
18
-
19
- it { _(BandRepresenter.new(Band.new).from_yaml(data)[:id, :name]).must_equal [1, "Rancid"] }
20
- it { _(BandRepresenter.new(Band.new).parse(data)[:id, :name]).must_equal [1, "Rancid"] }
21
-
22
- #---
23
- # to_yaml
24
- let(:band) { Band.new("1", "Rancid") }
25
-
26
- it { _(BandRepresenter.new(band).to_yaml).must_equal data }
27
- it { _(BandRepresenter.new(band).render).must_equal data }
28
- end
29
-
30
- class YamlTest < Minitest::Spec
31
- def self.yaml_representer(&block)
32
- Module.new do
33
- include Representable::YAML
34
- instance_exec(&block)
35
- end
36
- end
37
-
38
- def yaml_representer(&block)
39
- self.class.yaml_representer(&block)
40
- end
41
-
42
- describe "property" do
43
- let(:yaml) { yaml_representer { property :best_song } }
44
-
45
- let(:album) do
46
- Album.new.tap do |album|
47
- album.best_song = "Liar"
48
- end
49
- end
50
-
51
- describe "#to_yaml" do
52
- it "renders plain property" do
53
- _(album.extend(yaml).to_yaml).must_equal(
54
- "---
55
- best_song: Liar
56
- "
57
- )
58
- end
59
-
60
- it "always renders values into strings" do
61
- _(Album.new.tap { |a| a.best_song = 8675309 }.extend(yaml).to_yaml).must_equal(
62
- "---
63
- best_song: 8675309
64
- "
65
- )
66
- end
67
- end
68
-
69
- describe "#from_yaml" do
70
- it "parses plain property" do
71
- _(
72
- album.extend(yaml).from_yaml(
73
- "---
74
- best_song: This Song Is Recycled
75
- "
76
- ).best_song
77
- ).must_equal "This Song Is Recycled"
78
- end
79
- end
80
-
81
- describe "with :class and :extend" do
82
- yaml_song = yaml_representer { property :name }
83
- let(:yaml_album) do
84
- Module.new do
85
- include Representable::YAML
86
- property :best_song, :extend => yaml_song, :class => Song
87
- end
88
- end
89
-
90
- let(:album) do
91
- Album.new.tap do |album|
92
- album.best_song = Song.new("Liar")
93
- end
94
- end
95
-
96
- describe "#to_yaml" do
97
- it "renders embedded typed property" do
98
- _(album.extend(yaml_album).to_yaml).must_equal "---
99
- best_song:
100
- name: Liar
101
- "
102
- end
103
- end
104
-
105
- describe "#from_yaml" do
106
- it "parses embedded typed property" do
107
- _(
108
- album.extend(yaml_album).from_yaml(
109
- "---
110
- best_song:
111
- name: Go With Me
112
- "
113
- )
114
- ).must_equal Album.new(nil, Song.new("Go With Me"))
115
- end
116
- end
117
- end
118
- end
119
-
120
- describe "collection" do
121
- let(:yaml) { yaml_representer { collection :songs } }
122
-
123
- let(:album) do
124
- Album.new.tap do |album|
125
- album.songs = ["Jackhammer", "Terrible Man"]
126
- end
127
- end
128
-
129
- describe "#to_yaml" do
130
- it "renders a block style list per default" do
131
- _(album.extend(yaml).to_yaml).must_equal "---
132
- songs:
133
- - Jackhammer
134
- - Terrible Man
135
- "
136
- end
137
-
138
- it "renders a flow style list when :style => :flow set" do
139
- yaml = yaml_representer { collection :songs, :style => :flow }
140
- _(album.extend(yaml).to_yaml).must_equal "---
141
- songs: [Jackhammer, Terrible Man]
142
- "
143
- end
144
- end
145
-
146
- describe "#from_yaml" do
147
- it "parses a block style list" do
148
- _(
149
- album.extend(yaml).from_yaml(
150
- "---
151
- songs:
152
- - Off Key Melody
153
- - Sinking"
154
- )
155
- ).must_equal Album.new(["Off Key Melody", "Sinking"])
156
- end
157
-
158
- it "parses a flow style list" do
159
- _(
160
- album.extend(yaml).from_yaml(
161
- "---
162
- songs: [Off Key Melody, Sinking]"
163
- )
164
- ).must_equal Album.new(["Off Key Melody", "Sinking"])
165
- end
166
- end
167
-
168
- describe "with :class and :extend" do
169
- let(:yaml_album) do
170
- Module.new do
171
- include Representable::YAML
172
- collection :songs, :class => Song do
173
- property :name
174
- property :track
175
- end
176
- end
177
- end
178
-
179
- let(:album) { Album.new([Song.new("Liar", 1), Song.new("What I Know", 2)]) }
180
-
181
- describe "#to_yaml" do
182
- it "renders collection of typed property" do
183
- _(album.extend(yaml_album).to_yaml).must_equal "---
184
- songs:
185
- - name: Liar
186
- track: 1
187
- - name: What I Know
188
- track: 2
189
- "
190
- end
191
- end
192
-
193
- describe "#from_yaml" do
194
- it "parses collection of typed property" do
195
- _(
196
- album.extend(yaml_album).from_yaml(
197
- "---
198
- songs:
199
- - name: One Shot Deal
200
- track: 4
201
- - name: Three Way Dance
202
- track: 5"
203
- )
204
- ).must_equal Album.new([Song.new("One Shot Deal", 4), Song.new("Three Way Dance", 5)])
205
- end
206
- end
207
- end
208
- end
209
- end