diff options
author | Douwe Maan <douwe@gitlab.com> | 2017-05-09 14:46:50 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2017-05-09 14:46:50 +0000 |
commit | dccf5f19f911eaf8d32e37e9f369a46d9e7ec9bd (patch) | |
tree | bf85d85d79b885b90f20ed587fc7ea77387095c3 /spec/models | |
parent | 2aa084a484784bc72e85dbaa82189a66a913e352 (diff) | |
parent | 3531ea096f730b8533df259ac2f6cbed738965ed (diff) | |
download | gitlab-ce-dccf5f19f911eaf8d32e37e9f369a46d9e7ec9bd.tar.gz |
Merge branch 'tc-cache-trackable-attributes' into 'master'
Limit User's trackable attributes to update at most once/hour
Closes #22068
See merge request !11053
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/user_spec.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 63e71f5ff2f..c7ddd17872b 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -344,6 +344,35 @@ describe User, models: true do end end + describe '#update_tracked_fields!', :redis do + let(:request) { OpenStruct.new(remote_ip: "127.0.0.1") } + let(:user) { create(:user) } + + it 'writes trackable attributes' do + expect do + user.update_tracked_fields!(request) + end.to change { user.reload.current_sign_in_at } + end + + it 'does not write trackable attributes when called a second time within the hour' do + user.update_tracked_fields!(request) + + expect do + user.update_tracked_fields!(request) + end.not_to change { user.reload.current_sign_in_at } + end + + it 'writes trackable attributes for a different user' do + user2 = create(:user) + + user.update_tracked_fields!(request) + + expect do + user2.update_tracked_fields!(request) + end.to change { user2.reload.current_sign_in_at } + end + end + shared_context 'user keys' do let(:user) { create(:user) } let!(:key) { create(:key, user: user) } |