issue_2715_fix_broken_twitter_urls_job_spec.rb 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. require 'rails_helper'
  2. require_dependency 'issue_2715_fix_broken_twitter_urls_job' # Rails autoloading expects `issue2715_fix...`
  3. RSpec.describe Issue2715FixBrokenTwitterUrlsJob, type: :job do
  4. context 'with existing Twitter articles' do
  5. let!(:tweet) { create(:twitter_article, preferences: tweet_preferences) }
  6. let!(:dm) { create(:twitter_dm_article, preferences: dm_preferences) }
  7. let(:tweet_preferences) do
  8. # NOTE: Faker 2.0+ has deprecated the `#number(20)` syntax in favor of `#number(digits: 20)`.
  9. { links: [{ url: "https://twitter.com/statuses/#{Faker::Number.number(20)}" }] }
  10. end
  11. let(:dm_preferences) do
  12. {
  13. # NOTE: Faker 2.0+ has deprecated the `#number(20)` syntax in favor of `#number(digits: 20)`.
  14. links: [{ url: "https://twitter.com/statuses/#{Faker::Number.number(20)}" }],
  15. twitter: {
  16. recipient_id: recipient_id,
  17. sender_id: sender_id,
  18. },
  19. }
  20. end
  21. let(:recipient_id) { '1234567890' }
  22. let(:sender_id) { '0987654321' }
  23. it 'reformats all Twitter status URLs' do
  24. expect { described_class.perform_now }
  25. .to change { urls_of(tweet) }
  26. .to all(match(%r{^https://twitter.com/_/status/#{tweet.message_id}$}))
  27. end
  28. it 'reformats all Twitter DM URLs' do
  29. expect { described_class.perform_now }
  30. .to change { urls_of(dm) }
  31. .to all(match(%r{^https://twitter.com/messages/#{recipient_id}-#{sender_id}$}))
  32. end
  33. def urls_of(article)
  34. article.reload.preferences[:links].pluck(:url)
  35. end
  36. end
  37. end