The code powering m.abunchtell.com https://m.abunchtell.com
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

86 lignes
2.2 KiB

  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe RemoteFollow do
  4. describe '.initialize' do
  5. let(:remote_follow) { RemoteFollow.new(option) }
  6. context 'option with acct' do
  7. let(:option) { { acct: 'hoge@example.com' } }
  8. it 'sets acct' do
  9. expect(remote_follow.acct).to eq 'hoge@example.com'
  10. end
  11. end
  12. context 'option without acct' do
  13. let(:option) { {} }
  14. it 'does not set acct' do
  15. expect(remote_follow.acct).to be_nil
  16. end
  17. end
  18. end
  19. describe '#valid?' do
  20. let(:remote_follow) { RemoteFollow.new }
  21. context 'super is falsy' do
  22. module InvalidSuper
  23. def valid?
  24. nil
  25. end
  26. end
  27. before do
  28. class RemoteFollow
  29. include InvalidSuper
  30. end
  31. end
  32. it 'returns false without calling #populate_template and #errors' do
  33. expect(remote_follow).not_to receive(:populate_template)
  34. expect(remote_follow).not_to receive(:errors)
  35. expect(remote_follow.valid?).to be false
  36. end
  37. end
  38. context 'super is truthy' do
  39. module ValidSuper
  40. def valid?
  41. true
  42. end
  43. end
  44. before do
  45. class RemoteFollow
  46. include ValidSuper
  47. end
  48. end
  49. it 'calls #populate_template and #errors.empty?' do
  50. expect(remote_follow).to receive(:populate_template)
  51. expect(remote_follow).to receive_message_chain(:errors, :empty?)
  52. remote_follow.valid?
  53. end
  54. end
  55. end
  56. describe '#subscribe_address_for' do
  57. before do
  58. allow(remote_follow).to receive(:addressable_template).and_return(addressable_template)
  59. end
  60. let(:account) { instance_double('Account', local_username_and_domain: local_username_and_domain) }
  61. let(:addressable_template) { instance_double('Addressable::Template') }
  62. let(:local_username_and_domain) { 'hoge@example.com' }
  63. let(:remote_follow) { RemoteFollow.new }
  64. it 'calls Addressable::Template#expand.to_s' do
  65. expect(addressable_template).to receive_message_chain(:expand, :to_s).with(uri: local_username_and_domain).with(no_args)
  66. remote_follow.subscribe_address_for(account)
  67. end
  68. end
  69. end