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
user = User.find(auth.user_id)
if (!user_data[:note] || user_data[:note].empty?) && tweet_user.description
user_data[:note] = tweet_user.description
end
map = {
note: 'description',
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)
else
user_data[:login] = tweet_user.screen_name
user_data[:firstname] = tweet_user.name
user_data[:web] = tweet_user.website.to_s
user_data[:note] = tweet_user.description
user_data[:address] = tweet_user.location
user_data[:active] = true
user_data[:roles] = Role.where(name: 'Customer')
user = User.create(user_data)
end

View file

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