issue_2460_fix_corrupted_twitter_ids_spec.rb 1.0 KB

1234567891011121314151617181920212223242526272829
  1. require 'rails_helper'
  2. RSpec.describe Issue2460FixCorruptedTwitterIds, type: :db_migration do
  3. before { allow(Twitter::REST::Client).to receive(:new).and_return(client) }
  4. let(:client) { double('Twitter::REST::Client', user: twitter_api_user) }
  5. let(:twitter_api_user) { double('Twitter::User', id: twitter_api_user_id) }
  6. let(:twitter_api_user_id) { 1234567890 } # rubocop:disable Style/NumericLiterals
  7. context 'with existing, corrupted Twitter channel' do
  8. let!(:twitter_channel) { create(:twitter_channel) }
  9. it 'updates the channel’s stored user ID (as string)' do
  10. expect { migrate }
  11. .to change { twitter_channel.reload.options[:user][:id] }
  12. .to(twitter_api_user_id.to_s)
  13. end
  14. context 'with invalid credentials stored' do
  15. before { allow(Twitter::REST::Client).to receive(:new).and_raise(Twitter::Error::Unauthorized.new('Could not authenticate you.')) }
  16. it 'skips the Channel' do
  17. expect { migrate }
  18. .not_to change { twitter_channel.reload.options[:user][:id] }
  19. end
  20. end
  21. end
  22. end