praxis 2.0.pre.5 → 2.0.pre.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +5 -5
  2. data/.rspec +0 -1
  3. data/.ruby-version +1 -0
  4. data/CHANGELOG.md +22 -0
  5. data/Gemfile +1 -1
  6. data/Guardfile +2 -1
  7. data/Rakefile +1 -7
  8. data/TODO.md +28 -0
  9. data/lib/api_browser/package-lock.json +7110 -0
  10. data/lib/praxis.rb +6 -4
  11. data/lib/praxis/action_definition.rb +9 -16
  12. data/lib/praxis/application.rb +1 -2
  13. data/lib/praxis/bootloader_stages/routing.rb +2 -4
  14. data/lib/praxis/extensions/attribute_filtering.rb +2 -0
  15. data/lib/praxis/extensions/attribute_filtering/active_record_filter_query_builder.rb +148 -157
  16. data/lib/praxis/extensions/attribute_filtering/active_record_patches.rb +15 -0
  17. data/lib/praxis/extensions/attribute_filtering/active_record_patches/5x.rb +90 -0
  18. data/lib/praxis/extensions/attribute_filtering/active_record_patches/6_0.rb +68 -0
  19. data/lib/praxis/extensions/attribute_filtering/active_record_patches/6_1_plus.rb +58 -0
  20. data/lib/praxis/extensions/attribute_filtering/filter_tree_node.rb +35 -0
  21. data/lib/praxis/extensions/attribute_filtering/filtering_params.rb +9 -12
  22. data/lib/praxis/extensions/attribute_filtering/sequel_filter_query_builder.rb +3 -2
  23. data/lib/praxis/extensions/field_selection/active_record_query_selector.rb +7 -9
  24. data/lib/praxis/extensions/field_selection/sequel_query_selector.rb +6 -9
  25. data/lib/praxis/extensions/pagination.rb +130 -0
  26. data/lib/praxis/extensions/pagination/active_record_pagination_handler.rb +42 -0
  27. data/lib/praxis/extensions/pagination/header_generator.rb +70 -0
  28. data/lib/praxis/extensions/pagination/ordering_params.rb +234 -0
  29. data/lib/praxis/extensions/pagination/pagination_handler.rb +68 -0
  30. data/lib/praxis/extensions/pagination/pagination_params.rb +374 -0
  31. data/lib/praxis/extensions/pagination/sequel_pagination_handler.rb +45 -0
  32. data/lib/praxis/handlers/json.rb +2 -0
  33. data/lib/praxis/handlers/www_form.rb +5 -0
  34. data/lib/praxis/handlers/{xml.rb → xml-sample.rb} +6 -0
  35. data/lib/praxis/mapper/active_model_compat.rb +23 -5
  36. data/lib/praxis/mapper/resource.rb +16 -9
  37. data/lib/praxis/mapper/sequel_compat.rb +1 -0
  38. data/lib/praxis/media_type.rb +1 -56
  39. data/lib/praxis/plugins/mapper_plugin.rb +1 -1
  40. data/lib/praxis/plugins/pagination_plugin.rb +71 -0
  41. data/lib/praxis/resource_definition.rb +4 -12
  42. data/lib/praxis/route.rb +2 -4
  43. data/lib/praxis/routing_config.rb +4 -8
  44. data/lib/praxis/tasks/routes.rb +9 -14
  45. data/lib/praxis/validation_handler.rb +1 -2
  46. data/lib/praxis/version.rb +1 -1
  47. data/praxis.gemspec +2 -3
  48. data/spec/functional_spec.rb +9 -6
  49. data/spec/praxis/action_definition_spec.rb +4 -16
  50. data/spec/praxis/api_general_info_spec.rb +6 -6
  51. data/spec/praxis/extensions/attribute_filtering/active_record_filter_query_builder_spec.rb +304 -0
  52. data/spec/praxis/extensions/attribute_filtering/filter_tree_node_spec.rb +39 -0
  53. data/spec/praxis/extensions/attribute_filtering/filtering_params_spec.rb +34 -0
  54. data/spec/praxis/extensions/field_expansion_spec.rb +6 -24
  55. data/spec/praxis/extensions/field_selection/active_record_query_selector_spec.rb +15 -11
  56. data/spec/praxis/extensions/field_selection/sequel_query_selector_spec.rb +4 -3
  57. data/spec/praxis/extensions/pagination/active_record_pagination_handler_spec.rb +130 -0
  58. data/spec/praxis/extensions/{field_selection/support → support}/spec_resources_active_model.rb +45 -2
  59. data/spec/praxis/extensions/{field_selection/support → support}/spec_resources_sequel.rb +0 -0
  60. data/spec/praxis/media_type_spec.rb +5 -129
  61. data/spec/praxis/request_spec.rb +3 -22
  62. data/spec/praxis/resource_definition_spec.rb +1 -1
  63. data/spec/praxis/response_definition_spec.rb +1 -5
  64. data/spec/praxis/route_spec.rb +2 -9
  65. data/spec/praxis/routing_config_spec.rb +4 -13
  66. data/spec/praxis/types/multipart_array_spec.rb +4 -21
  67. data/spec/spec_app/config/environment.rb +0 -2
  68. data/spec/spec_app/design/api.rb +1 -1
  69. data/spec/spec_app/design/media_types/instance.rb +0 -8
  70. data/spec/spec_app/design/media_types/volume.rb +0 -12
  71. data/spec/spec_app/design/resources/instances.rb +1 -2
  72. data/spec/spec_helper.rb +6 -0
  73. data/spec/support/spec_media_types.rb +0 -73
  74. metadata +35 -45
  75. data/spec/praxis/handlers/xml_spec.rb +0 -177
  76. data/spec/praxis/links_spec.rb +0 -68
