Fixes #2826 - Invalid stored Twitter credentials block migration.
This commit is contained in:
parent
3921820ae8
commit
ff6b4256e1
2 changed files with 21 additions and 5 deletions
|
@ -4,13 +4,19 @@ class Issue2460FixCorruptedTwitterIds < ActiveRecord::Migration[5.2]
|
||||||
|
|
||||||
Channel.where(area: 'Twitter::Account').each do |channel|
|
Channel.where(area: 'Twitter::Account').each do |channel|
|
||||||
|
|
||||||
client = Twitter::REST::Client.new do |config|
|
begin
|
||||||
config.consumer_key = channel.options['auth']['consumer_key']
|
client = Twitter::REST::Client.new do |config|
|
||||||
config.consumer_secret = channel.options['auth']['consumer_secret']
|
config.consumer_key = channel.options['auth']['consumer_key']
|
||||||
config.access_token = channel.options['auth']['oauth_token']
|
config.consumer_secret = channel.options['auth']['consumer_secret']
|
||||||
config.access_token_secret = channel.options['auth']['oauth_token_secret']
|
config.access_token = channel.options['auth']['oauth_token']
|
||||||
|
config.access_token_secret = channel.options['auth']['oauth_token_secret']
|
||||||
|
end
|
||||||
|
rescue => e
|
||||||
|
Rails.logger.error "Error while trying to update corrupted Twitter User ID: #{e.message}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
next if client.blank?
|
||||||
|
|
||||||
channel.options['user']['id'] = client.user.id.to_s
|
channel.options['user']['id'] = client.user.id.to_s
|
||||||
|
|
||||||
channel.save!
|
channel.save!
|
||||||
|
|
|
@ -15,5 +15,15 @@ RSpec.describe Issue2460FixCorruptedTwitterIds, type: :db_migration do
|
||||||
.to change { twitter_channel.reload.options[:user][:id] }
|
.to change { twitter_channel.reload.options[:user][:id] }
|
||||||
.to(twitter_api_user_id.to_s)
|
.to(twitter_api_user_id.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'with invalid credentials stored' do
|
||||||
|
|
||||||
|
before { allow(Twitter::REST::Client).to receive(:new).and_raise(Twitter::Error::Unauthorized.new('Could not authenticate you.')) }
|
||||||
|
|
||||||
|
it 'skips the Channel' do
|
||||||
|
expect { migrate }
|
||||||
|
.not_to change { twitter_channel.reload.options[:user][:id] }
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue