1
0

atom_builder_helper_spec.rb 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. require 'rails_helper'
  2. RSpec.describe AtomBuilderHelper, type: :helper do
  3. describe '#stream_updated_at' do
  4. pending
  5. end
  6. describe '#entry' do
  7. it 'creates an entry' do
  8. expect(used_in_builder { |xml| helper.entry(xml) }).to match '<entry/>'
  9. end
  10. end
  11. describe '#feed' do
  12. it 'creates a feed' do
  13. expect(used_in_builder { |xml| helper.feed(xml) }).to match '<feed xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:poco="http://portablecontacts.net/spec/1.0" xmlns:media="http://purl.org/syndication/atommedia" xmlns:ostatus="http://ostatus.org/schema/1.0"/>'
  14. end
  15. end
  16. describe '#unique_id' do
  17. it 'creates an id' do
  18. time = Time.now
  19. expect(used_in_builder { |xml| helper.unique_id(xml, time, 1, 'Status') }).to match "<id>#{TagManager.instance.unique_tag(time, 1, 'Status')}</id>"
  20. end
  21. end
  22. describe '#simple_id' do
  23. it 'creates an id' do
  24. expect(used_in_builder { |xml| helper.simple_id(xml, 1) }).to match '<id>1</id>'
  25. end
  26. end
  27. describe '#published_at' do
  28. it 'creates a published tag' do
  29. time = Time.now
  30. expect(used_in_builder { |xml| helper.published_at(xml, time) }).to match "<published>#{time.iso8601}</published>"
  31. end
  32. end
  33. describe '#updated_at' do
  34. it 'creates an updated tag' do
  35. time = Time.now
  36. expect(used_in_builder { |xml| helper.updated_at(xml, time) }).to match "<updated>#{time.iso8601}</updated>"
  37. end
  38. end
  39. describe '#verb' do
  40. it 'creates an entry' do
  41. expect(used_with_namespaces { |xml| helper.verb(xml, :post) }).to match '<activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>'
  42. end
  43. end
  44. describe '#content' do
  45. it 'creates a content' do
  46. expect(used_in_builder { |xml| helper.content(xml, 'foo') }).to match '<content type="html">foo</content>'
  47. end
  48. end
  49. describe '#title' do
  50. it 'creates a title' do
  51. expect(used_in_builder { |xml| helper.title(xml, 'foo') }).to match '<title>foo</title>'
  52. end
  53. end
  54. describe '#author' do
  55. it 'creates an author' do
  56. expect(used_in_builder { |xml| helper.author(xml) }).to match '<author/>'
  57. end
  58. end
  59. describe '#target' do
  60. it 'creates a target' do
  61. expect(used_with_namespaces { |xml| helper.target(xml) }).to match '<activity:object/>'
  62. end
  63. end
  64. describe '#object_type' do
  65. it 'creates an object type' do
  66. expect(used_with_namespaces { |xml| helper.object_type(xml, :person) }).to match '<activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>'
  67. end
  68. end
  69. describe '#uri' do
  70. it 'creates a uri' do
  71. expect(used_in_builder { |xml| helper.uri(xml, 1) }).to match '<uri>1</uri>'
  72. end
  73. end
  74. describe '#name' do
  75. it 'creates a name' do
  76. expect(used_in_builder { |xml| helper.name(xml, 1) }).to match '<name>1</name>'
  77. end
  78. end
  79. describe '#summary' do
  80. it 'creates a summary' do
  81. expect(used_in_builder { |xml| helper.summary(xml, 1) }).to match '<summary>1</summary>'
  82. end
  83. end
  84. describe '#subtitle' do
  85. it 'creates a subtitle' do
  86. expect(used_in_builder { |xml| helper.subtitle(xml, 1) }).to match '<subtitle>1</subtitle>'
  87. end
  88. end
  89. describe '#link_alternate' do
  90. it 'creates a link' do
  91. expect(used_in_builder { |xml| helper.link_alternate(xml, 1) }).to match '<link rel="alternate" type="text/html" href="1"/>'
  92. end
  93. end
  94. describe '#link_self' do
  95. it 'creates a link' do
  96. expect(used_in_builder { |xml| helper.link_self(xml, 1) }).to match '<link rel="self" type="application/atom+xml" href="1"/>'
  97. end
  98. end
  99. describe '#link_hub' do
  100. it 'creates a link' do
  101. expect(used_in_builder { |xml| helper.link_hub(xml, 1) }).to match '<link rel="hub" href="1"/>'
  102. end
  103. end
  104. describe '#link_salmon' do
  105. it 'creates a link' do
  106. expect(used_in_builder { |xml| helper.link_salmon(xml, 1) }).to match '<link rel="salmon" href="1"/>'
  107. end
  108. end
  109. describe '#portable_contact' do
  110. let(:account) { Fabricate(:account, username: 'alice', display_name: 'Alice in Wonderland') }
  111. it 'creates portable contacts entries' do
  112. expect(used_with_namespaces { |xml| helper.portable_contact(xml, account) }).to match '<poco:displayName>Alice in Wonderland</poco:displayName>'
  113. end
  114. end
  115. describe '#in_reply_to' do
  116. it 'creates a thread' do
  117. expect(used_with_namespaces { |xml| helper.in_reply_to(xml, 'uri', 'url') }).to match '<thr:in-reply-to ref="uri" href="url" type="text/html"/>'
  118. end
  119. end
  120. describe '#link_mention' do
  121. let(:account) { Fabricate(:account, username: 'alice') }
  122. it 'creates a link' do
  123. expect(used_in_builder { |xml| helper.link_mention(xml, account) }).to match '<link rel="mentioned" href="https://cb6e6126.ngrok.io/users/alice" ostatus:object-type="http://activitystrea.ms/schema/1.0/person"/>'
  124. end
  125. end
  126. describe '#include_author' do
  127. pending
  128. end
  129. describe '#include_entry' do
  130. pending
  131. end
  132. describe '#link_avatar' do
  133. let(:account) { Fabricate(:account, username: 'alice') }
  134. it 'creates a link' do
  135. expect(used_with_namespaces { |xml| helper.link_avatar(xml, account) }).to match '<link rel="avatar" type="" media:width="120" media:height="120" href="http://test.host/avatars/original/missing.png"/>'
  136. end
  137. end
  138. describe '#link_enclosure' do
  139. pending
  140. end
  141. describe '#logo' do
  142. it 'creates a logo' do
  143. expect(used_in_builder { |xml| helper.logo(xml, 1) }).to match '<logo>1</logo>'
  144. end
  145. end
  146. def used_in_builder(&block)
  147. builder = Nokogiri::XML::Builder.new(&block)
  148. builder.doc.root.to_xml
  149. end
  150. def used_with_namespaces(&block)
  151. used_in_builder { |xml| helper.entry(xml, true, &block) }
  152. end
  153. end