@@ -9,12 +9,6 @@ class Volume < Praxis::MediaType
9
9
 
10
10
  attribute :snapshots, Praxis::Collection.of(VolumeSnapshot)
11
11
  attribute :snapshots_summary, VolumeSnapshot::CollectionSummary
12
-
13
- links do
14
- link :source
15
- link :snapshots, VolumeSnapshot::CollectionSummary, using: :snapshots_summary
16
- end
17
-
18
12
  end
19
13
 
20
14
  view :default do
@@ -22,12 +16,6 @@ class Volume < Praxis::MediaType
22
16
  attribute :name
23
17
  attribute :source
24
18
  attribute :snapshots
25
-
26
- attribute :links
27
- end
28
-
29
- view :link do
30
- attribute :id
31
19
  end
32
20
 
33
21
  class Collection < Praxis::Collection
@@ -44,7 +44,6 @@ module ApiResources
44
44
  action :show do
45
45
  routing do
46
46
  get '/:id'
47
- get '/something/:id', name: :alternate
48
47
  end
49
48
 
50
49
  response :ok, media_type: 'application/json'
@@ -144,7 +143,7 @@ module ApiResources
144
143
  attribute :id
145
144
  end
146
145
 
147
- payload do
146
+ payload required: false do
148
147
  attribute :when, DateTime
149
148
  end
150
149
 
@@ -7,6 +7,12 @@ $:.unshift File.expand_path('support',__dir__)
7
7
 
8
8
  require 'bundler'
9
9
  Bundler.setup :default, :test
10
+
11
+ RSpec.configure do |config|
12
+ config.filter_run focus: true
13
+ config.run_all_when_everything_filtered = true
14
+ end
15
+
10
16
  require 'simplecov'
11
17
  SimpleCov.start 'praxis'
12
18
 
@@ -6,22 +6,13 @@ class Person < Praxis::MediaType
6
6
  attribute :id, Integer
7
7
  attribute :name, String, example: /[:name:]/
8
8
  attribute :href, String, example: proc { |person| "/people/#{person.id}" }
9
- attribute :links, Attributor::Collection.of(String),
10
- description: 'Here to ensure an explicit links attribute works'
11
-
12
9
  end
13
10
 
14
11
  view :default do
15
12
  attribute :id
16
13
  attribute :name
17
- attribute :links
18
14
  end
19
15
 
