nokogiri-happymapper 0.8.1 → 0.9.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 (55) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +7 -0
  3. data/README.md +0 -3
  4. data/lib/happymapper/element.rb +2 -2
  5. data/lib/happymapper/supported_types.rb +3 -5
  6. data/lib/happymapper/version.rb +1 -1
  7. data/lib/happymapper.rb +44 -52
  8. metadata +98 -107
  9. data/spec/features/after_parse_callbacks_spec.rb +0 -32
  10. data/spec/features/attribute_default_value_spec.rb +0 -48
  11. data/spec/features/attributes_spec.rb +0 -35
  12. data/spec/features/has_many_empty_array_spec.rb +0 -44
  13. data/spec/features/ignay_spec.rb +0 -92
  14. data/spec/features/inheritance_spec.rb +0 -121
  15. data/spec/features/mixed_namespaces_spec.rb +0 -60
  16. data/spec/features/parse_with_object_to_update_spec.rb +0 -116
  17. data/spec/features/same_tag_different_meaning_spec.rb +0 -44
  18. data/spec/features/to_xml_spec.rb +0 -205
  19. data/spec/features/to_xml_with_namespaces_spec.rb +0 -237
  20. data/spec/features/wildcard_tag_name_spec.rb +0 -110
  21. data/spec/features/wrap_spec.rb +0 -87
  22. data/spec/features/xpath_spec.rb +0 -84
  23. data/spec/fixtures/address.xml +0 -9
  24. data/spec/fixtures/ambigous_items.xml +0 -22
  25. data/spec/fixtures/analytics.xml +0 -61
  26. data/spec/fixtures/analytics_profile.xml +0 -127
  27. data/spec/fixtures/atom.xml +0 -19
  28. data/spec/fixtures/commit.xml +0 -52
  29. data/spec/fixtures/current_weather.xml +0 -89
  30. data/spec/fixtures/current_weather_missing_elements.xml +0 -18
  31. data/spec/fixtures/default_namespace_combi.xml +0 -6
  32. data/spec/fixtures/dictionary.xml +0 -20
  33. data/spec/fixtures/family_tree.xml +0 -21
  34. data/spec/fixtures/inagy.xml +0 -85
  35. data/spec/fixtures/lastfm.xml +0 -355
  36. data/spec/fixtures/multiple_namespaces.xml +0 -170
  37. data/spec/fixtures/multiple_primitives.xml +0 -5
  38. data/spec/fixtures/optional_attributes.xml +0 -6
  39. data/spec/fixtures/pita.xml +0 -133
  40. data/spec/fixtures/posts.xml +0 -23
  41. data/spec/fixtures/product_default_namespace.xml +0 -18
  42. data/spec/fixtures/product_no_namespace.xml +0 -10
  43. data/spec/fixtures/product_single_namespace.xml +0 -10
  44. data/spec/fixtures/quarters.xml +0 -19
  45. data/spec/fixtures/radar.xml +0 -21
  46. data/spec/fixtures/set_config_options.xml +0 -3
  47. data/spec/fixtures/statuses.xml +0 -422
  48. data/spec/fixtures/subclass_namespace.xml +0 -50
  49. data/spec/fixtures/unformatted_address.xml +0 -1
  50. data/spec/fixtures/wrapper.xml +0 -11
  51. data/spec/happymapper/anonymous_mapper_spec.rb +0 -158
  52. data/spec/happymapper/attribute_spec.rb +0 -12
  53. data/spec/happymapper/item_spec.rb +0 -177
  54. data/spec/happymapper_spec.rb +0 -1208
  55. data/spec/spec_helper.rb +0 -25
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 29c4973fa94bd305d925426e58d62690a2929c57af50a2e9d1666957b030db0c
4
- data.tar.gz: e93f66003fc2991d3a28acf775d4224e2d2184751d082e48393c371580949803
3
+ metadata.gz: df07426975e91e50aa2aec4abd1583c85021a314296b10b06079e09126198120
4
+ data.tar.gz: 910f91cb9ed649317e82605c8571c9a59744e23d53a327e2b228f32a8f275758
5
5
  SHA512:
