nokogiri-happymapper 0.6.0 → 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.
- checksums.yaml +5 -5
- data/CHANGELOG.md +64 -5
- data/README.md +296 -192
- data/lib/happymapper/anonymous_mapper.rb +46 -43
- data/lib/happymapper/attribute.rb +7 -5
- data/lib/happymapper/element.rb +19 -22
- data/lib/happymapper/item.rb +19 -21
- data/lib/happymapper/supported_types.rb +20 -28
- data/lib/happymapper/text_node.rb +4 -3
- data/lib/happymapper/version.rb +3 -1
- data/lib/happymapper.rb +336 -362
- data/lib/nokogiri-happymapper.rb +4 -0
- metadata +124 -105
- data/spec/attribute_default_value_spec.rb +0 -50
- data/spec/attributes_spec.rb +0 -36
- data/spec/fixtures/address.xml +0 -9
- data/spec/fixtures/ambigous_items.xml +0 -22
- data/spec/fixtures/analytics.xml +0 -61
- data/spec/fixtures/analytics_profile.xml +0 -127
- data/spec/fixtures/atom.xml +0 -19
- data/spec/fixtures/commit.xml +0 -52
- data/spec/fixtures/current_weather.xml +0 -89
- data/spec/fixtures/current_weather_missing_elements.xml +0 -18
- data/spec/fixtures/default_namespace_combi.xml +0 -6
- data/spec/fixtures/dictionary.xml +0 -20
- data/spec/fixtures/family_tree.xml +0 -21
- data/spec/fixtures/inagy.xml +0 -85
- data/spec/fixtures/lastfm.xml +0 -355
- data/spec/fixtures/multiple_namespaces.xml +0 -170
- data/spec/fixtures/multiple_primitives.xml +0 -5
- data/spec/fixtures/optional_attributes.xml +0 -6
- data/spec/fixtures/pita.xml +0 -133
- data/spec/fixtures/posts.xml +0 -23
- data/spec/fixtures/product_default_namespace.xml +0 -18
- data/spec/fixtures/product_no_namespace.xml +0 -10
- data/spec/fixtures/product_single_namespace.xml +0 -10
- data/spec/fixtures/quarters.xml +0 -19
- data/spec/fixtures/radar.xml +0 -21
- data/spec/fixtures/set_config_options.xml +0 -3
- data/spec/fixtures/statuses.xml +0 -422
- data/spec/fixtures/subclass_namespace.xml +0 -50
- data/spec/fixtures/unformatted_address.xml +0 -1
- data/spec/fixtures/wrapper.xml +0 -11
- data/spec/happymapper/attribute_spec.rb +0 -12
- data/spec/happymapper/element_spec.rb +0 -9
- data/spec/happymapper/item_spec.rb +0 -136
- data/spec/happymapper/text_node_spec.rb +0 -9
- data/spec/happymapper_parse_spec.rb +0 -113
- data/spec/happymapper_spec.rb +0 -1129
- data/spec/has_many_empty_array_spec.rb +0 -43
- data/spec/ignay_spec.rb +0 -95
- data/spec/inheritance_spec.rb +0 -107
- data/spec/mixed_namespaces_spec.rb +0 -61
- data/spec/parse_with_object_to_update_spec.rb +0 -111
- data/spec/spec_helper.rb +0 -7
- data/spec/to_xml_spec.rb +0 -201
- data/spec/to_xml_with_namespaces_spec.rb +0 -232
- data/spec/wilcard_tag_name_spec.rb +0 -96
- data/spec/wrap_spec.rb +0 -82
- data/spec/xpath_spec.rb +0 -89
@@ -1,113 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe HappyMapper do
|
4
|
-
|
5
|
-
context ".parse" do
|
6
|
-
|
7
|
-
context "on a single root node" do
|
8
|
-
|
9
|
-
subject { described_class.parse fixture_file('address.xml') }
|
10
|
-
|
11
|
-
it "should parse child elements" do
|
12
|
-
expect(subject.street).to eq("Milchstrasse")
|
13
|
-
expect(subject.housenumber).to eq("23")
|
14
|
-
expect(subject.postcode).to eq("26131")
|
15
|
-
expect(subject.city).to eq("Oldenburg")
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should not create a content entry when the xml contents no text content" do
|
19
|
-
expect(subject).not_to respond_to :content
|
20
|
-
end
|
21
|
-
|
22
|
-
context "child elements with attributes" do
|
23
|
-
|
24
|
-
it "should parse the attributes" do
|
25
|
-
expect(subject.country.code).to eq("de")
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should parse the content" do
|
29
|
-
expect(subject.country.content).to eq("Germany")
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
context "element names with special characters" do
|
37
|
-
subject { described_class.parse fixture_file('ambigous_items.xml') }
|
38
|
-
|
39
|
-
it "should create accessor methods with similar names" do
|
40
|
-
expect(subject.my_items.item).to be_kind_of Array
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
context "element names with camelCased elements and Capital Letters" do
|
45
|
-
|
46
|
-
subject { described_class.parse fixture_file('subclass_namespace.xml') }
|
47
|
-
|
48
|
-
it "should parse the elements and values correctly" do
|
49
|
-
expect(subject.title).to eq("article title")
|
50
|
-
expect(subject.photo.publish_options.author).to eq("Stephanie")
|
51
|
-
expect(subject.gallery.photo.title).to eq("photo title")
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
context "several elements nested deep" do
|
56
|
-
subject { described_class.parse fixture_file('ambigous_items.xml') }
|
57
|
-
|
58
|
-
it "should parse the entire relationship" do
|
59
|
-
expect(subject.my_items.item.first.item.name).to eq("My first internal item")
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
context "xml that contains multiple entries" do
|
64
|
-
|
65
|
-
subject { described_class.parse fixture_file('multiple_primitives.xml') }
|
66
|
-
|
67
|
-
it "should parse the elements as it would a 'has_many'" do
|
68
|
-
|
69
|
-
expect(subject.name).to eq("value")
|
70
|
-
expect(subject.image).to eq([ "image1", "image2" ])
|
71
|
-
|
72
|
-
end
|
73
|
-
|
74
|
-
end
|
75
|
-
|
76
|
-
context "xml with multiple namespaces" do
|
77
|
-
|
78
|
-
subject { described_class.parse fixture_file('subclass_namespace.xml') }
|
79
|
-
|
80
|
-
it "should parse the elements an values correctly" do
|
81
|
-
expect(subject.title).to eq("article title")
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
context "after_parse callbacks" do
|
86
|
-
module AfterParseSpec
|
87
|
-
class Address
|
88
|
-
include HappyMapper
|
89
|
-
element :street, String
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
after do
|
94
|
-
AfterParseSpec::Address.after_parse_callbacks.clear
|
95
|
-
end
|
96
|
-
|
97
|
-
it "should callback with the newly created object" do
|
98
|
-
from_cb = nil
|
99
|
-
called = false
|
100
|
-
cb1 = proc { |object| from_cb = object }
|
101
|
-
cb2 = proc { called = true }
|
102
|
-
AfterParseSpec::Address.after_parse(&cb1)
|
103
|
-
AfterParseSpec::Address.after_parse(&cb2)
|
104
|
-
|
105
|
-
object = AfterParseSpec::Address.parse fixture_file('address.xml')
|
106
|
-
expect(from_cb).to eq(object)
|
107
|
-
expect(called).to eq(true)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
end
|
112
|
-
|
113
|
-
end
|