20
- view :link do
21
- attribute :id
22
- attribute :name
23
- attribute :href
24
- end
25
16
 
26
17
  class CollectionSummary < Praxis::MediaType
27
18
  attributes do
@@ -29,11 +20,6 @@ class Person < Praxis::MediaType
29
20
  attribute :size, Integer
30
21
  end
31
22
 
32
- view :link do
33
- attribute :href
34
- attribute :size
35
- end
36
-
37
23
  view :default do
38
24
  attribute :href
39
25
  end
@@ -59,14 +45,6 @@ class Address < Praxis::MediaType
59
45
  attribute :residents_summary, Person::CollectionSummary
60
46
 
61
47
  attribute :fields, Praxis::Types::FieldSelector.for(Person)
62
-
63
- links do
64
- link :owner
65
- link :super, Person, using: :manager
66
- link :caretaker, using: :custodian
67
- link :residents, using: :residents_summary
68
- end
69
-
70
48
  end
71
49
 
72
50
  view :default do
@@ -74,15 +52,7 @@ class Address < Praxis::MediaType
74
52
  attribute :name
75
53
  attribute :owner
76
54
  attribute :fields
77
-
78
- attribute :links
79
- end
80
-
81
- view :link do
82
- attribute :id
83
- attribute :name
84
55
  end
85
-
86
56
  end
87
57
 
88
58
 
@@ -123,10 +93,6 @@ class Blog < Praxis::MediaType
123
93
  example: proc { |blog,ctx| Post::CollectionSummary.example(ctx, href: "#{blog.href}/posts") },
124
94
  description: "Summary of information from related Post resources"
125
95
 
126
- links do
127
- link :posts, using: :posts_summary
128
- link :owner
129
- end
130
96
  end
131
97
 
132
98
  view :default do
@@ -138,7 +104,6 @@ class Blog < Praxis::MediaType
138
104
  attribute :timestamps
139
105
 
140
106
  attribute :owner
141
- attribute :links
142
107
  end
143
108
 
144
109
  view :overview do
@@ -146,11 +111,6 @@ class Blog < Praxis::MediaType
146
111
  attribute :name
147
112
  attribute :description
148
113
  end
149
-
150
- view :link do
151
- attribute :href
152
- end
153
-
154
114
  end
155
115
 
156
116
 
@@ -185,11 +145,6 @@ class Post < Praxis::MediaType
185
145
  attribute :created_at, DateTime
186
146
  attribute :updated_at, DateTime
187
147
  end
188
-
189
- links do
190
- link :author
191
- link :blog
192
- end
193
148
  end
194
149
 
195
150
  view :default do
@@ -202,23 +157,13 @@ class Post < Praxis::MediaType
202
157
  attribute :author
203
158
 
204
159
  attribute :timestamps
205
- attribute :links
206
- end
207
-
208
- view :link do
209
- attribute :href
210
160
  end
211
161
 
212
-
213
162
  class CollectionSummary < Praxis::MediaType
214
163
  attributes do
215
164
  attribute :href, String
216
165
  attribute :count, Integer
217
166
  end
218
-
219
- view :link do
220
- attribute :href
221
- end
222
167
  end
223
168
  end
224
169
 
@@ -251,12 +196,6 @@ class User < Praxis::MediaType
251
196
 
252
197
  attribute :posts_summary, Post::CollectionSummary,
253
198
  example: proc { |user,ctx| Post::CollectionSummary.example(ctx, href: "#{user.href}/posts") }
254
-
255
- links do
256
- link :posts, using: :posts_summary
257
- link :primary_blog
258
- end
259
-
260
199
  end
261
200
 
262
201
  view :default do
@@ -265,8 +204,6 @@ class User < Praxis::MediaType
265
204
 
266
205
  attribute :first
267
206
  attribute :last
268
-
269
- attribute :links
270
207
  end
271
208
 
272
209
  view :extended do
@@ -276,20 +213,10 @@ class User < Praxis::MediaType
276
213
  attribute :first
277
214
  attribute :last
278
215
  attribute :primary_blog, view: :overview
279
-
280
- attribute :links
281
216
  end