6
- metadata.gz: 9ecf514caadcbce076cafe31127cc3a108a004b7abc75e3bfe2aa18c3d22f1fc86294c5912e43cb30f6d89b26021199d6a8e1cb3f9f63d331ba8eb4afcb2ee2f
7
- data.tar.gz: 3811e5811bc2205708e038629155a195cb949c41f11d096c13db991251d939c1e2327c8c1f80b6e5aab4783ca71f898f06ab3adaa5c20e66e57b90adce634880
6
+ metadata.gz: 9e2c3a0b37ab88d2887b6c5b3e6043c33606102a2e8389e591f259d26b5bd1cc973dcdcb73316b287c0132f2ce5e9c9f4fd3ecfa8904f779eccc5833bfab4342
7
+ data.tar.gz: ba72beaa7d76b55268c0da2e0957604a280d66cba3b334a6fc4a0ee483afc21e3f696d5fd0c5c5ac6d103f94f9a6cab9b20c6541fd5ef36043b5a28a59aa9e05
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.9.0 / 2022-01-21
4
+
5
+ * Add official support for Ruby 2.7, 3.0 and 3.1
6
+ * Drop support for Ruby 2.3, 2.4 and 2.5
7
+ * Fix handling of attributes and elements with `state_when_nil` set
8
+ ([#165](https://github.com/mvz/happymapper/pull/165))
9
+
3
10
  ## 0.8.1 / 2019-03-18
4
11
 
5
12
  * Allow requiring `nokogiri-happymapper`
data/README.md CHANGED
@@ -7,9 +7,6 @@ This project is a fork of the great work done first by
7
7
  [jnunemaker](https://github.com/jnunemaker/happymapper).
8
8
 
9
9
  [![Gem Version](https://badge.fury.io/rb/nokogiri-happymapper.svg)](https://badge.fury.io/rb/nokogiri-happymapper)
10
- [![Build Status](https://travis-ci.org/mvz/happymapper.svg?branch=master)](https://travis-ci.org/mvz/happymapper)
11
- [![Coverage Status](https://coveralls.io/repos/github/mvz/happymapper/badge.svg?branch=master)](https://coveralls.io/github/mvz/happymapper?branch=master)
12
- [![Depfu](https://badges.depfu.com/badges/1707c8c2322e2ed267cf88bd4fb12b66/overview.svg)](https://depfu.com/github/mvz/happymapper)
13
10
  [![Maintainability](https://api.codeclimate.com/v1/badges/491015f82bd2a45fd9d3/maintainability)](https://codeclimate.com/github/mvz/happymapper/maintainability)
14
11
 
15
12
  ## Major Differences
@@ -41,8 +41,8 @@ module HappyMapper
41
41
  result.attribute_nodes.each do |xml_attribute|
42
42
  next unless (attribute_options = options[:attributes][xml_attribute.name.to_sym])
43
43
 
44
- attribute_value = Attribute.new(xml_attribute.name.to_sym, *attribute_options).
45
- from_xml_node(result, namespace, xpath_options)
44
+ attribute_value = Attribute.new(xml_attribute.name.to_sym, *attribute_options)
45
+ .from_xml_node(result, namespace, xpath_options)
46
46
 
47
47
  method_name = xml_attribute.name.tr('-', '_')
48
48
  value.define_singleton_method(method_name) { attribute_value }
@@ -103,11 +103,9 @@ module HappyMapper
103
103
  register_type Float, &:to_f
104
104
 
105
105
  register_type Time do |value|
106
- begin
107
- Time.parse(value.to_s)
108
- rescue StandardError
109
- Time.at(value.to_i)
110
- end
106
+ Time.parse(value.to_s)
107
+ rescue StandardError
108
+ Time.at(value.to_i)
111
109
  end
112
110
 
113
111
  register_type DateTime do |value|
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HappyMapper
4
- VERSION = '0.8.1'
4
+ VERSION = '0.9.0'
5
5
  end
data/lib/happymapper.rb CHANGED
@@ -8,6 +8,7 @@ require 'happymapper/anonymous_mapper'
8
8
 
9
9
  module HappyMapper
10
10
  class Boolean; end
11
+
11
12
  class XmlContent; end
12
13
 
13
14
  def self.parse(xml_content)
@@ -249,15 +250,19 @@ module HappyMapper
249
250
  # onto this class. They get/set the value by passing thru to the anonymous class.
250
251
  passthrus = wrapper.attributes + wrapper.elements
251
252
  passthrus.each do |item|
253
+ method_name = item.method_name
252
254
  class_eval <<-RUBY, __FILE__, __LINE__ + 1
253
- def #{item.method_name}
254
- @#{name} ||= self.class.instance_variable_get('@wrapper_anonymous_classes')['#{wrapper_key}'].new
255
- @#{name}.#{item.method_name}
256
- end
257
- def #{item.method_name}=(value)
258
- @#{name} ||= self.class.instance_variable_get('@wrapper_anonymous_classes')['#{wrapper_key}'].new
259
- @#{name}.#{item.method_name} = value
260
- end
255
+ def #{method_name} # def property
256
+ @#{name} ||= # @wrapper ||=
257
+ wrapper_anonymous_classes['#{wrapper_key}'].new # wrapper_anonymous_classes['#<Class:0x0000555b7d0b9220>'].new
258
+ @#{name}.#{method_name} # @wrapper.property
259
+ end # end
260
+
261
+ def #{method_name}=(value) # def property=(value)
262
+ @#{name} ||= # @wrapper ||=
263
+ wrapper_anonymous_classes['#{wrapper_key}'].new # wrapper_anonymous_classes['#<Class:0x0000555b7d0b9220>'].new
264
+ @#{name}.#{method_name} = value # @wrapper.property = value
265
+ end # end
261
266
  RUBY
262
267
  end
263
268
 
@@ -460,7 +465,7 @@ module HappyMapper
460
465
  # attr_writer :xml_value, or attr_accessor :xml_value then we want to
461
466
  # assign the current xml that we just parsed to the xml_value
462
467
 
463
- if obj.respond_to?('xml_value=')
468
+ if obj.respond_to?(:xml_value=)
464
469
  obj.xml_value = node.to_xml(save_with: Nokogiri::XML::Node::SaveOptions::AS_XML)
465
470
  end
466
471
 
@@ -468,7 +473,7 @@ module HappyMapper
468
473
  # attr_write :xml_content, or attr_accessor :xml_content then we want to
469
474
  # assign the child xml that we just parsed to the xml_content
470
475
 
471
- if obj.respond_to?('xml_content=')
476
+ if obj.respond_to?(:xml_content=)
472
477
  node = node.children if node.respond_to?(:children)
473
478
  obj.xml_content = node.to_xml(save_with: Nokogiri::XML::Node::SaveOptions::AS_XML)
474
479
  end
@@ -554,15 +559,11 @@ module HappyMapper
554
559
  # When a content has been defined we add the resulting value
555
560
  # the output xml
556
561
  #
557
- if (content = self.class.defined_content)
558
-
559
- unless content.options[:read_only]
560
- value = send(content.name)
561
- value = apply_on_save_action(content, value)
562
-
563
- builder.text(value)
564
- end
562
+ if (content = self.class.defined_content) && !content.options[:read_only]
563
+ value = send(content.name)
564
+ value = apply_on_save_action(content, value)
565
565
 
566
+ builder.text(value)
566
567
  end
567
568
 
568
569
  #
@@ -636,33 +637,27 @@ module HappyMapper
636
637
  # when it comes to saving the xml document; so we will not go into any of
637
638
  # the below process
638
639
  #
639
- if attribute.options[:read_only]
640
- []
641
- else
640
+ next if attribute.options[:read_only]
642
641
 
643
- value = send(attribute.method_name)
644
- value = nil if value == attribute.default
642
+ value = send(attribute.method_name)
643
+ value = nil if value == attribute.default
645
644
 
646
- #
647
- # Apply any on_save lambda/proc or value defined on the attribute.
648
- #
649
- value = apply_on_save_action(attribute, value)
645
+ #
646
+ # Apply any on_save lambda/proc or value defined on the attribute.
647
+ #
648
+ value = apply_on_save_action(attribute, value)
650
649
 
651
- #
652
- # Attributes that have a nil value should be ignored unless they explicitly
653
- # state that they should be expressed in the output.
654
- #
655
- if !(value.nil? || attribute.options[:state_when_nil])
656
- attribute_namespace = attribute.options[:namespace]
657
- ["#{attribute_namespace ? "#{attribute_namespace}:" : ''}#{attribute.tag}", value]
658
- else
659
- []
660
- end
650
+ #
651
+ # Attributes that have a nil value should be ignored unless they explicitly
652
+ # state that they should be expressed in the output.
653
+ #
654
+ next if value.nil? && !attribute.options[:state_when_nil]
661
655
 
662
- end
663
- end.flatten
656
+ attribute_namespace = attribute.options[:namespace]
657
+ ["#{attribute_namespace ? "#{attribute_namespace}:" : ''}#{attribute.tag}", value]
658
+ end.compact
664
659
 
665
- Hash[*attributes]
660
+ attributes.to_h
666
661
  end
667
662
 
668
663
  #
@@ -674,9 +669,9 @@ module HappyMapper
674
669
  # which means that it is the default namespace of the code.
675
670
  #
676
671
  def register_namespaces_with_builder(builder)
677
- return unless self.class.instance_variable_get('@registered_namespaces')
672
+ return unless self.class.instance_variable_get(:@registered_namespaces)
678
673
 
679
- self.class.instance_variable_get('@registered_namespaces').sort.each do |name, href|
674
+ self.class.instance_variable_get(:@registered_namespaces).sort.each do |name, href|
680
675
  name = nil if name == 'xmlns'
681
676
  builder.doc.root.add_namespace(name, href)
682
677
  end
@@ -726,29 +721,26 @@ module HappyMapper
726
721
  element.options[:namespace],
727
722
  element.options[:tag] || nil)
728
723
 
729
- elsif !item.nil?
724
+ elsif !item.nil? || element.options[:state_when_nil]
730
725
 
731
726
  item_namespace = element.options[:namespace] || self.class.namespace || default_namespace
732
727
 
733
728
  #
734
- # When a value exists we should append the value for the tag
729
+ # When a value exists or the tag should always be emitted,
730
+ # we should append the value for the tag
735
731
  #
736
732
  if item_namespace
737
733
  xml[item_namespace].send("#{tag}_", item.to_s)
738
734
  else
739
735
  xml.send("#{tag}_", item.to_s)
740
736
  end
741
-
742
- elsif element.options[:state_when_nil]
743
-
744
- #
745
- # Normally a nil value would be ignored, however if specified then
746
- # an empty element will be written to the xml
747
- #
748
- xml.send("#{tag}_", '')
749
737
  end
750
738
  end
751
739
  end
740
+
741
+ def wrapper_anonymous_classes
742
+ self.class.instance_variable_get(:@wrapper_anonymous_classes)
743
+ end
752
744
  end
753
745
 
754
746
  require 'happymapper/supported_types'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nokogiri-happymapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damien Le Berrigaud
@@ -11,10 +11,10 @@ authors:
11
11
  - Etienne Vallette d'Osia
12
12
  - Franklin Webber
13
13
  - Matijs van Zuijlen
14
- autorequire:
14
+ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
- date: 2019-03-18 00:00:00.000000000 Z
17
+ date: 2022-01-21 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: nokogiri
@@ -30,20 +30,48 @@ dependencies:
30
30
  - - "~>"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '1.5'
33
+ - !ruby/object:Gem::Dependency
34
+ name: pry
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 0.14.0
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: 0.14.0
33
47
  - !ruby/object:Gem::Dependency
34
48
  name: rake
35
49
  requirement: !ruby/object:Gem::Requirement
36
50
  requirements:
37
51
  - - "~>"
38
52
  - !ruby/object:Gem::Version
39
- version: '12.0'
53
+ version: '13.0'
40
54
  type: :development
41
55
  prerelease: false
42
56
  version_requirements: !ruby/object:Gem::Requirement
43
57
  requirements:
44
58
  - - "~>"
45
59
  - !ruby/object:Gem::Version
46
- version: '12.0'
60
+ version: '13.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake-manifest
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 0.2.0
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 0.2.0
47
75
  - !ruby/object:Gem::Dependency
48
76
  name: rspec
49
77
  requirement: !ruby/object:Gem::Requirement
@@ -58,20 +86,76 @@ dependencies:
58
86
  - - "~>"
59
87
  - !ruby/object:Gem::Version
60
88
  version: '3.0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rubocop
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: 1.25.0
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: 1.25.0
103
+ - !ruby/object:Gem::Dependency
104
+ name: rubocop-packaging
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: 0.5.0
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: 0.5.0
117
+ - !ruby/object:Gem::Dependency
118
+ name: rubocop-performance
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: 1.13.0
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: 1.13.0
131
+ - !ruby/object:Gem::Dependency
132
+ name: rubocop-rspec
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: 2.7.0
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - "~>"
143
+ - !ruby/object:Gem::Version
144
+ version: 2.7.0
61
145
  - !ruby/object:Gem::Dependency
62
146
  name: simplecov
63
147
  requirement: !ruby/object:Gem::Requirement
64
148
  requirements:
65
149
  - - "~>"
66
150
  - !ruby/object:Gem::Version
67
- version: 0.16.1
151
+ version: 0.21.1
68
152
  type: :development
69
153
  prerelease: false
70
154
  version_requirements: !ruby/object:Gem::Requirement
71
155
  requirements:
72
156
  - - "~>"
73
157
  - !ruby/object:Gem::Version
74
- version: 0.16.1
158
+ version: 0.21.1
75
159
  description: Object to XML Mapping Library, using Nokogiri (fork from John Nunemaker's
76
160
  Happymapper)
77
161
  email: matijs@matijs.net
@@ -94,58 +178,12 @@ files:
94
178
  - lib/happymapper/text_node.rb
95
179
  - lib/happymapper/version.rb
96
180
  - lib/nokogiri-happymapper.rb
97
- - spec/features/after_parse_callbacks_spec.rb
98
- - spec/features/attribute_default_value_spec.rb
99
- - spec/features/attributes_spec.rb
100
- - spec/features/has_many_empty_array_spec.rb
101
- - spec/features/ignay_spec.rb
102
- - spec/features/inheritance_spec.rb
103
- - spec/features/mixed_namespaces_spec.rb
104
- - spec/features/parse_with_object_to_update_spec.rb
105
- - spec/features/same_tag_different_meaning_spec.rb
106
- - spec/features/to_xml_spec.rb
107
- - spec/features/to_xml_with_namespaces_spec.rb
108
- - spec/features/wildcard_tag_name_spec.rb
109
- - spec/features/wrap_spec.rb
110
- - spec/features/xpath_spec.rb
111
- - spec/fixtures/address.xml
112
- - spec/fixtures/ambigous_items.xml
113
- - spec/fixtures/analytics.xml
114
- - spec/fixtures/analytics_profile.xml
115
- - spec/fixtures/atom.xml
116
- - spec/fixtures/commit.xml
117
- - spec/fixtures/current_weather.xml
118
- - spec/fixtures/current_weather_missing_elements.xml
119
- - spec/fixtures/default_namespace_combi.xml
120
- - spec/fixtures/dictionary.xml
121
- - spec/fixtures/family_tree.xml
122
- - spec/fixtures/inagy.xml
123
- - spec/fixtures/lastfm.xml
124
- - spec/fixtures/multiple_namespaces.xml
125
- - spec/fixtures/multiple_primitives.xml
126
- - spec/fixtures/optional_attributes.xml
127
- - spec/fixtures/pita.xml
128
- - spec/fixtures/posts.xml
129
- - spec/fixtures/product_default_namespace.xml
130
- - spec/fixtures/product_no_namespace.xml
131
- - spec/fixtures/product_single_namespace.xml
132
- - spec/fixtures/quarters.xml
133
- - spec/fixtures/radar.xml
134
- - spec/fixtures/set_config_options.xml
135
- - spec/fixtures/statuses.xml
136
- - spec/fixtures/subclass_namespace.xml
137
- - spec/fixtures/unformatted_address.xml
138
- - spec/fixtures/wrapper.xml
139
- - spec/happymapper/anonymous_mapper_spec.rb
140
- - spec/happymapper/attribute_spec.rb
141
- - spec/happymapper/item_spec.rb
142
- - spec/happymapper_spec.rb
143
- - spec/spec_helper.rb
144
181
  homepage: http://github.com/mvz/happymapper
145
182
  licenses:
146
183
  - MIT
147
- metadata: {}
148
- post_install_message:
184
+ metadata:
185
+ rubygems_mfa_required: 'true'
186
+ post_install_message:
149
187
  rdoc_options: []
150
188
  require_paths:
151
189
  - lib
@@ -153,62 +191,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
153
191
  requirements:
154
192
  - - ">="
155
193
  - !ruby/object:Gem::Version
156
- version: 2.3.0
194
+ version: 2.6.0
157
195
  required_rubygems_version: !ruby/object:Gem::Requirement
158
196
  requirements:
159
197
  - - ">="
160
198
  - !ruby/object:Gem::Version
161
199
  version: '0'
162
200
  requirements: []
163
- rubygems_version: 3.0.3
164
- signing_key:
201
+ rubygems_version: 3.3.3
202
+ signing_key:
165
203
  specification_version: 4
166
204
  summary: Provides a simple way to map XML to Ruby Objects and back again.
167
- test_files:
168
- - spec/features/after_parse_callbacks_spec.rb
169
- - spec/features/attribute_default_value_spec.rb
170
- - spec/features/attributes_spec.rb
171
- - spec/features/has_many_empty_array_spec.rb
172
- - spec/features/ignay_spec.rb
173
- - spec/features/inheritance_spec.rb
174
- - spec/features/mixed_namespaces_spec.rb
175
- - spec/features/parse_with_object_to_update_spec.rb
176
- - spec/features/same_tag_different_meaning_spec.rb
177
- - spec/features/to_xml_spec.rb
178
- - spec/features/to_xml_with_namespaces_spec.rb
179
- - spec/features/wildcard_tag_name_spec.rb
180
- - spec/features/wrap_spec.rb
181
- - spec/features/xpath_spec.rb
182
- - spec/fixtures/address.xml
183
- - spec/fixtures/ambigous_items.xml
184
- - spec/fixtures/analytics.xml
185
- - spec/fixtures/analytics_profile.xml
186
- - spec/fixtures/atom.xml
187
- - spec/fixtures/commit.xml
188
- - spec/fixtures/current_weather.xml
189
- - spec/fixtures/current_weather_missing_elements.xml
190
- - spec/fixtures/default_namespace_combi.xml
191
- - spec/fixtures/dictionary.xml
192
- - spec/fixtures/family_tree.xml
193
- - spec/fixtures/inagy.xml
194
- - spec/fixtures/lastfm.xml
195
- - spec/fixtures/multiple_namespaces.xml
196
- - spec/fixtures/multiple_primitives.xml
197
- - spec/fixtures/optional_attributes.xml
198
- - spec/fixtures/pita.xml
199
- - spec/fixtures/posts.xml
200
- - spec/fixtures/product_default_namespace.xml
201
- - spec/fixtures/product_no_namespace.xml
202
- - spec/fixtures/product_single_namespace.xml
203
- - spec/fixtures/quarters.xml
204
- - spec/fixtures/radar.xml
205
- - spec/fixtures/set_config_options.xml
206
- - spec/fixtures/statuses.xml
207
- - spec/fixtures/subclass_namespace.xml
208
- - spec/fixtures/unformatted_address.xml
209
- - spec/fixtures/wrapper.xml
210
- - spec/happymapper/anonymous_mapper_spec.rb
211
- - spec/happymapper/attribute_spec.rb
212
- - spec/happymapper/item_spec.rb
213
- - spec/happymapper_spec.rb
214
- - spec/spec_helper.rb
205
+ test_files: []
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe 'after_parse callbacks', type: :feature do
6
- module AfterParseSpec
7
- class Address
8
- include HappyMapper
9
- element :street, String
10
- end
11
- end
12
-
13
- after do
14
- AfterParseSpec::Address.after_parse_callbacks.clear
15
- end
16
-
17
- it 'callbacks with the newly created object' do
18
- from_cb = nil
19
- called = false
20
- cb1 = proc { |object| from_cb = object }
21
- cb2 = proc { called = true }
22
- AfterParseSpec::Address.after_parse(&cb1)
23
- AfterParseSpec::Address.after_parse(&cb2)
24
-
25
- object = AfterParseSpec::Address.parse fixture_file('address.xml')
26
-
27
- aggregate_failures do
28
- expect(from_cb).to eq(object)
29
- expect(called).to eq(true)
30
- end
31
- end
32
- end
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe 'Attribute Default Value', type: :feature do
6
- context 'when given a default value' do
7
- class Meal
8
- include HappyMapper
9
- tag 'meal'
10
- attribute :type, String, default: 'omnivore'
11
- end
12
-
13
- let(:default_meal_type) { 'omnivore' }
14
-
15
- context 'when no value has been specified' do
16
- it 'returns the default value' do
17
- meal = Meal.parse('<meal />')
18
- expect(meal.type).to eq default_meal_type
19
- end
20
- end
21
-
22
- context 'when saving to xml' do
23
- let(:expected_xml) { %(<?xml version="1.0"?>\n<meal/>\n) }
24
-
25
- it 'the default value is not included' do
26
- meal = Meal.new
27
- expect(meal.to_xml).to eq expected_xml
28
- end
29
- end
30
-
31
- context 'when a new, non-nil value has been set' do
32
- let(:expected_xml) { %(<?xml version="1.0"?>\n<meal type="kosher"/>\n) }
33
-
34
- it 'returns the new value' do
35
- meal = Meal.parse('<meal />')
36
- meal.type = 'vegan'
37
-
38
- expect(meal.type).not_to eq default_meal_type
39
- end
40
-
41
- it 'saves the new value to the xml' do
42
- meal = Meal.new
43
- meal.type = 'kosher'
44
- expect(meal.to_xml).to eq expected_xml
45
- end
46
- end
47
- end
48
- end
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe 'Attribute Method Conversion', type: :feature do
6
- module AttributeMethodConversion
7
- class Document
8
- include HappyMapper
9
-
10
- has_many :link, String, attributes: { 'data-src': String, type: String, href: String }
11
- end
12
- end
13
-
14
- let(:xml_document) do
15
- %(<document>
16
- <link data-src='http://cooking.com/roastbeef' type='recipe'>Roast Beef</link>
17
- </document>)
18
- end
19
-
20
- let(:document) do
21
- AttributeMethodConversion::Document.parse(xml_document, single: true)
22
- end
23
-
24
- it 'link' do
25
- expect(document.link).to eq ['Roast Beef']
26
- end
27
-
28
- it 'link.data_src' do
29
- expect(document.link.first.data_src).to eq 'http://cooking.com/roastbeef'
30
- end
31
-
32
- it 'link.type' do
33
- expect(document.link.first.type).to eq 'recipe'
34
- end
35
- end
@@ -1,44 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- module Sheep
6
- class Item
7
- include HappyMapper
8
- end
9
-
10
- class Navigator
11
- include HappyMapper
12
- tag 'navigator'
13
-
14
- # This is purposefully set to have the name 'items' with the tag 'item'.
15
- # The idea is that it should not find the empty items contained within the
16
- # xml and return an empty array. This exercises the order of how nodes
17
- # are searched for within an XML document.
18
- has_many :items, Item, tag: 'item'
19
-
20
- has_many :items_with_a_different_name, Item, tag: 'item'
21
- end
22
- end
23
-
24
- RSpec.describe 'empty arrays of items based on tags', type: :feature do
25
- let(:xml) do
26
- <<-XML
27
- <navigator>
28
- <items/>
29
- </navigator>
30
- XML
31
- end
32
-
33
- let(:navigator) do
34
- Sheep::Navigator.parse(xml)
35
- end
36
-
37
- it 'returns an empty array' do
38
- expect(navigator.items_with_a_different_name).to be_empty
39
- end
40
-
41
- it 'looks for items based on the element tag, not the element name' do
42
- expect(navigator.items).to be_empty
43
- end
44
- end