logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

remote_profile_spec.rb (3351B)


  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe RemoteProfile do
  4. let(:remote_profile) { RemoteProfile.new(body) }
  5. let(:body) do
  6. <<-XML
  7. <feed xmlns="http://www.w3.org/2005/Atom">
  8. <author>John</author>
  9. XML
  10. end
  11. describe '.initialize' do
  12. it 'calls Nokogiri::XML.parse' do
  13. expect(Nokogiri::XML).to receive(:parse).with(body, nil, 'utf-8')
  14. RemoteProfile.new(body)
  15. end
  16. it 'sets document' do
  17. remote_profile = RemoteProfile.new(body)
  18. expect(remote_profile).not_to be nil
  19. end
  20. end
  21. describe '#root' do
  22. let(:document) { remote_profile.document }
  23. it 'callse document.at_xpath' do
  24. expect(document).to receive(:at_xpath).with(
  25. '/atom:feed|/atom:entry',
  26. atom: OStatus::TagManager::XMLNS
  27. )
  28. remote_profile.root
  29. end
  30. end
  31. describe '#author' do
  32. let(:root) { remote_profile.root }
  33. it 'calls root.at_xpath' do
  34. expect(root).to receive(:at_xpath).with(
  35. './atom:author|./dfrn:owner',
  36. atom: OStatus::TagManager::XMLNS,
  37. dfrn: OStatus::TagManager::DFRN_XMLNS
  38. )
  39. remote_profile.author
  40. end
  41. end
  42. describe '#hub_link' do
  43. let(:root) { remote_profile.root }
  44. it 'calls #link_href_from_xml' do
  45. expect(remote_profile).to receive(:link_href_from_xml).with(root, 'hub')
  46. remote_profile.hub_link
  47. end
  48. end
  49. describe '#display_name' do
  50. let(:author) { remote_profile.author }
  51. it 'calls author.at_xpath.content' do
  52. expect(author).to receive_message_chain(:at_xpath, :content).with(
  53. './poco:displayName',
  54. poco: OStatus::TagManager::POCO_XMLNS
  55. ).with(no_args)
  56. remote_profile.display_name
  57. end
  58. end
  59. describe '#note' do
  60. let(:author) { remote_profile.author }
  61. it 'calls author.at_xpath.content' do
  62. expect(author).to receive_message_chain(:at_xpath, :content).with(
  63. './atom:summary|./poco:note',
  64. atom: OStatus::TagManager::XMLNS,
  65. poco: OStatus::TagManager::POCO_XMLNS
  66. ).with(no_args)
  67. remote_profile.note
  68. end
  69. end
  70. describe '#scope' do
  71. let(:author) { remote_profile.author }
  72. it 'calls author.at_xpath.content' do
  73. expect(author).to receive_message_chain(:at_xpath, :content).with(
  74. './mastodon:scope',
  75. mastodon: OStatus::TagManager::MTDN_XMLNS
  76. ).with(no_args)
  77. remote_profile.scope
  78. end
  79. end
  80. describe '#avatar' do
  81. let(:author) { remote_profile.author }
  82. it 'calls #link_href_from_xml' do
  83. expect(remote_profile).to receive(:link_href_from_xml).with(author, 'avatar')
  84. remote_profile.avatar
  85. end
  86. end
  87. describe '#header' do
  88. let(:author) { remote_profile.author }
  89. it 'calls #link_href_from_xml' do
  90. expect(remote_profile).to receive(:link_href_from_xml).with(author, 'header')
  91. remote_profile.header
  92. end
  93. end
  94. describe '#locked?' do
  95. before do
  96. allow(remote_profile).to receive(:scope).and_return(scope)
  97. end
  98. subject { remote_profile.locked? }
  99. context 'scope is private' do
  100. let(:scope) { 'private' }
  101. it 'returns true' do
  102. is_expected.to be true
  103. end
  104. end
  105. context 'scope is not private' do
  106. let(:scope) { 'public' }
  107. it 'returns false' do
  108. is_expected.to be false
  109. end
  110. end
  111. end
  112. end