282
217
 
283
218
  view :with_post_links do
284
219
  attribute :id
285
220
  attribute :posts, view: :link
286
221
  end
287
-
288
- view :link do
289
- attribute :href
290
- end
291
-
292
- view :summary do
293
- attribute :links
294
- end
295
222
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: praxis
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.pre.5
4
+ version: 2.0.pre.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josep M. Blanquer
8
8
  - Dane Jensen
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-08-21 00:00:00.000000000 Z
12
+ date: 2020-10-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
@@ -147,30 +147,16 @@ dependencies:
147
147
  name: rake
148
148
  requirement: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - "~>"
151
- - !ruby/object:Gem::Version
152
- version: '0.9'
153
- type: :development
154
- prerelease: false
155
- version_requirements: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - "~>"
158
- - !ruby/object:Gem::Version
159
- version: '0.9'
160
- - !ruby/object:Gem::Dependency
161
- name: rake-notes
162
- requirement: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - "~>"
150
+ - - ">="
165
151
  - !ruby/object:Gem::Version
166
- version: '0'
152
+ version: 12.3.3
167
153
  type: :development
168
154
  prerelease: false
169
155
  version_requirements: !ruby/object:Gem::Requirement
170
156
  requirements:
171
- - - "~>"
157
+ - - ">="
172
158
  - !ruby/object:Gem::Version
173
- version: '0'
159
+ version: 12.3.3
174
160
  - !ruby/object:Gem::Dependency
175
161
  name: pry
176
162
  requirement: !ruby/object:Gem::Requirement
@@ -353,20 +339,6 @@ dependencies:
353
339
  - - "~>"
354
340
  - !ruby/object:Gem::Version
355
341
  version: '2'
356
- - !ruby/object:Gem::Dependency
357
- name: yard
358
- requirement: !ruby/object:Gem::Requirement
359
- requirements:
360
- - - ">="
361
- - !ruby/object:Gem::Version
362
- version: 0.9.20
363
- type: :development
364
- prerelease: false
365
- version_requirements: !ruby/object:Gem::Requirement
366
- requirements:
367
- - - ">="
368
- - !ruby/object:Gem::Version
369
- version: 0.9.20
370
342
  - !ruby/object:Gem::Dependency
371
343
  name: coveralls
372
344
  requirement: !ruby/object:Gem::Requirement
@@ -409,7 +381,7 @@ dependencies:
409
381
  - - ">"
410
382
  - !ruby/object:Gem::Version
411
383
  version: '4'
412
- description:
384
+ description:
413
385
  email:
414
386
  - blanquer@gmail.com
415
387
  - dane.jensen@gmail.com
@@ -420,6 +392,7 @@ extra_rdoc_files: []
420
392
  files:
421
393
  - ".gitignore"
422
394
  - ".rspec"
395
+ - ".ruby-version"
423
396
  - ".simplecov"
424
397
  - ".travis.yml"
425
398
  - CHANGELOG.md
@@ -431,6 +404,7 @@ files:
431
404
  - MAINTAINERS.md
432
405
  - README.md
433
406
  - Rakefile
407
+ - TODO.md
434
408
  - bin/praxis
435
409
  - lib/api_browser/.bowerrc
436
410
  - lib/api_browser/.editorconfig
@@ -516,6 +490,7 @@ files:
516
490
  - lib/api_browser/app/views/types/standalone/default.html
517
491
  - lib/api_browser/app/views/types/standalone/struct.html
518
492
  - lib/api_browser/bower_template.json
493
+ - lib/api_browser/package-lock.json
519
494
  - lib/api_browser/package.json
520
495
  - lib/praxis.rb
521
496
  - lib/praxis/action_definition.rb
@@ -562,7 +537,13 @@ files:
562
537
  - lib/praxis/exceptions/invalid_trait.rb
563
538
  - lib/praxis/exceptions/stage_not_found.rb
564
539
  - lib/praxis/exceptions/validation.rb
540
+ - lib/praxis/extensions/attribute_filtering.rb
565
541
  - lib/praxis/extensions/attribute_filtering/active_record_filter_query_builder.rb
542
+ - lib/praxis/extensions/attribute_filtering/active_record_patches.rb
543
+ - lib/praxis/extensions/attribute_filtering/active_record_patches/5x.rb
544
+ - lib/praxis/extensions/attribute_filtering/active_record_patches/6_0.rb
545
+ - lib/praxis/extensions/attribute_filtering/active_record_patches/6_1_plus.rb
546
+ - lib/praxis/extensions/attribute_filtering/filter_tree_node.rb
566
547
  - lib/praxis/extensions/attribute_filtering/filtering_params.rb
567
548
  - lib/praxis/extensions/attribute_filtering/sequel_filter_query_builder.rb
568
549
  - lib/praxis/extensions/field_expansion.rb
@@ -570,6 +551,13 @@ files:
570
551
  - lib/praxis/extensions/field_selection/active_record_query_selector.rb
571
552
  - lib/praxis/extensions/field_selection/field_selector.rb
572
553
  - lib/praxis/extensions/field_selection/sequel_query_selector.rb
554
+ - lib/praxis/extensions/pagination.rb
555
+ - lib/praxis/extensions/pagination/active_record_pagination_handler.rb
556
+ - lib/praxis/extensions/pagination/header_generator.rb
557
+ - lib/praxis/extensions/pagination/ordering_params.rb
558
+ - lib/praxis/extensions/pagination/pagination_handler.rb
559
+ - lib/praxis/extensions/pagination/pagination_params.rb
560
+ - lib/praxis/extensions/pagination/sequel_pagination_handler.rb
573
561
  - lib/praxis/extensions/rails_compat.rb
574
562
  - lib/praxis/extensions/rails_compat/request_methods.rb
575
563
  - lib/praxis/extensions/rendering.rb
@@ -577,7 +565,7 @@ files:
577
565
  - lib/praxis/handlers/json.rb
578
566
  - lib/praxis/handlers/plain.rb
579
567
  - lib/praxis/handlers/www_form.rb
580
- - lib/praxis/handlers/xml.rb
568
+ - lib/praxis/handlers/xml-sample.rb
581
569
  - lib/praxis/links.rb
582
570
  - lib/praxis/mapper/active_model_compat.rb
583
571
  - lib/praxis/mapper/resource.rb
@@ -592,6 +580,7 @@ files:
592
580
  - lib/praxis/plugin.rb
593
581
  - lib/praxis/plugin_concern.rb
594
582
  - lib/praxis/plugins/mapper_plugin.rb
583
+ - lib/praxis/plugins/pagination_plugin.rb
595
584
  - lib/praxis/plugins/rails_plugin.rb
596
585
  - lib/praxis/request.rb
597
586
  - lib/praxis/request_stages/action.rb
@@ -649,17 +638,19 @@ files:
649
638
  - spec/praxis/config_spec.rb
650
639
  - spec/praxis/controller_spec.rb
651
640
  - spec/praxis/dispatcher_spec.rb
641
+ - spec/praxis/extensions/attribute_filtering/active_record_filter_query_builder_spec.rb
642
+ - spec/praxis/extensions/attribute_filtering/filter_tree_node_spec.rb
643
+ - spec/praxis/extensions/attribute_filtering/filtering_params_spec.rb
652
644
  - spec/praxis/extensions/field_expansion_spec.rb
653
645
  - spec/praxis/extensions/field_selection/active_record_query_selector_spec.rb
654
646
  - spec/praxis/extensions/field_selection/field_selector_spec.rb
655
647
  - spec/praxis/extensions/field_selection/sequel_query_selector_spec.rb
656
- - spec/praxis/extensions/field_selection/support/spec_resources_active_model.rb
657
- - spec/praxis/extensions/field_selection/support/spec_resources_sequel.rb
648
+ - spec/praxis/extensions/pagination/active_record_pagination_handler_spec.rb
658
649
  - spec/praxis/extensions/rendering_spec.rb
650
+ - spec/praxis/extensions/support/spec_resources_active_model.rb
651
+ - spec/praxis/extensions/support/spec_resources_sequel.rb
659
652
  - spec/praxis/file_group_spec.rb
