data_active 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +2 -1
- data/data_active.gemspec +8 -6
- data/features/step_definitions/step_helper.rb +5 -4
- data/features/step_definitions/sync_books_with_xml.rb +11 -7
- data/features/support/book_generator.rb +29 -0
- data/features/support/factories/book.rb +6 -0
- data/features/support/factories/book_price.rb +8 -0
- data/features/support/factories/chapter.rb +7 -0
- data/features/support/factories/page.rb +7 -0
- data/features/support/fixtures/fresh/pages.yml +10 -10
- data/features/sync_database_with_xml.feature +2 -2
- data/features/sync_one_to_many.feature +0 -6
- data/features/sync_one_to_one.feature +1 -1
- data/lib/data_active.rb +8 -282
- data/lib/data_active/attribute.rb +12 -0
- data/lib/data_active/entity.rb +151 -0
- data/lib/data_active/parser.rb +159 -0
- data/lib/data_active/sax_document.rb +29 -0
- data/lib/data_active/version.rb +1 -1
- data/spec/entity_spec.rb +11 -0
- data/spec/fixtures/xml/ms_xml/books_fresh.xml +173 -0
- data/spec/fixtures/xml/rails_xml/books_fresh.xml +173 -0
- data/spec/parser_spec.rb +285 -0
- data/spec/sax_document_spec.rb +3 -0
- data/spec/spec_helper.rb +39 -0
- data/test_apps/book_store_rails_31x/config/application.rb +0 -32
- data/test_apps/book_store_rails_32x/.rspec +1 -0
- data/test_apps/book_store_rails_32x/.rvmrc +1 -1
- data/test_apps/book_store_rails_32x/Gemfile +12 -4
- data/test_apps/book_store_rails_32x/config/application.rb +0 -40
- metadata +63 -5
- data/features/step_definitions/web_steps.rb +0 -211
@@ -0,0 +1,173 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<books type="array">
|
3
|
+
<book>
|
4
|
+
<id type="integer">1</id>
|
5
|
+
<name>Book 1</name>
|
6
|
+
<book_price>
|
7
|
+
<id type="integer">1</id>
|
8
|
+
<sell>50.00</sell>
|
9
|
+
<educational>35.00</educational>
|
10
|
+
<cost>20.00</cost>
|
11
|
+
</book_price>
|
12
|
+
<chapters type="array">
|
13
|
+
<chapter>
|
14
|
+
<id type="integer">1</id>
|
15
|
+
<title>Chapter 1</title>
|
16
|
+
<introduction>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus purus nulla, condimentum vitae hendrerit nec, blandit et felis. Suspendisse vulputate mollis suscipit. Vivamus non libero quis urna gravida euismod quis in nisi. Morbi turpis orci, posuere nec ultrices ut, egestas ac purus. Morbi id pretium erat. In ullamcorper, ligula id porta pellentesque, sem turpis ultricies libero, non elementum ipsum neque at dui. Donec auctor nulla id mi dapibus id faucibus felis mollis. Curabitur imperdiet tristique nisi, consectetur molestie purus accumsan id. Curabitur lacinia diam et nisl iaculis eleifend. Quisque turpis elit, volutpat eget dapibus sed, egestas nec leo. Mauris dignissim tellus non lorem fringilla pharetra.</introduction>
|
17
|
+
<pages type="array">
|
18
|
+
<page>
|
19
|
+
<id type="integer">1</id>
|
20
|
+
<content>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus purus nulla, condimentum vitae hendrerit nec, blandit et felis. Suspendisse vulputate mollis suscipit. Vivamus non libero quis urna gravida euismod quis in nisi. Morbi turpis orci, posuere nec ultrices ut, egestas ac purus. Morbi id pretium erat. In ullamcorper, ligula id porta pellentesque, sem turpis ultricies libero, non elementum ipsum neque at dui. Donec auctor nulla id mi dapibus id faucibus felis mollis. Curabitur imperdiet tristique nisi, consectetur molestie purus accumsan id. Curabitur lacinia diam et nisl iaculis eleifend. Quisque turpis elit, volutpat eget dapibus sed, egestas nec leo. Mauris dignissim tellus non lorem fringilla pharetra.</content>
|
21
|
+
<number>1</number>
|
22
|
+
</page>
|
23
|
+
<page>
|
24
|
+
<id type="integer">2</id>
|
25
|
+
<content>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus purus nulla, condimentum vitae hendrerit nec, blandit et felis. Suspendisse vulputate mollis suscipit. Vivamus non libero quis urna gravida euismod quis in nisi. Morbi turpis orci, posuere nec ultrices ut, egestas ac purus. Morbi id pretium erat. In ullamcorper, ligula id porta pellentesque, sem turpis ultricies libero, non elementum ipsum neque at dui. Donec auctor nulla id mi dapibus id faucibus felis mollis. Curabitur imperdiet tristique nisi, consectetur molestie purus accumsan id. Curabitur lacinia diam et nisl iaculis eleifend. Quisque turpis elit, volutpat eget dapibus sed, egestas nec leo. Mauris dignissim tellus non lorem fringilla pharetra.</content>
|
26
|
+
<number>2</number>
|
27
|
+
</page>
|
28
|
+
<page>
|
29
|
+
<id type="integer">3</id>
|
30
|
+
<content>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus purus nulla, condimentum vitae hendrerit nec, blandit et felis. Suspendisse vulputate mollis suscipit. Vivamus non libero quis urna gravida euismod quis in nisi. Morbi turpis orci, posuere nec ultrices ut, egestas ac purus. Morbi id pretium erat. In ullamcorper, ligula id porta pellentesque, sem turpis ultricies libero, non elementum ipsum neque at dui. Donec auctor nulla id mi dapibus id faucibus felis mollis. Curabitur imperdiet tristique nisi, consectetur molestie purus accumsan id. Curabitur lacinia diam et nisl iaculis eleifend. Quisque turpis elit, volutpat eget dapibus sed, egestas nec leo. Mauris dignissim tellus non lorem fringilla pharetra.</content>
|
31
|
+
<number>3</number>
|
32
|
+
</page>
|
33
|
+
<page>
|
34
|
+
<id type="integer">4</id>
|
35
|
+
<content>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus purus nulla, condimentum vitae hendrerit nec, blandit et felis. Suspendisse vulputate mollis suscipit. Vivamus non libero quis urna gravida euismod quis in nisi. Morbi turpis orci, posuere nec ultrices ut, egestas ac purus. Morbi id pretium erat. In ullamcorper, ligula id porta pellentesque, sem turpis ultricies libero, non elementum ipsum neque at dui. Donec auctor nulla id mi dapibus id faucibus felis mollis. Curabitur imperdiet tristique nisi, consectetur molestie purus accumsan id. Curabitur lacinia diam et nisl iaculis eleifend. Quisque turpis elit, volutpat eget dapibus sed, egestas nec leo. Mauris dignissim tellus non lorem fringilla pharetra.</content>
|
36
|
+
<number>4</number>
|
37
|
+
</page>
|
38
|
+
</pages>
|
39
|
+
</chapter>
|
40
|
+
<chapter>
|
41
|
+
<id type="integer">2</id>
|
42
|
+
<title>Chapter 2</title>
|
43
|
+
<introduction>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus purus nulla, condimentum vitae hendrerit nec, blandit et felis. Suspendisse vulputate mollis suscipit. Vivamus non libero quis urna gravida euismod quis in nisi. Morbi turpis orci, posuere nec ultrices ut, egestas ac purus. Morbi id pretium erat. In ullamcorper, ligula id porta pellentesque, sem turpis ultricies libero, non elementum ipsum neque at dui. Donec auctor nulla id mi dapibus id faucibus felis mollis. Curabitur imperdiet tristique nisi, consectetur molestie purus accumsan id. Curabitur lacinia diam et nisl iaculis eleifend. Quisque turpis elit, volutpat eget dapibus sed, egestas nec leo. Mauris dignissim tellus non lorem fringilla pharetra.</introduction>
|
44
|
+
<pages type="array">
|
45
|
+
<page>
|
46
|
+
<id type="integer">5</id>
|
47
|
+
<content>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus purus nulla, condimentum vitae hendrerit nec, blandit et felis. Suspendisse vulputate mollis suscipit. Vivamus non libero quis urna gravida euismod quis in nisi. Morbi turpis orci, posuere nec ultrices ut, egestas ac purus. Morbi id pretium erat. In ullamcorper, ligula id porta pellentesque, sem turpis ultricies libero, non elementum ipsum neque at dui. Donec auctor nulla id mi dapibus id faucibus felis mollis. Curabitur imperdiet tristique nisi, consectetur molestie purus accumsan id. Curabitur lacinia diam et nisl iaculis eleifend. Quisque turpis elit, volutpat eget dapibus sed, egestas nec leo. Mauris dignissim tellus non lorem fringilla pharetra.</content>
|
48
|
+
<number>1</number>
|
49
|
+
</page>
|
50
|
+
<page>
|
51
|
+
<id type="integer">6</id>
|
52
|
+
<content>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus purus nulla, condimentum vitae hendrerit nec, blandit et felis. Suspendisse vulputate mollis suscipit. Vivamus non libero quis urna gravida euismod quis in nisi. Morbi turpis orci, posuere nec ultrices ut, egestas ac purus. Morbi id pretium erat. In ullamcorper, ligula id porta pellentesque, sem turpis ultricies libero, non elementum ipsum neque at dui. Donec auctor nulla id mi dapibus id faucibus felis mollis. Curabitur imperdiet tristique nisi, consectetur molestie purus accumsan id. Curabitur lacinia diam et nisl iaculis eleifend. Quisque turpis elit, volutpat eget dapibus sed, egestas nec leo. Mauris dignissim tellus non lorem fringilla pharetra.</content>
|
53
|
+
<number>2</number>
|
54
|
+
</page>
|
55
|
+
<page>
|
56
|
+
<id type="integer">7</id>
|
57
|
+
<content>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus purus nulla, condimentum vitae hendrerit nec, blandit et felis. Suspendisse vulputate mollis suscipit. Vivamus non libero quis urna gravida euismod quis in nisi. Morbi turpis orci, posuere nec ultrices ut, egestas ac purus. Morbi id pretium erat. In ullamcorper, ligula id porta pellentesque, sem turpis ultricies libero, non elementum ipsum neque at dui. Donec auctor nulla id mi dapibus id faucibus felis mollis. Curabitur imperdiet tristique nisi, consectetur molestie purus accumsan id. Curabitur lacinia diam et nisl iaculis eleifend. Quisque turpis elit, volutpat eget dapibus sed, egestas nec leo. Mauris dignissim tellus non lorem fringilla pharetra.</content>
|
58
|
+
<number>3</number>
|
59
|
+
</page>
|
60
|
+
<page>
|
61
|
+
<id type="integer">8</id>
|
62
|
+
<content>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus purus nulla, condimentum vitae hendrerit nec, blandit et felis. Suspendisse vulputate mollis suscipit. Vivamus non libero quis urna gravida euismod quis in nisi. Morbi turpis orci, posuere nec ultrices ut, egestas ac purus. Morbi id pretium erat. In ullamcorper, ligula id porta pellentesque, sem turpis ultricies libero, non elementum ipsum neque at dui. Donec auctor nulla id mi dapibus id faucibus felis mollis. Curabitur imperdiet tristique nisi, consectetur molestie purus accumsan id. Curabitur lacinia diam et nisl iaculis eleifend. Quisque turpis elit, volutpat eget dapibus sed, egestas nec leo. Mauris dignissim tellus non lorem fringilla pharetra.</content>
|
63
|
+
<number>4</number>
|
64
|
+
</page>
|
65
|
+
</pages>
|
66
|
+
</chapter>
|
67
|
+
<chapter>
|
68
|
+
<id type="integer">3</id>
|
69
|
+
<title>Chapter 3</title>
|
70
|
+
<introduction>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus purus nulla, condimentum vitae hendrerit nec, blandit et felis. Suspendisse vulputate mollis suscipit. Vivamus non libero quis urna gravida euismod quis in nisi. Morbi turpis orci, posuere nec ultrices ut, egestas ac purus. Morbi id pretium erat. In ullamcorper, ligula id porta pellentesque, sem turpis ultricies libero, non elementum ipsum neque at dui. Donec auctor nulla id mi dapibus id faucibus felis mollis. Curabitur imperdiet tristique nisi, consectetur molestie purus accumsan id. Curabitur lacinia diam et nisl iaculis eleifend. Quisque turpis elit, volutpat eget dapibus sed, egestas nec leo. Mauris dignissim tellus non lorem fringilla pharetra.</introduction>
|
71
|
+
<pages type="array">
|
72
|
+
<page>
|
73
|
+
<id type="integer">9</id>
|
74
|
+
<content>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus purus nulla, condimentum vitae hendrerit nec, blandit et felis. Suspendisse vulputate mollis suscipit. Vivamus non libero quis urna gravida euismod quis in nisi. Morbi turpis orci, posuere nec ultrices ut, egestas ac purus. Morbi id pretium erat. In ullamcorper, ligula id porta pellentesque, sem turpis ultricies libero, non elementum ipsum neque at dui. Donec auctor nulla id mi dapibus id faucibus felis mollis. Curabitur imperdiet tristique nisi, consectetur molestie purus accumsan id. Curabitur lacinia diam et nisl iaculis eleifend. Quisque turpis elit, volutpat eget dapibus sed, egestas nec leo. Mauris dignissim tellus non lorem fringilla pharetra.</content>
|
75
|
+
<number>1</number>
|
76
|
+
</page>
|
77
|
+
<page>
|
78
|
+
<id type="integer">10</id>
|
79
|
+
<content>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus purus nulla, condimentum vitae hendrerit nec, blandit et felis. Suspendisse vulputate mollis suscipit. Vivamus non libero quis urna gravida euismod quis in nisi. Morbi turpis orci, posuere nec ultrices ut, egestas ac purus. Morbi id pretium erat. In ullamcorper, ligula id porta pellentesque, sem turpis ultricies libero, non elementum ipsum neque at dui. Donec auctor nulla id mi dapibus id faucibus felis mollis. Curabitur imperdiet tristique nisi, consectetur molestie purus accumsan id. Curabitur lacinia diam et nisl iaculis eleifend. Quisque turpis elit, volutpat eget dapibus sed, egestas nec leo. Mauris dignissim tellus non lorem fringilla pharetra.</content>
|
80
|
+
<number>2</number>
|
81
|
+
</page>
|
82
|
+
<page>
|
83
|
+
<id type="integer">11</id>
|
84
|
+
<content>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus purus nulla, condimentum vitae hendrerit nec, blandit et felis. Suspendisse vulputate mollis suscipit. Vivamus non libero quis urna gravida euismod quis in nisi. Morbi turpis orci, posuere nec ultrices ut, egestas ac purus. Morbi id pretium erat. In ullamcorper, ligula id porta pellentesque, sem turpis ultricies libero, non elementum ipsum neque at dui. Donec auctor nulla id mi dapibus id faucibus felis mollis. Curabitur imperdiet tristique nisi, consectetur molestie purus accumsan id. Curabitur lacinia diam et nisl iaculis eleifend. Quisque turpis elit, volutpat eget dapibus sed, egestas nec leo. Mauris dignissim tellus non lorem fringilla pharetra.</content>
|
85
|
+
<number>3</number>
|
86
|
+
</page>
|
87
|
+
</pages>
|
88
|
+
</chapter>
|
89
|
+
</chapters>
|
90
|
+
</book>
|
91
|
+
<book>
|
92
|
+
<id type="integer">2</id>
|
93
|
+
<name>Book 1</name>
|
94
|
+
<chapters type="array">
|
95
|
+
<chapter>
|
96
|
+
<id type="integer">4</id>
|
97
|
+
<title>Chapter 1</title>
|
98
|
+
<introduction>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus purus nulla, condimentum vitae hendrerit nec, blandit et felis. Suspendisse vulputate mollis suscipit. Vivamus non libero quis urna gravida euismod quis in nisi. Morbi turpis orci, posuere nec ultrices ut, egestas ac purus. Morbi id pretium erat. In ullamcorper, ligula id porta pellentesque, sem turpis ultricies libero, non elementum ipsum neque at dui. Donec auctor nulla id mi dapibus id faucibus felis mollis. Curabitur imperdiet tristique nisi, consectetur molestie purus accumsan id. Curabitur lacinia diam et nisl iaculis eleifend. Quisque turpis elit, volutpat eget dapibus sed, egestas nec leo. Mauris dignissim tellus non lorem fringilla pharetra.</introduction>
|
99
|
+
<pages type="array">
|
100
|
+
<page>
|
101
|
+
<id type="integer">12</id>
|
102
|
+
<content>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus purus nulla, condimentum vitae hendrerit nec, blandit et felis. Suspendisse vulputate mollis suscipit. Vivamus non libero quis urna gravida euismod quis in nisi. Morbi turpis orci, posuere nec ultrices ut, egestas ac purus. Morbi id pretium erat. In ullamcorper, ligula id porta pellentesque, sem turpis ultricies libero, non elementum ipsum neque at dui. Donec auctor nulla id mi dapibus id faucibus felis mollis. Curabitur imperdiet tristique nisi, consectetur molestie purus accumsan id. Curabitur lacinia diam et nisl iaculis eleifend. Quisque turpis elit, volutpat eget dapibus sed, egestas nec leo. Mauris dignissim tellus non lorem fringilla pharetra.</content>
|
103
|
+
<number>1</number>
|
104
|
+
</page>
|
105
|
+
<page>
|
106
|
+
<id type="integer">13</id>
|
107
|
+
<content>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus purus nulla, condimentum vitae hendrerit nec, blandit et felis. Suspendisse vulputate mollis suscipit. Vivamus non libero quis urna gravida euismod quis in nisi. Morbi turpis orci, posuere nec ultrices ut, egestas ac purus. Morbi id pretium erat. In ullamcorper, ligula id porta pellentesque, sem turpis ultricies libero, non elementum ipsum neque at dui. Donec auctor nulla id mi dapibus id faucibus felis mollis. Curabitur imperdiet tristique nisi, consectetur molestie purus accumsan id. Curabitur lacinia diam et nisl iaculis eleifend. Quisque turpis elit, volutpat eget dapibus sed, egestas nec leo. Mauris dignissim tellus non lorem fringilla pharetra.</content>
|
108
|
+
<number>2</number>
|
109
|
+
</page>
|
110
|
+
<page>
|
111
|
+
<id type="integer">14</id>
|
112
|
+
<content>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus purus nulla, condimentum vitae hendrerit nec, blandit et felis. Suspendisse vulputate mollis suscipit. Vivamus non libero quis urna gravida euismod quis in nisi. Morbi turpis orci, posuere nec ultrices ut, egestas ac purus. Morbi id pretium erat. In ullamcorper, ligula id porta pellentesque, sem turpis ultricies libero, non elementum ipsum neque at dui. Donec auctor nulla id mi dapibus id faucibus felis mollis. Curabitur imperdiet tristique nisi, consectetur molestie purus accumsan id. Curabitur lacinia diam et nisl iaculis eleifend. Quisque turpis elit, volutpat eget dapibus sed, egestas nec leo. Mauris dignissim tellus non lorem fringilla pharetra.</content>
|
113
|
+
<number>3</number>
|
114
|
+
</page>
|
115
|
+
<page>
|
116
|
+
<id type="integer">15</id>
|
117
|
+
<content>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus purus nulla, condimentum vitae hendrerit nec, blandit et felis. Suspendisse vulputate mollis suscipit. Vivamus non libero quis urna gravida euismod quis in nisi. Morbi turpis orci, posuere nec ultrices ut, egestas ac purus. Morbi id pretium erat. In ullamcorper, ligula id porta pellentesque, sem turpis ultricies libero, non elementum ipsum neque at dui. Donec auctor nulla id mi dapibus id faucibus felis mollis. Curabitur imperdiet tristique nisi, consectetur molestie purus accumsan id. Curabitur lacinia diam et nisl iaculis eleifend. Quisque turpis elit, volutpat eget dapibus sed, egestas nec leo. Mauris dignissim tellus non lorem fringilla pharetra.</content>
|
118
|
+
<number>4</number>
|
119
|
+
</page>
|
120
|
+
</pages>
|
121
|
+
</chapter>
|
122
|
+
<chapter>
|
123
|
+
<id type="integer">5</id>
|
124
|
+
<title>Chapter 2</title>
|
125
|
+
<introduction>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus purus nulla, condimentum vitae hendrerit nec, blandit et felis. Suspendisse vulputate mollis suscipit. Vivamus non libero quis urna gravida euismod quis in nisi. Morbi turpis orci, posuere nec ultrices ut, egestas ac purus. Morbi id pretium erat. In ullamcorper, ligula id porta pellentesque, sem turpis ultricies libero, non elementum ipsum neque at dui. Donec auctor nulla id mi dapibus id faucibus felis mollis. Curabitur imperdiet tristique nisi, consectetur molestie purus accumsan id. Curabitur lacinia diam et nisl iaculis eleifend. Quisque turpis elit, volutpat eget dapibus sed, egestas nec leo. Mauris dignissim tellus non lorem fringilla pharetra.</introduction>
|
126
|
+
<pages type="array">
|
127
|
+
<page>
|
128
|
+
<id type="integer">16</id>
|
129
|
+
<content>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus purus nulla, condimentum vitae hendrerit nec, blandit et felis. Suspendisse vulputate mollis suscipit. Vivamus non libero quis urna gravida euismod quis in nisi. Morbi turpis orci, posuere nec ultrices ut, egestas ac purus. Morbi id pretium erat. In ullamcorper, ligula id porta pellentesque, sem turpis ultricies libero, non elementum ipsum neque at dui. Donec auctor nulla id mi dapibus id faucibus felis mollis. Curabitur imperdiet tristique nisi, consectetur molestie purus accumsan id. Curabitur lacinia diam et nisl iaculis eleifend. Quisque turpis elit, volutpat eget dapibus sed, egestas nec leo. Mauris dignissim tellus non lorem fringilla pharetra.</content>
|
130
|
+
<number>1</number>
|
131
|
+
</page>
|
132
|
+
<page>
|
133
|
+
<id type="integer">17</id>
|
134
|
+
<content>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus purus nulla, condimentum vitae hendrerit nec, blandit et felis. Suspendisse vulputate mollis suscipit. Vivamus non libero quis urna gravida euismod quis in nisi. Morbi turpis orci, posuere nec ultrices ut, egestas ac purus. Morbi id pretium erat. In ullamcorper, ligula id porta pellentesque, sem turpis ultricies libero, non elementum ipsum neque at dui. Donec auctor nulla id mi dapibus id faucibus felis mollis. Curabitur imperdiet tristique nisi, consectetur molestie purus accumsan id. Curabitur lacinia diam et nisl iaculis eleifend. Quisque turpis elit, volutpat eget dapibus sed, egestas nec leo. Mauris dignissim tellus non lorem fringilla pharetra.</content>
|
135
|
+
<number>2</number>
|
136
|
+
</page>
|
137
|
+
<page>
|
138
|
+
<id type="integer">18</id>
|
139
|
+
<content>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus purus nulla, condimentum vitae hendrerit nec, blandit et felis. Suspendisse vulputate mollis suscipit. Vivamus non libero quis urna gravida euismod quis in nisi. Morbi turpis orci, posuere nec ultrices ut, egestas ac purus. Morbi id pretium erat. In ullamcorper, ligula id porta pellentesque, sem turpis ultricies libero, non elementum ipsum neque at dui. Donec auctor nulla id mi dapibus id faucibus felis mollis. Curabitur imperdiet tristique nisi, consectetur molestie purus accumsan id. Curabitur lacinia diam et nisl iaculis eleifend. Quisque turpis elit, volutpat eget dapibus sed, egestas nec leo. Mauris dignissim tellus non lorem fringilla pharetra.</content>
|
140
|
+
<number>3</number>
|
141
|
+
</page>
|
142
|
+
<page>
|
143
|
+
<id type="integer">19</id>
|
144
|
+
<content>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus purus nulla, condimentum vitae hendrerit nec, blandit et felis. Suspendisse vulputate mollis suscipit. Vivamus non libero quis urna gravida euismod quis in nisi. Morbi turpis orci, posuere nec ultrices ut, egestas ac purus. Morbi id pretium erat. In ullamcorper, ligula id porta pellentesque, sem turpis ultricies libero, non elementum ipsum neque at dui. Donec auctor nulla id mi dapibus id faucibus felis mollis. Curabitur imperdiet tristique nisi, consectetur molestie purus accumsan id. Curabitur lacinia diam et nisl iaculis eleifend. Quisque turpis elit, volutpat eget dapibus sed, egestas nec leo. Mauris dignissim tellus non lorem fringilla pharetra.</content>
|
145
|
+
<number>4</number>
|
146
|
+
</page>
|
147
|
+
</pages>
|
148
|
+
</chapter>
|
149
|
+
<chapter>
|
150
|
+
<id type="integer">6</id>
|
151
|
+
<title>Chapter 3</title>
|
152
|
+
<introduction>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus purus nulla, condimentum vitae hendrerit nec, blandit et felis. Suspendisse vulputate mollis suscipit. Vivamus non libero quis urna gravida euismod quis in nisi. Morbi turpis orci, posuere nec ultrices ut, egestas ac purus. Morbi id pretium erat. In ullamcorper, ligula id porta pellentesque, sem turpis ultricies libero, non elementum ipsum neque at dui. Donec auctor nulla id mi dapibus id faucibus felis mollis. Curabitur imperdiet tristique nisi, consectetur molestie purus accumsan id. Curabitur lacinia diam et nisl iaculis eleifend. Quisque turpis elit, volutpat eget dapibus sed, egestas nec leo. Mauris dignissim tellus non lorem fringilla pharetra.</introduction>
|
153
|
+
<pages type="array">
|
154
|
+
<page>
|
155
|
+
<id type="integer">20</id>
|
156
|
+
<content>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus purus nulla, condimentum vitae hendrerit nec, blandit et felis. Suspendisse vulputate mollis suscipit. Vivamus non libero quis urna gravida euismod quis in nisi. Morbi turpis orci, posuere nec ultrices ut, egestas ac purus. Morbi id pretium erat. In ullamcorper, ligula id porta pellentesque, sem turpis ultricies libero, non elementum ipsum neque at dui. Donec auctor nulla id mi dapibus id faucibus felis mollis. Curabitur imperdiet tristique nisi, consectetur molestie purus accumsan id. Curabitur lacinia diam et nisl iaculis eleifend. Quisque turpis elit, volutpat eget dapibus sed, egestas nec leo. Mauris dignissim tellus non lorem fringilla pharetra.</content>
|
157
|
+
<number>1</number>
|
158
|
+
</page>
|
159
|
+
<page>
|
160
|
+
<id type="integer">21</id>
|
161
|
+
<content>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus purus nulla, condimentum vitae hendrerit nec, blandit et felis. Suspendisse vulputate mollis suscipit. Vivamus non libero quis urna gravida euismod quis in nisi. Morbi turpis orci, posuere nec ultrices ut, egestas ac purus. Morbi id pretium erat. In ullamcorper, ligula id porta pellentesque, sem turpis ultricies libero, non elementum ipsum neque at dui. Donec auctor nulla id mi dapibus id faucibus felis mollis. Curabitur imperdiet tristique nisi, consectetur molestie purus accumsan id. Curabitur lacinia diam et nisl iaculis eleifend. Quisque turpis elit, volutpat eget dapibus sed, egestas nec leo. Mauris dignissim tellus non lorem fringilla pharetra.</content>
|
162
|
+
<number>2</number>
|
163
|
+
</page>
|
164
|
+
<page>
|
165
|
+
<id type="integer">22</id>
|
166
|
+
<content>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus purus nulla, condimentum vitae hendrerit nec, blandit et felis. Suspendisse vulputate mollis suscipit. Vivamus non libero quis urna gravida euismod quis in nisi. Morbi turpis orci, posuere nec ultrices ut, egestas ac purus. Morbi id pretium erat. In ullamcorper, ligula id porta pellentesque, sem turpis ultricies libero, non elementum ipsum neque at dui. Donec auctor nulla id mi dapibus id faucibus felis mollis. Curabitur imperdiet tristique nisi, consectetur molestie purus accumsan id. Curabitur lacinia diam et nisl iaculis eleifend. Quisque turpis elit, volutpat eget dapibus sed, egestas nec leo. Mauris dignissim tellus non lorem fringilla pharetra.</content>
|
167
|
+
<number>3</number>
|
168
|
+
</page>
|
169
|
+
</pages>
|
170
|
+
</chapter>
|
171
|
+
</chapters>
|
172
|
+
</book>
|
173
|
+
</books>
|
data/spec/parser_spec.rb
ADDED
@@ -0,0 +1,285 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DataActive::Parser do
|
4
|
+
context 'parsing start' do
|
5
|
+
let (:parser) { DataActive::Parser.new('book') }
|
6
|
+
it ('should occur when the right element name is provided') { parser.begin('book'); parser.has_started_parsing? }
|
7
|
+
it ('should not occur when the wrong element is provided') { parser.begin('dataroot'); parser.has_started_parsing? == false }
|
8
|
+
end
|
9
|
+
|
10
|
+
context 'when parsing attributes' do
|
11
|
+
let (:parser) { DataActive::Parser.new('book') }
|
12
|
+
it ('will get upset about mismatched tags') do
|
13
|
+
parser.begin('book')
|
14
|
+
|
15
|
+
parser.begin('id')
|
16
|
+
parser.content('1')
|
17
|
+
failed = true
|
18
|
+
begin
|
19
|
+
parser.end('name')
|
20
|
+
rescue
|
21
|
+
failed = false
|
22
|
+
end
|
23
|
+
|
24
|
+
fail('Allowed mismatched tags') if failed
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
it ('should record known attributes against the entity') do
|
29
|
+
parser
|
30
|
+
.begin('book')
|
31
|
+
.begin('id').content('1').end('id')
|
32
|
+
.begin('name').content('101 Testing').end('name')
|
33
|
+
.begin('full_name').content('101 Testing: Your start to testing').end('full_name') # Unknown attribute
|
34
|
+
|
35
|
+
entity = parser.stack.last
|
36
|
+
entity.attributes['id'].name.should eq 'id'
|
37
|
+
entity.attributes['id'].content.should eq '1'
|
38
|
+
entity.attributes['name'].name.should eq 'name'
|
39
|
+
entity.attributes['name'].content.should eq '101 Testing'
|
40
|
+
attributes = entity.attributes.select { |key, a| a.name == 'full_name' }
|
41
|
+
attributes.count.should eq 0
|
42
|
+
end
|
43
|
+
|
44
|
+
it ('should create records when the :create option is in use') do
|
45
|
+
parser.options << :create
|
46
|
+
|
47
|
+
parser
|
48
|
+
.begin('book')
|
49
|
+
.begin('id').content('2').end('id')
|
50
|
+
.begin('name').content('101 Testing').end('name')
|
51
|
+
.end('book')
|
52
|
+
|
53
|
+
books = Book.all
|
54
|
+
books.count.should eq 1
|
55
|
+
books[0].id.should eq 1
|
56
|
+
books[0].name.should eq '101 Testing'
|
57
|
+
end
|
58
|
+
|
59
|
+
it ('will update records when the :update option is in use') do
|
60
|
+
book = Book.create! name: '101 Testing'
|
61
|
+
|
62
|
+
parser.options << :update
|
63
|
+
|
64
|
+
parser
|
65
|
+
.begin('book')
|
66
|
+
.begin('id').content(book.id).end('id')
|
67
|
+
.begin('name').content('101 Testing again').end('name')
|
68
|
+
.end('book')
|
69
|
+
|
70
|
+
books = Book.all
|
71
|
+
books.count.should eq 1
|
72
|
+
books[0].id.should eq 1
|
73
|
+
books[0].name.should eq '101 Testing again'
|
74
|
+
end
|
75
|
+
|
76
|
+
it ('should raise an error when strict mode is used') do
|
77
|
+
parser.options << :strict
|
78
|
+
parser.begin('book')
|
79
|
+
failed = true
|
80
|
+
begin
|
81
|
+
parser.begin('bogus').content('1').end('bogus')
|
82
|
+
rescue
|
83
|
+
failed = false
|
84
|
+
end
|
85
|
+
fail('Element that was not either an attribute or association was allowed') if failed
|
86
|
+
end
|
87
|
+
|
88
|
+
it ('should all unknown element when not in strict mode') do
|
89
|
+
parser
|
90
|
+
.begin('book')
|
91
|
+
.begin('bogus').content('1').end('bogus')
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
context 'when parsing associations' do
|
96
|
+
let (:parser) { DataActive::Parser.new('book') }
|
97
|
+
|
98
|
+
it ('will parse until it gets to the first element') do
|
99
|
+
parser
|
100
|
+
.begin('library')
|
101
|
+
.begin('id').content('1').end('id')
|
102
|
+
.begin('book')
|
103
|
+
.begin('id').content('1').end('id')
|
104
|
+
.end('book')
|
105
|
+
.end('library')
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
it ('will get upset about mismatched tags') do
|
110
|
+
parser
|
111
|
+
.begin('book')
|
112
|
+
.begin('id').content('1').end('id')
|
113
|
+
|
114
|
+
failed = true
|
115
|
+
begin
|
116
|
+
parser.end('chapter')
|
117
|
+
rescue
|
118
|
+
failed = false
|
119
|
+
end
|
120
|
+
|
121
|
+
fail('Allowed mismatched tags') if failed
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
it ('should parse all associations known and unknown') do
|
126
|
+
parser.options << :create
|
127
|
+
parser
|
128
|
+
.begin('book')
|
129
|
+
.begin('id').content('1').end('id')
|
130
|
+
.begin('name').content('Past, now and future').end('name')
|
131
|
+
.begin('chapter')
|
132
|
+
.begin('id').content('2').end('id')
|
133
|
+
.begin('title').content('20/20 hindsight').end('title')
|
134
|
+
.end('chapter')
|
135
|
+
.begin('appendix')
|
136
|
+
.begin('id').content('3').end('id')
|
137
|
+
.begin('name').content('Appendix A - Swimming Rules').end('name')
|
138
|
+
.begin('body').content('some swimming rules').end('body')
|
139
|
+
.end('appendix')
|
140
|
+
.begin('chapter')
|
141
|
+
.begin('id').content('3').end('id')
|
142
|
+
.begin('title').content('The future').end('title')
|
143
|
+
.end('chapter')
|
144
|
+
.end('book')
|
145
|
+
end
|
146
|
+
|
147
|
+
it ('should update :has_many associations with existing parent') do
|
148
|
+
parser.options << :create
|
149
|
+
parser.options << :update
|
150
|
+
|
151
|
+
parser
|
152
|
+
.begin('book')
|
153
|
+
.begin('name').content('101 Testing again').end('name')
|
154
|
+
.end('book')
|
155
|
+
|
156
|
+
books = Book.all
|
157
|
+
|
158
|
+
parser = DataActive::Parser.new('book')
|
159
|
+
parser.options << :create
|
160
|
+
parser.options << :update
|
161
|
+
|
162
|
+
parser
|
163
|
+
.begin('book')
|
164
|
+
.begin('id').content(books[0].id).end('id')
|
165
|
+
.begin('name').content('Past, now and future').end('name')
|
166
|
+
.begin('chapter')
|
167
|
+
.begin('id').content('2').end('id')
|
168
|
+
.begin('title').content('20/20 hindsight').end('title')
|
169
|
+
.end('chapter')
|
170
|
+
.begin('chapter')
|
171
|
+
.begin('id').content('3').end('id')
|
172
|
+
.begin('title').content('The future').end('title')
|
173
|
+
.end('chapter')
|
174
|
+
.end('book')
|
175
|
+
|
176
|
+
books = Book.all
|
177
|
+
books.count.should eq 1
|
178
|
+
chapters = Chapter.all
|
179
|
+
chapters.count.should eq 2
|
180
|
+
chapters[0].book_id.should eq books[0].id
|
181
|
+
chapters[1].book_id.should eq books[0].id
|
182
|
+
end
|
183
|
+
|
184
|
+
it ('should update :has_many associations') do
|
185
|
+
parser.options << :create
|
186
|
+
|
187
|
+
parser
|
188
|
+
.begin('book')
|
189
|
+
.begin('id').content('1').end('id')
|
190
|
+
.begin('name').content('Past, now and future').end('name')
|
191
|
+
.begin('chapter')
|
192
|
+
.begin('id').content('2').end('id')
|
193
|
+
.begin('title').content('20/20 hindsight').end('title')
|
194
|
+
.end('chapter')
|
195
|
+
.begin('chapter')
|
196
|
+
.begin('id').content('3').end('id')
|
197
|
+
.begin('title').content('The future').end('title')
|
198
|
+
.end('chapter')
|
199
|
+
.end('book')
|
200
|
+
|
201
|
+
books = Book.all
|
202
|
+
books.count.should eq 1
|
203
|
+
chapters = Chapter.all
|
204
|
+
chapters.count.should eq 2
|
205
|
+
chapters[0].book_id.should eq books[0].id
|
206
|
+
chapters[1].book_id.should eq books[0].id
|
207
|
+
end
|
208
|
+
|
209
|
+
it ('should update :has_one associations with existing parent') do
|
210
|
+
parser.options << :create
|
211
|
+
parser.options << :update
|
212
|
+
|
213
|
+
parser
|
214
|
+
.begin('book')
|
215
|
+
.begin('name').content('101 Testing again').end('name')
|
216
|
+
.end('book')
|
217
|
+
|
218
|
+
books = Book.all
|
219
|
+
|
220
|
+
parser = DataActive::Parser.new('book')
|
221
|
+
parser.options << :create
|
222
|
+
parser.options << :update
|
223
|
+
|
224
|
+
parser
|
225
|
+
.begin('book')
|
226
|
+
.begin('id').content(books[0].id).end('id')
|
227
|
+
.begin('name').content('Past, now and future').end('name')
|
228
|
+
.begin('book_price')
|
229
|
+
.begin('id').content('2').end('id')
|
230
|
+
.begin('educational').content('10.0').end('educational')
|
231
|
+
.end('book_price')
|
232
|
+
.end('book')
|
233
|
+
|
234
|
+
books = Book.all
|
235
|
+
books.count.should eq 1
|
236
|
+
book_prices = BookPrice.all
|
237
|
+
book_prices.count.should eq 1
|
238
|
+
book_prices[0].book_id.should eq books[0].id
|
239
|
+
end
|
240
|
+
|
241
|
+
it ('should update :has_one associations') do
|
242
|
+
parser.options << :create
|
243
|
+
parser
|
244
|
+
.begin('book')
|
245
|
+
.begin('id').content('1').end('id')
|
246
|
+
.begin('name').content('Past, now and future').end('name')
|
247
|
+
.begin('book_price')
|
248
|
+
.begin('id').content('2').end('id')
|
249
|
+
.begin('educational').content('10.0').end('educational')
|
250
|
+
.end('book_price')
|
251
|
+
.end('book')
|
252
|
+
|
253
|
+
books = Book.all
|
254
|
+
books.count.should eq 1
|
255
|
+
book_prices = BookPrice.all
|
256
|
+
book_prices.count.should eq 1
|
257
|
+
book_prices[0].book_id.should eq books[0].id
|
258
|
+
end
|
259
|
+
|
260
|
+
it ('should parse only known associations when in strict mode') do
|
261
|
+
parser.options << :strict
|
262
|
+
|
263
|
+
parser
|
264
|
+
.begin('book')
|
265
|
+
.begin('id').content('1').end('id')
|
266
|
+
.begin('chapter')
|
267
|
+
.begin('id').content('2').end('id')
|
268
|
+
.begin('title').content('20/20 hindsight').end('title')
|
269
|
+
.end('chapter')
|
270
|
+
|
271
|
+
failed = true
|
272
|
+
begin
|
273
|
+
parser
|
274
|
+
.begin('appendix')
|
275
|
+
.begin('id').content('3').end('id')
|
276
|
+
.begin('name').content('Appendix A - Swimming Rules').end('name')
|
277
|
+
.begin('body').content('some swimming rules').end('body')
|
278
|
+
rescue
|
279
|
+
failed = false
|
280
|
+
end
|
281
|
+
fail('Element that was not either an attribute or association was allowed') if failed
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
end
|