Improved user attributes sync.

This commit is contained in:
Martin Edenhofer 2016-01-12 09:55:00 +01:00
parent b93b4b5579
commit 329d412035
2 changed files with 26 additions and 9 deletions

View file

@ -39,16 +39,29 @@ class TweetBase
} }
if auth if auth
user = User.find(auth.user_id) user = User.find(auth.user_id)
if (!user_data[:note] || user_data[:note].empty?) && tweet_user.description map = {
user_data[:note] = tweet_user.description note: 'description',
end web: 'website',
address: 'location',
}
# ignore if value is already set
map.each {|target, source|
next if user[target] && !user[target].empty?
new_value = tweet_user.send(source).to_s
next if !new_value || new_value.empty?
user_data[target] = new_value
}
user.update_attributes(user_data) user.update_attributes(user_data)
else else
user_data[:login] = tweet_user.screen_name user_data[:login] = tweet_user.screen_name
user_data[:firstname] = tweet_user.name user_data[:firstname] = tweet_user.name
user_data[:web] = tweet_user.website.to_s
user_data[:note] = tweet_user.description user_data[:note] = tweet_user.description
user_data[:address] = tweet_user.location
user_data[:active] = true user_data[:active] = true
user_data[:roles] = Role.where(name: 'Customer') user_data[:roles] = Role.where(name: 'Customer')
user = User.create(user_data) user = User.create(user_data)
end end

View file

@ -58,6 +58,10 @@ class TwitterTest < ActiveSupport::TestCase
oauth_token: armin_theo_token, oauth_token: armin_theo_token,
oauth_token_secret: armin_theo_token_secret, oauth_token_secret: armin_theo_token_secret,
}, },
user: {
screen_name: '@armin_theo',
id: '1234',
},
sync: { sync: {
search: [ search: [
{ {
@ -236,7 +240,7 @@ class TwitterTest < ActiveSupport::TestCase
config.access_token = armin_theo_token config.access_token = armin_theo_token
config.access_token_secret = armin_theo_token_secret config.access_token_secret = armin_theo_token_secret
end end
dms = client.direct_messages(count: 40) dms = client.direct_messages(count: 100)
dms.each {|dm| dms.each {|dm|
client.destroy_direct_message(dm.id) client.destroy_direct_message(dm.id)
} }
@ -246,7 +250,7 @@ class TwitterTest < ActiveSupport::TestCase
access_token: me_bauer_token, access_token: me_bauer_token,
access_token_secret: me_bauer_token_secret access_token_secret: me_bauer_token_secret
) )
dms = client.direct_messages(count: 40) dms = client.direct_messages(count: 100)
dms.each {|dm| dms.each {|dm|
client.destroy_direct_message(dm.id) client.destroy_direct_message(dm.id)
} }
@ -346,7 +350,7 @@ class TwitterTest < ActiveSupport::TestCase
# check if ticket and article has been created # check if ticket and article has been created
article = Ticket::Article.find_by(message_id: dm.id) article = Ticket::Article.find_by(message_id: dm.id)
break if article break if article
sleep 10 sleep 15
} }
assert(article, "inbound article '#{text}' created") assert(article, "inbound article '#{text}' created")