660
653
  - spec/praxis/handlers/json_spec.rb
661
- - spec/praxis/handlers/xml_spec.rb
662
- - spec/praxis/links_spec.rb
663
654
  - spec/praxis/mapper/resource_spec.rb
664
655
  - spec/praxis/mapper/selector_generator_spec.rb
665
656
  - spec/praxis/media_type_identifier_spec.rb
@@ -752,7 +743,7 @@ homepage: https://github.com/praxis/praxis
752
743
  licenses:
753
744
  - MIT
754
745
  metadata: {}
755
- post_install_message:
746
+ post_install_message:
756
747
  rdoc_options: []
757
748
  require_paths:
758
749
  - lib
@@ -767,9 +758,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
767
758
  - !ruby/object:Gem::Version
768
759
  version: 1.3.1
769
760
  requirements: []
770
- rubyforge_project:
771
- rubygems_version: 2.6.14
772
- signing_key:
761
+ rubygems_version: 3.0.3
762
+ signing_key:
773
763
  specification_version: 4
774
764
  summary: Building APIs the way you want it.
775
765
  test_files: []
@@ -1,177 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Praxis::Handlers::XML do
4
-
5
- describe '#parse' do
6
- shared_examples 'xml something' do
7
- it 'works' do
8
- expect(subject.parse(parsed.to_xml)).to eq(parsed)
9
- end
10
- end
11
-
12
- # XML_TYPE_NAMES = {
13
- # "Symbol" => "symbol",
14
- # "Fixnum" => "integer",
15
- # "Bignum" => "integer",
16
- # "BigDecimal" => "decimal",
17
- # "Float" => "float",
18
- # "TrueClass" => "boolean",
19
- # "FalseClass" => "boolean",
20
- # "Date" => "date",
21
- # "DateTime" => "dateTime",
22
- # "Time" => "dateTime"
23
- # }
24
-
25
- context "Parsing symbols" do
26
- let(:xml){ '<objects type="array"><object type="symbol">a_symbol</object></objects>' }
27
- let(:parsed){ [:a_symbol] }
28
- it_behaves_like 'xml something'
29
- end
30
-
31
- context "Parsing integers" do
32
- let(:xml){ '<objects type="array"><object type="integer">1234</object></objects>' }
33
- let(:parsed){ [1234] }
34
- it_behaves_like 'xml something'
35
- end
36
-
37
- context "Parsing decimals" do
38
- let(:xml){ '<objects type="array"><object type="decimal">0.1</object></objects>' }
39
- let(:parsed){ [0.1] }
40
- it_behaves_like 'xml something'
41
- end
42
-
43
- context "Parsing floats" do
44
- let(:xml){ '<objects type="array"><object type="float">0.1</object></objects>' }
45
- let(:parsed){ [0.1] }
46
- it_behaves_like 'xml something'
47
- end
48
-
49
- context "Parsing booleans" do
50
- context "that are true" do
51
- let(:xml){ '<objects type="array"><object type="boolean">true</object></objects>' }
52
- let(:parsed){ [true] }
53
- it_behaves_like 'xml something'
54
- end
55
- context "that are false" do
56
- let(:xml){ '<objects type="array"><object type="boolean">false</object></objects>' }
57
- let(:parsed){ [false] }
58
- it_behaves_like 'xml something'
59
-
60
- end
61
- end
62
-
63
- context "Parsing dates" do
64
- let(:xml){ '<objects type="array"><object type="date">2001-01-01</object></objects>' }
65
- let(:parsed){ [Date.parse("2001-01-01")] }
66
- it_behaves_like 'xml something'
67
- end
68
-
69
- context "Parsing dateTimes" do
70
- let(:xml){ '<objects type="array"><object type="dateTime">2015-03-13T19:34:40-07:00</object></objects>' }
71
- let(:parsed){ [DateTime.parse("2015-03-13T19:34:40-07:00")] }
72
- it_behaves_like 'xml something'
73
- end
74
-
75
- context "Parsing hashes" do
76
- context "that are empty" do
77
- let(:xml){ "<hash></hash>" }
78
-
79
- it 'get converted to empty strings' do
80
- expect(subject.parse(xml)).to eq('')
81
- end
82
- end
83
-
84
- context "with a couple of elements" do
85
- let(:xml){ '<hash><one type="integer">1</one><two type="integer">2</two></hash>' }
86
- let(:parsed){ {"one"=>1, "two"=>2} }
87
- it_behaves_like 'xml something'
88
- end
89
- context "with hyphenated elements" do
90
- let(:xml){ '<hash><part-one type="integer">1</part-one><part-two type="integer">2</part-two></hash>' }
91
- let(:parsed){ {"part_one"=>1, "part_two"=>2} }
92
- it_behaves_like 'xml something'
93
- end
94
- context "with a nested hash" do
95
- let(:xml){ '<hash><one type="integer">1</one><sub_hash><first>hello</first></sub_hash></hash>' }
96
- let(:parsed){ {"one"=>1, "sub_hash"=>{"first"=>"hello"} } }
97
- it_behaves_like 'xml something'
98
- end
99
- context "with a nested array" do
100
- let(:xml){ '<hash><one type="integer">1</one><two type="array"><object>just text</object></two></hash>' }
101
- let(:parsed){ {"one"=>1, "two" => ["just text"] } }
102
- it_behaves_like 'xml something'
103
- end
104
-
105
- end
106
-
107
- context "Parsing an Array" do
108
- context 'with a couple of simple elements in it' do
109
- let(:xml){ '<objects type="array"><object>just text</object><object type="integer">1</object></objects>' }
110
- let(:parsed){ ["just text", 1] }
111
- it_behaves_like 'xml something'
112
- end
113
- context "with a nested hash" do
114
- let(:xml){ '<objects type="array"><object>just text</object><object><one type="integer">1</one></object></objects>' }
115
- let(:parsed){ ["just text", { "one" => 1}] }
116
- it_behaves_like 'xml something'
117
- end
118
- end
119
-
120
- context "Parsing XML strings created with .to_xml" do
121
- let(:xml){ parsed.to_xml }
122
- context 'array with a couple of simple elements in it' do
123
- let(:parsed){ ["just text", 1] }
124
- it_behaves_like 'xml something'
125
- end
126
- context 'a hash with a couple of simple elements in it' do
127
- let(:parsed){ { "one"=>"just text", "two"=> 1 } }
128
- it_behaves_like 'xml something'
129
- end
130
- context 'a array with elements of all types' do
131
- let(:parsed){ ["just text",:a,1,BigDecimal(100),0.1,true,Date.new] }
132
- it_behaves_like 'xml something'
133
- end
134
- context 'a hash with a complex substructure' do
135
- let(:parsed) do
136
- Hash(
137
- "text" => "just text",
138
- "symbol" => :a,
139
- "num" => 1,
140
- "bd" => BigDecimal(100),
141
- "float" => 0.1,
142
- "truthyness" => true,
143
- "day" => Date.new,
144
- "empty_string" => ""
145
- )
146
- end
147
- it_behaves_like 'xml something'
148
- end
149
-
150
- context "transformed characters when using .to_xml" do
151
- context 'underscores become dashes' do
152
- let(:xml){ {"one_thing"=>1, "two_things"=>2}.to_xml }
153
- it do
154
- doc = Nokogiri::XML(xml)
155
-
156
- expect(doc.search('one-thing')).to_not be_empty
157
- expect(doc.search('two-things')).to_not be_empty
158
- end
159
- end
160
- context 'spaces become dashes' do
161
- let(:xml){ {"one thing"=>1, "two things"=>2}.to_xml }
162
- let(:parsed){ {"one-thing"=>1, "two-things"=>2} }
163
- it do
164
- doc = Nokogiri::XML(xml)
165
-
166
- expect(doc.search('one-thing')).to_not be_empty
167
- expect(doc.search('two-things')).to_not be_empty
168
- end
169
- end
170
- end
171
- end
172
-
173
- describe '#generate' do
174
- it 'has tests'
175
- end
176
- end
177
- end