feedjira 2.0.0 → 2.2.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/.gitignore +2 -0
- data/.rubocop.yml +15 -0
- data/.travis.yml +31 -12
- data/CHANGELOG.md +34 -1
- data/Dangerfile +1 -0
- data/Gemfile +2 -1
- data/LICENSE +1 -1
- data/README.md +210 -7
- data/Rakefile +11 -1
- data/feedjira.gemspec +17 -14
- data/fixtures/vcr_cassettes/fetch_failure.yml +62 -0
- data/fixtures/vcr_cassettes/parse_error.yml +222 -0
- data/fixtures/vcr_cassettes/success.yml +281 -0
- data/lib/feedjira/configuration.rb +76 -0
- data/lib/feedjira/core_ext/date.rb +3 -1
- data/lib/feedjira/core_ext/string.rb +2 -1
- data/lib/feedjira/core_ext/time.rb +24 -17
- data/lib/feedjira/core_ext.rb +3 -3
- data/lib/feedjira/date_time_utilities/date_time_epoch_parser.rb +13 -0
- data/lib/feedjira/date_time_utilities/date_time_language_parser.rb +24 -0
- data/lib/feedjira/date_time_utilities/date_time_pattern_parser.rb +34 -0
- data/lib/feedjira/date_time_utilities.rb +32 -0
- data/lib/feedjira/feed.rb +89 -62
- data/lib/feedjira/feed_entry_utilities.rb +20 -19
- data/lib/feedjira/feed_utilities.rb +37 -22
- data/lib/feedjira/parser/atom.rb +10 -8
- data/lib/feedjira/parser/atom_entry.rb +11 -13
- data/lib/feedjira/parser/atom_feed_burner.rb +27 -10
- data/lib/feedjira/parser/atom_feed_burner_entry.rb +12 -14
- data/lib/feedjira/parser/atom_youtube.rb +21 -0
- data/lib/feedjira/parser/atom_youtube_entry.rb +30 -0
- data/lib/feedjira/parser/google_docs_atom.rb +8 -7
- data/lib/feedjira/parser/google_docs_atom_entry.rb +13 -11
- data/lib/feedjira/parser/itunes_rss.rb +41 -22
- data/lib/feedjira/parser/itunes_rss_category.rb +39 -0
- data/lib/feedjira/parser/itunes_rss_item.rb +32 -20
- data/lib/feedjira/parser/itunes_rss_owner.rb +4 -4
- data/lib/feedjira/parser/podlove_chapter.rb +22 -0
- data/lib/feedjira/parser/rss.rb +11 -8
- data/lib/feedjira/parser/rss_entry.rb +17 -21
- data/lib/feedjira/parser/rss_feed_burner.rb +5 -6
- data/lib/feedjira/parser/rss_feed_burner_entry.rb +24 -28
- data/lib/feedjira/parser/rss_image.rb +15 -0
- data/lib/feedjira/parser.rb +1 -1
- data/lib/feedjira/preprocessor.rb +4 -2
- data/lib/feedjira/version.rb +1 -1
- data/lib/feedjira.rb +15 -0
- data/spec/feedjira/configuration_spec.rb +25 -0
- data/spec/feedjira/date_time_utilities_spec.rb +47 -0
- data/spec/feedjira/feed_entry_utilities_spec.rb +23 -19
- data/spec/feedjira/feed_spec.rb +140 -75
- data/spec/feedjira/feed_utilities_spec.rb +83 -63
- data/spec/feedjira/parser/atom_entry_spec.rb +54 -34
- data/spec/feedjira/parser/atom_feed_burner_entry_spec.rb +27 -20
- data/spec/feedjira/parser/atom_feed_burner_spec.rb +87 -30
- data/spec/feedjira/parser/atom_spec.rb +50 -48
- data/spec/feedjira/parser/atom_youtube_entry_spec.rb +86 -0
- data/spec/feedjira/parser/atom_youtube_spec.rb +43 -0
- data/spec/feedjira/parser/google_docs_atom_entry_spec.rb +5 -4
- data/spec/feedjira/parser/google_docs_atom_spec.rb +6 -6
- data/spec/feedjira/parser/itunes_rss_item_spec.rb +49 -29
- data/spec/feedjira/parser/itunes_rss_owner_spec.rb +10 -9
- data/spec/feedjira/parser/itunes_rss_spec.rb +87 -30
- data/spec/feedjira/parser/podlove_chapter_spec.rb +37 -0
- data/spec/feedjira/parser/rss_entry_spec.rb +50 -33
- data/spec/feedjira/parser/rss_feed_burner_entry_spec.rb +55 -33
- data/spec/feedjira/parser/rss_feed_burner_spec.rb +31 -26
- data/spec/feedjira/parser/rss_spec.rb +56 -24
- data/spec/feedjira/preprocessor_spec.rb +11 -3
- data/spec/sample_feeds/AmazonWebServicesBlog.xml +797 -797
- data/spec/sample_feeds/AtomEscapedHTMLInPreTag.xml +13 -0
- data/spec/sample_feeds/CRE.xml +5849 -0
- data/spec/sample_feeds/FeedBurnerXHTML.xml +400 -400
- data/spec/sample_feeds/GiantRobotsSmashingIntoOtherGiantRobots.xml +682 -0
- data/spec/sample_feeds/ITunesWithSingleQuotedAttributes.xml +67 -0
- data/spec/sample_feeds/InvalidDateFormat.xml +20 -0
- data/spec/sample_feeds/PaulDixExplainsNothing.xml +175 -175
- data/spec/sample_feeds/PaulDixExplainsNothingAlternate.xml +175 -175
- data/spec/sample_feeds/PaulDixExplainsNothingFirstEntryContent.xml +16 -16
- data/spec/sample_feeds/PaulDixExplainsNothingWFW.xml +174 -174
- data/spec/sample_feeds/TenderLovemaking.xml +12 -2
- data/spec/sample_feeds/TrotterCashionHome.xml +611 -611
- data/spec/sample_feeds/TypePadNews.xml +368 -368
- data/spec/sample_feeds/itunes.xml +31 -2
- data/spec/sample_feeds/pet_atom.xml +229 -229
- data/spec/sample_feeds/youtube_atom.xml +395 -0
- data/spec/sample_feeds.rb +31 -21
- data/spec/spec_helper.rb +6 -0
- metadata +132 -25
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Feedjira::FeedUtilities do
|
4
4
|
before(:each) do
|
@@ -8,47 +8,64 @@ describe Feedjira::FeedUtilities do
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
describe
|
12
|
-
context
|
13
|
-
it
|
11
|
+
describe 'preprocessing' do
|
12
|
+
context 'when the flag is not set' do
|
13
|
+
it 'does not call the preprocessing method' do
|
14
14
|
@klass.preprocess_xml = false
|
15
15
|
expect(@klass).to_not receive :preprocess
|
16
16
|
@klass.parse sample_rss_feed
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
context
|
21
|
-
it
|
20
|
+
context 'when the flag is set' do
|
21
|
+
it 'calls the preprocessing method' do
|
22
22
|
@klass.preprocess_xml = true
|
23
|
-
expect(@klass).to receive(:preprocess).
|
24
|
-
and_return sample_rss_feed
|
23
|
+
expect(@klass).to receive(:preprocess).and_return sample_rss_feed
|
25
24
|
@klass.parse sample_rss_feed
|
26
25
|
end
|
27
26
|
end
|
28
27
|
end
|
29
28
|
|
30
|
-
describe
|
31
|
-
|
29
|
+
describe 'strip whitespace' do
|
30
|
+
context 'strip_whitespace config is true' do
|
31
|
+
it 'strips all XML whitespace' do
|
32
|
+
Feedjira.configure { |config| config.strip_whitespace = true }
|
33
|
+
|
34
|
+
expect(@klass.strip_whitespace("\nfoobar\n")).to eq('foobar')
|
35
|
+
|
36
|
+
Feedjira.configure { |config| config.strip_whitespace = false }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'strip_whitespace config is false' do
|
41
|
+
it 'lstrips XML whitespace' do
|
42
|
+
expect(@klass.strip_whitespace("\nfoobar\n")).to eq("foobar\n")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe 'instance methods' do
|
48
|
+
it 'should provide an updated? accessor' do
|
32
49
|
feed = @klass.new
|
33
50
|
expect(feed).to_not be_updated
|
34
51
|
feed.updated = true
|
35
52
|
expect(feed).to be_updated
|
36
53
|
end
|
37
54
|
|
38
|
-
it
|
55
|
+
it 'should provide a new_entries accessor' do
|
39
56
|
feed = @klass.new
|
40
57
|
expect(feed.new_entries).to eq []
|
41
58
|
feed.new_entries = [:foo]
|
42
59
|
expect(feed.new_entries).to eq [:foo]
|
43
60
|
end
|
44
61
|
|
45
|
-
it
|
62
|
+
it 'should provide an etag accessor' do
|
46
63
|
feed = @klass.new
|
47
|
-
feed.etag =
|
48
|
-
expect(feed.etag).to eq
|
64
|
+
feed.etag = 'foo'
|
65
|
+
expect(feed.etag).to eq 'foo'
|
49
66
|
end
|
50
67
|
|
51
|
-
it
|
68
|
+
it 'should provide a last_modified accessor' do
|
52
69
|
feed = @klass.new
|
53
70
|
time = Time.now
|
54
71
|
feed.last_modified = time
|
@@ -56,21 +73,21 @@ describe Feedjira::FeedUtilities do
|
|
56
73
|
expect(feed.last_modified.class).to eq Time
|
57
74
|
end
|
58
75
|
|
59
|
-
it
|
76
|
+
it 'should return new_entries? as true when entries are put into new_entries' do # rubocop:disable Metrics/LineLength
|
60
77
|
feed = @klass.new
|
61
78
|
feed.new_entries << :foo
|
62
|
-
expect(feed).to
|
79
|
+
expect(feed.new_entries?).to eq true
|
63
80
|
end
|
64
81
|
|
65
|
-
it "should return a last_modified value from the entry with the most recent published date if the last_modified date hasn't been set" do
|
82
|
+
it "should return a last_modified value from the entry with the most recent published date if the last_modified date hasn't been set" do # rubocop:disable Metrics/LineLength
|
66
83
|
feed = Feedjira::Parser::Atom.new
|
67
|
-
entry =Feedjira::Parser::AtomEntry.new
|
84
|
+
entry = Feedjira::Parser::AtomEntry.new
|
68
85
|
entry.published = Time.now.to_s
|
69
86
|
feed.entries << entry
|
70
87
|
expect(feed.last_modified).to eq entry.published
|
71
88
|
end
|
72
89
|
|
73
|
-
it
|
90
|
+
it 'should not throw an error if one of the entries has published date of nil' do # rubocop:disable Metrics/LineLength
|
74
91
|
feed = Feedjira::Parser::Atom.new
|
75
92
|
entry = Feedjira::Parser::AtomEntry.new
|
76
93
|
entry.published = Time.now.to_s
|
@@ -80,122 +97,125 @@ describe Feedjira::FeedUtilities do
|
|
80
97
|
end
|
81
98
|
end
|
82
99
|
|
83
|
-
describe
|
84
|
-
describe
|
100
|
+
describe '#update_from_feed' do
|
101
|
+
describe 'updating feed attributes' do
|
85
102
|
before(:each) do
|
86
|
-
# I'm using the Atom class when I know I should be using a different
|
87
|
-
# method would only be called
|
103
|
+
# I'm using the Atom class when I know I should be using a different
|
104
|
+
# one. However, this update_from_feed method would only be called
|
105
|
+
# against a feed item.
|
88
106
|
@feed = Feedjira::Parser::Atom.new
|
89
|
-
@feed.title =
|
90
|
-
@feed.url =
|
91
|
-
@feed.feed_url =
|
107
|
+
@feed.title = 'A title'
|
108
|
+
@feed.url = 'http://pauldix.net'
|
109
|
+
@feed.feed_url = 'http://feeds.feedburner.com/PaulDixExplainsNothing'
|
92
110
|
@feed.updated = false
|
93
111
|
@updated_feed = @feed.dup
|
94
112
|
end
|
95
113
|
|
96
|
-
it
|
97
|
-
@updated_feed.title =
|
114
|
+
it 'should update the title if changed' do
|
115
|
+
@updated_feed.title = 'new title'
|
98
116
|
@feed.update_from_feed(@updated_feed)
|
99
117
|
expect(@feed.title).to eq @updated_feed.title
|
100
118
|
expect(@feed).to be_updated
|
101
119
|
end
|
102
120
|
|
103
|
-
it
|
121
|
+
it 'should not update the title if the same' do
|
104
122
|
@feed.update_from_feed(@updated_feed)
|
105
123
|
expect(@feed).to_not be_updated
|
106
124
|
end
|
107
125
|
|
108
|
-
it
|
109
|
-
@updated_feed.feed_url =
|
126
|
+
it 'should update the feed_url if changed' do
|
127
|
+
@updated_feed.feed_url = 'a new feed url'
|
110
128
|
@feed.update_from_feed(@updated_feed)
|
111
129
|
expect(@feed.feed_url).to eq @updated_feed.feed_url
|
112
130
|
expect(@feed).to be_updated
|
113
131
|
end
|
114
132
|
|
115
|
-
it
|
133
|
+
it 'should not update the feed_url if the same' do
|
116
134
|
@feed.update_from_feed(@updated_feed)
|
117
135
|
expect(@feed).to_not be_updated
|
118
136
|
end
|
119
137
|
|
120
|
-
it
|
121
|
-
@updated_feed.url =
|
138
|
+
it 'should update the url if changed' do
|
139
|
+
@updated_feed.url = 'a new url'
|
122
140
|
@feed.update_from_feed(@updated_feed)
|
123
141
|
expect(@feed.url).to eq @updated_feed.url
|
124
142
|
end
|
125
143
|
|
126
|
-
it
|
144
|
+
it 'should not update the url if not changed' do
|
127
145
|
@feed.update_from_feed(@updated_feed)
|
128
146
|
expect(@feed).to_not be_updated
|
129
147
|
end
|
130
148
|
end
|
131
149
|
|
132
|
-
describe
|
150
|
+
describe 'updating entries' do
|
133
151
|
before(:each) do
|
134
|
-
# I'm using the Atom class when I know I should be using a different
|
135
|
-
# method would only be called
|
152
|
+
# I'm using the Atom class when I know I should be using a different
|
153
|
+
# one. However, this update_from_feed method would only be called
|
154
|
+
# against a feed item.
|
136
155
|
@feed = Feedjira::Parser::Atom.new
|
137
|
-
@feed.title =
|
138
|
-
@feed.url =
|
139
|
-
@feed.feed_url =
|
156
|
+
@feed.title = 'A title'
|
157
|
+
@feed.url = 'http://pauldix.net'
|
158
|
+
@feed.feed_url = 'http://feeds.feedburner.com/PaulDixExplainsNothing'
|
140
159
|
@feed.updated = false
|
141
160
|
@updated_feed = @feed.dup
|
142
161
|
@old_entry = Feedjira::Parser::AtomEntry.new
|
143
|
-
@old_entry.url =
|
162
|
+
@old_entry.url = 'http://pauldix.net/old.html'
|
144
163
|
@old_entry.published = Time.now.to_s
|
145
|
-
@old_entry.entry_id =
|
164
|
+
@old_entry.entry_id = 'entry_id_old'
|
146
165
|
@new_entry = Feedjira::Parser::AtomEntry.new
|
147
|
-
@new_entry.url =
|
166
|
+
@new_entry.url = 'http://pauldix.net/new.html'
|
148
167
|
@new_entry.published = (Time.now + 10).to_s
|
149
|
-
@new_entry.entry_id =
|
168
|
+
@new_entry.entry_id = 'entry_id_new'
|
150
169
|
@feed.entries << @old_entry
|
151
170
|
@updated_feed.entries << @new_entry
|
152
171
|
@updated_feed.entries << @old_entry
|
153
172
|
end
|
154
173
|
|
155
|
-
it
|
174
|
+
it 'should update last-modified from the latest entry date' do
|
156
175
|
@feed.update_from_feed(@updated_feed)
|
157
176
|
expect(@feed.last_modified).to eq @new_entry.published
|
158
177
|
end
|
159
178
|
|
160
|
-
it
|
179
|
+
it 'should put new entries into new_entries' do
|
161
180
|
@feed.update_from_feed(@updated_feed)
|
162
181
|
expect(@feed.new_entries).to eq [@new_entry]
|
163
182
|
end
|
164
183
|
|
165
|
-
it
|
184
|
+
it 'should also put new entries into the entries collection' do
|
166
185
|
@feed.update_from_feed(@updated_feed)
|
167
186
|
expect(@feed.entries).to include(@new_entry)
|
168
187
|
expect(@feed.entries).to include(@old_entry)
|
169
188
|
end
|
170
189
|
end
|
171
190
|
|
172
|
-
describe
|
191
|
+
describe '#update_from_feed' do
|
173
192
|
let(:recent_entry_id) { 'entry_id' }
|
174
193
|
let(:old_entry_id) { nil }
|
175
194
|
|
176
195
|
before(:each) do
|
177
|
-
# I'm using the Atom class when I know I should be using a different
|
178
|
-
# method would only be called
|
196
|
+
# I'm using the Atom class when I know I should be using a different
|
197
|
+
# one. However, this update_from_feed method would only be called
|
198
|
+
# against a feed item.
|
179
199
|
@feed = Feedjira::Parser::Atom.new
|
180
|
-
@feed.title =
|
181
|
-
@feed.url =
|
182
|
-
@feed.feed_url =
|
200
|
+
@feed.title = 'A title'
|
201
|
+
@feed.url = 'http://pauldix.net'
|
202
|
+
@feed.feed_url = 'http://feeds.feedburner.com/PaulDixExplainsNothing'
|
183
203
|
@feed.updated = false
|
184
204
|
@updated_feed = @feed.dup
|
185
205
|
|
186
206
|
@old_entry = Feedjira::Parser::AtomEntry.new
|
187
|
-
@old_entry.url =
|
207
|
+
@old_entry.url = 'http://pauldix.net/old.html'
|
188
208
|
@old_entry.entry_id = old_entry_id
|
189
209
|
@old_entry.published = (Time.now - 10).to_s
|
190
210
|
|
191
211
|
@entry = Feedjira::Parser::AtomEntry.new
|
192
212
|
@entry.published = (Time.now + 10).to_s
|
193
213
|
@entry.entry_id = recent_entry_id
|
194
|
-
@entry.url =
|
214
|
+
@entry.url = 'http://pauldix.net/entry.html'
|
195
215
|
|
196
216
|
# only difference is a changed url
|
197
217
|
@entry_changed_url = @entry.dup
|
198
|
-
@entry_changed_url.url =
|
218
|
+
@entry_changed_url.url = 'http://pauldix.net/updated.html'
|
199
219
|
|
200
220
|
# entry with changed url must be first
|
201
221
|
@feed.entries << @entry
|
@@ -204,8 +224,8 @@ describe Feedjira::FeedUtilities do
|
|
204
224
|
@updated_feed.entries << @old_entry
|
205
225
|
end
|
206
226
|
|
207
|
-
context
|
208
|
-
it
|
227
|
+
context 'changing the url of an existing entry' do
|
228
|
+
it 'should not put the complete feed into new_entries' do
|
209
229
|
@feed.update_from_feed(@updated_feed)
|
210
230
|
expect(@feed.new_entries).to_not include(@entry_changed_url)
|
211
231
|
expect(@feed.new_entries).to_not include(@old_entry)
|
@@ -214,11 +234,11 @@ describe Feedjira::FeedUtilities do
|
|
214
234
|
end
|
215
235
|
end
|
216
236
|
|
217
|
-
context
|
237
|
+
context 'feed not have entry id and only difference is a url' do
|
218
238
|
let(:recent_entry_id) { nil }
|
219
239
|
let(:old_entry_id) { nil }
|
220
240
|
|
221
|
-
it
|
241
|
+
it 'should put the complete feed into new_entries' do
|
222
242
|
@feed.update_from_feed(@updated_feed)
|
223
243
|
expect(@feed.new_entries).to include(@entry_changed_url)
|
224
244
|
expect(@feed.new_entries).to include(@old_entry)
|
@@ -242,7 +262,7 @@ describe Feedjira::FeedUtilities do
|
|
242
262
|
let(:feed_two) { double 'Feed Two', entries: [entry_two] }
|
243
263
|
|
244
264
|
before do
|
245
|
-
stub_const(
|
265
|
+
stub_const('Feedjira::FeedUtilities::UPDATABLE_ATTRIBUTES', [])
|
246
266
|
feed_one.entries << entry_one
|
247
267
|
end
|
248
268
|
|
@@ -1,58 +1,64 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Feedjira::Parser::AtomEntry do
|
4
4
|
before(:each) do
|
5
|
-
# I don't really like doing it this way because these unit test should only
|
6
|
-
# but this is actually how it should work. You would
|
5
|
+
# I don't really like doing it this way because these unit test should only
|
6
|
+
# rely on AtomEntry, but this is actually how it should work. You would
|
7
|
+
# never just pass entry xml straight to the AtomEnry
|
7
8
|
@entry = Feedjira::Parser::Atom.parse(sample_atom_feed).entries.first
|
8
9
|
end
|
9
10
|
|
10
|
-
it
|
11
|
-
|
11
|
+
it 'should parse the title' do
|
12
|
+
title = 'AWS Job: Architect & Designer Position in Turkey'
|
13
|
+
expect(@entry.title).to eq title
|
12
14
|
end
|
13
15
|
|
14
|
-
it
|
15
|
-
expect(@entry.url).to eq
|
16
|
+
it 'should parse the url' do
|
17
|
+
expect(@entry.url).to eq 'http://aws.typepad.com/aws/2009/01/aws-job-architect-designer-position-in-turkey.html'
|
16
18
|
end
|
17
19
|
|
18
|
-
it
|
19
|
-
|
20
|
-
|
20
|
+
it 'should parse the url even when' do
|
21
|
+
xml = load_sample('atom_with_link_tag_for_url_unmarked.xml')
|
22
|
+
entries = Feedjira::Parser::Atom.parse(xml).entries
|
23
|
+
expect(entries.first.url).to eq 'http://www.innoq.com/blog/phaus/2009/07/ja.html'
|
21
24
|
end
|
22
25
|
|
23
|
-
it
|
24
|
-
expect(@entry.author).to eq
|
26
|
+
it 'should parse the author' do
|
27
|
+
expect(@entry.author).to eq 'AWS Editor'
|
25
28
|
end
|
26
29
|
|
27
|
-
it
|
30
|
+
it 'should parse the content' do
|
28
31
|
expect(@entry.content).to eq sample_atom_entry_content
|
29
32
|
end
|
30
33
|
|
31
|
-
it
|
32
|
-
|
34
|
+
it 'should provide a summary' do
|
35
|
+
summary = "Late last year an entrepreneur from Turkey visited me at Amazon HQ in Seattle. We talked about his plans to use AWS as part of his new social video portal startup. I won't spill any beans before he's ready to..." # rubocop:disable Metrics/LineLength
|
36
|
+
expect(@entry.summary).to eq summary
|
33
37
|
end
|
34
38
|
|
35
|
-
it
|
36
|
-
|
39
|
+
it 'should parse the published date' do
|
40
|
+
published = Time.parse_safely 'Fri Jan 16 18:21:00 UTC 2009'
|
41
|
+
expect(@entry.published).to eq published
|
37
42
|
end
|
38
43
|
|
39
|
-
it
|
40
|
-
expect(@entry.categories).to eq
|
44
|
+
it 'should parse the categories' do
|
45
|
+
expect(@entry.categories).to eq %w(Turkey Seattle)
|
41
46
|
end
|
42
47
|
|
43
|
-
it
|
44
|
-
|
48
|
+
it 'should parse the updated date' do
|
49
|
+
updated = Time.parse_safely 'Fri Jan 16 18:21:00 UTC 2009'
|
50
|
+
expect(@entry.updated).to eq updated
|
45
51
|
end
|
46
52
|
|
47
|
-
it
|
48
|
-
expect(@entry.id).to eq
|
53
|
+
it 'should parse the id' do
|
54
|
+
expect(@entry.id).to eq 'tag:typepad.com,2003:post-61484736'
|
49
55
|
end
|
50
56
|
|
51
|
-
it
|
57
|
+
it 'should support each' do
|
52
58
|
expect(@entry).to respond_to :each
|
53
59
|
end
|
54
60
|
|
55
|
-
it
|
61
|
+
it 'should be able to list out all fields with each' do
|
56
62
|
all_fields = []
|
57
63
|
title_value = ''
|
58
64
|
|
@@ -61,22 +67,36 @@ describe Feedjira::Parser::AtomEntry do
|
|
61
67
|
title_value = value if field == 'title'
|
62
68
|
end
|
63
69
|
|
64
|
-
expect(
|
65
|
-
|
70
|
+
expect(title_value).to eq 'AWS Job: Architect & Designer Position in Turkey'
|
71
|
+
|
72
|
+
expected_fields = %w(
|
73
|
+
author
|
74
|
+
categories
|
75
|
+
content
|
76
|
+
entry_id
|
77
|
+
links
|
78
|
+
published
|
79
|
+
summary
|
80
|
+
title
|
81
|
+
updated
|
82
|
+
url
|
83
|
+
)
|
84
|
+
expect(all_fields.sort).to eq expected_fields
|
66
85
|
end
|
67
86
|
|
68
|
-
it
|
87
|
+
it 'should support checking if a field exists in the entry' do
|
69
88
|
expect(@entry).to include 'author'
|
70
89
|
expect(@entry).to include 'title'
|
71
90
|
end
|
72
91
|
|
73
|
-
it
|
74
|
-
|
75
|
-
expect(@entry['
|
92
|
+
it 'should allow access to fields with hash syntax' do
|
93
|
+
title = 'AWS Job: Architect & Designer Position in Turkey'
|
94
|
+
expect(@entry['title']).to eq title
|
95
|
+
expect(@entry['author']).to eq 'AWS Editor'
|
76
96
|
end
|
77
97
|
|
78
|
-
it
|
79
|
-
@entry['title'] =
|
80
|
-
expect(@entry.title).to eq
|
98
|
+
it 'should allow setting field values with hash syntax' do
|
99
|
+
@entry['title'] = 'Foobar'
|
100
|
+
expect(@entry.title).to eq 'Foobar'
|
81
101
|
end
|
82
102
|
end
|
@@ -1,47 +1,54 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Feedjira::Parser::AtomFeedBurnerEntry do
|
4
4
|
before(:each) do
|
5
|
-
|
6
|
-
#
|
7
|
-
|
5
|
+
Feedjira::Parser::AtomFeedBurner.preprocess_xml = false
|
6
|
+
# I don't really like doing it this way because these unit test should only
|
7
|
+
# rely on AtomEntry, but this is actually how it should work. You would
|
8
|
+
# never just pass entry xml straight to the AtomEnry
|
9
|
+
feed = Feedjira::Parser::AtomFeedBurner.parse sample_feedburner_atom_feed
|
10
|
+
@entry = feed.entries.first
|
8
11
|
end
|
9
12
|
|
10
|
-
it
|
11
|
-
expect(@entry.title).to eq
|
13
|
+
it 'should parse the title' do
|
14
|
+
expect(@entry.title).to eq 'Making a Ruby C library even faster'
|
12
15
|
end
|
13
16
|
|
14
|
-
it "should be able to fetch a url via the 'alternate' rel if no origLink exists" do
|
15
|
-
|
17
|
+
it "should be able to fetch a url via the 'alternate' rel if no origLink exists" do # rubocop:disable Metrics/LineLength
|
18
|
+
xml = File.read("#{File.dirname(__FILE__)}/../../sample_feeds/PaulDixExplainsNothingAlternate.xml") # rubocop:disable Metrics/LineLength
|
19
|
+
entry = Feedjira::Parser::AtomFeedBurner.parse(xml).entries.first
|
16
20
|
expect(entry.url).to eq 'http://feeds.feedburner.com/~r/PaulDixExplainsNothing/~3/519925023/making-a-ruby-c-library-even-faster.html'
|
17
21
|
end
|
18
22
|
|
19
|
-
it
|
20
|
-
expect(@entry.url).to eq
|
23
|
+
it 'should parse the url' do
|
24
|
+
expect(@entry.url).to eq 'http://www.pauldix.net/2009/01/making-a-ruby-c-library-even-faster.html'
|
21
25
|
end
|
22
26
|
|
23
|
-
it
|
24
|
-
|
27
|
+
it 'should parse the url when there is no alternate' do
|
28
|
+
xml = File.read("#{File.dirname(__FILE__)}/../../sample_feeds/FeedBurnerUrlNoAlternate.xml") # rubocop:disable Metrics/LineLength
|
29
|
+
entry = Feedjira::Parser::AtomFeedBurner.parse(xml).entries.first
|
25
30
|
expect(entry.url).to eq 'http://example.com/QQQQ.html'
|
26
31
|
end
|
27
32
|
|
28
|
-
it
|
29
|
-
expect(@entry.author).to eq
|
33
|
+
it 'should parse the author' do
|
34
|
+
expect(@entry.author).to eq 'Paul Dix'
|
30
35
|
end
|
31
36
|
|
32
|
-
it
|
37
|
+
it 'should parse the content' do
|
33
38
|
expect(@entry.content).to eq sample_feedburner_atom_entry_content
|
34
39
|
end
|
35
40
|
|
36
|
-
it
|
37
|
-
|
41
|
+
it 'should provide a summary' do
|
42
|
+
summary = "Last week I released the first version of a SAX based XML parsing library called SAX-Machine. It uses Nokogiri, which uses libxml, so it's pretty fast. However, I felt that it could be even faster. The only question was how..." # rubocop:disable Metrics/LineLength
|
43
|
+
expect(@entry.summary).to eq summary
|
38
44
|
end
|
39
45
|
|
40
|
-
it
|
41
|
-
|
46
|
+
it 'should parse the published date' do
|
47
|
+
published = Time.parse_safely 'Thu Jan 22 15:50:22 UTC 2009'
|
48
|
+
expect(@entry.published).to eq published
|
42
49
|
end
|
43
50
|
|
44
|
-
it
|
51
|
+
it 'should parse the categories' do
|
45
52
|
expect(@entry.categories).to eq ['Ruby', 'Another Category']
|
46
53
|
end
|
47
54
|
end
|