|
19 | 19 | end |
20 | 20 |
|
21 | 21 | it "generates the xml" do |
22 | | - expect(subject.perform).to eq( |
23 | | - <<~TEXT |
24 | | - <?xml version="1.0"?> |
25 | | - <cmes> |
26 | | - <content_provider name="#{provider1.name}"> |
27 | | - <topic_year year="#{topic1.published_at.year}"> |
28 | | - <topic_month month="#{topic1.published_at.strftime("%m_%B")}"> |
29 | | - <title name="#{topic1.title}"> |
30 | | - <topic_id>#{topic1.id}</topic_id> |
31 | | - <topic_files files="Files"/> |
32 | | - <topic_tags>#{topic1.current_tags_list.join(", ")}</topic_tags> |
33 | | - </title> |
34 | | - </topic_month> |
35 | | - </topic_year> |
36 | | - </content_provider> |
37 | | - <content_provider name="#{provider2.name}"> |
38 | | - <topic_year year="#{topic2.published_at.year}"> |
39 | | - <topic_month month="#{topic2.published_at.strftime("%m_%B")}"> |
40 | | - <title name="#{topic2.title}"> |
41 | | - <topic_id>#{topic2.id}</topic_id> |
42 | | - <topic_files files="Files"> |
43 | | - <file_name_1 file_size="494323">test_image.png</file_name_1> |
44 | | - </topic_files> |
45 | | - <topic_tags>#{topic2.current_tags_list.join(", ")}</topic_tags> |
46 | | - </title> |
47 | | - </topic_month> |
48 | | - </topic_year> |
49 | | - </content_provider> |
50 | | - </cmes> |
51 | | - TEXT |
52 | | - ) |
| 22 | + xml = subject.perform |
| 23 | + doc = Nokogiri::XML(xml) |
| 24 | + |
| 25 | + [provider1, provider2].each do |prov| |
| 26 | + pnode = doc.at_xpath("//cmes/content_provider[@name='#{prov.name}']") |
| 27 | + expect(pnode).to be_present |
| 28 | + end |
| 29 | + |
| 30 | + [[provider1, topic1], [provider2, topic2]].each do |prov, topic| |
| 31 | + pnode = doc.at_xpath("//cmes/content_provider[@name='#{prov.name}']") |
| 32 | + year = topic.published_at.year |
| 33 | + ynode = pnode.at_xpath("./topic_year[@year='#{year}']") |
| 34 | + expect(ynode).to be_present |
| 35 | + |
| 36 | + month_label = topic.published_at.strftime('%m_%B') |
| 37 | + mnode = ynode.at_xpath("./topic_month[@month='#{month_label}']") |
| 38 | + expect(mnode).to be_present |
| 39 | + |
| 40 | + tnode = mnode.at_xpath("./title[@name='#{topic.title}']") |
| 41 | + expect(tnode).to be_present |
| 42 | + |
| 43 | + expect(tnode.at_xpath('./topic_id').text).to eq(topic.id.to_s) |
| 44 | + expect(tnode.at_xpath('./counter').text).to eq('0') |
| 45 | + expect(tnode.at_xpath('./topic_volume').text).to eq(topic.published_at.year.to_s) |
| 46 | + expect(tnode.at_xpath('./topic_issue').text).to eq(topic.published_at.month.to_s) |
| 47 | + |
| 48 | + files = tnode.at_xpath("./topic_files[@files='Files']") |
| 49 | + expect(files).to be_present |
| 50 | + if topic.documents.attached? && topic.documents.reject { |d| d.content_type == 'video/mp4' }.any? |
| 51 | + first_file = files.element_children.first |
| 52 | + expect(first_file).to be_present |
| 53 | + expect(first_file.text).to be_present |
| 54 | + expect(first_file['file_size']).to be_present |
| 55 | + else |
| 56 | + expect(files.element_children).to be_empty |
| 57 | + end |
| 58 | + |
| 59 | + author1 = tnode.at_xpath('./topic_author/topic_author_1') |
| 60 | + expect(author1.text).to eq(' ') |
| 61 | + |
| 62 | + expect(tnode.at_xpath('./topic_tags').text).to eq(topic.current_tags_list.join(', ')) |
| 63 | + end |
53 | 64 | end |
54 | 65 | end |
0 commit comments