Skip to content
代码片段 群组 项目
提交 ff27dcef 编辑于 作者: Vijay Hawoldar's avatar Vijay Hawoldar 提交者: Alper Akgun
浏览文件

Only log subscription history when applicable

Previously we would create a GitlabSubscriptionHistory record whenever a
GitlabSubscription was updated, regardless of what changed. Now we will
only create that record if a tracked attribute has been updated.
上级 0f40eaf3
No related branches found
No related tags found
无相关合并请求
...@@ -12,7 +12,7 @@ class GitlabSubscription < ApplicationRecord ...@@ -12,7 +12,7 @@ class GitlabSubscription < ApplicationRecord
attribute :start_date, default: -> { Date.today } attribute :start_date, default: -> { Date.today }
before_update :set_max_seats_used_changed_at before_update :set_max_seats_used_changed_at
before_update :log_previous_state_for_update before_update :log_previous_state_for_update, if: :tracked_attributes_changed?
before_update :reset_seat_statistics before_update :reset_seat_statistics
before_update :publish_subscription_renewed_event before_update :publish_subscription_renewed_event
...@@ -200,4 +200,8 @@ def new_term? ...@@ -200,4 +200,8 @@ def new_term?
def reset_seat_statistics? def reset_seat_statistics?
new_term? || (max_seats_used_changed_at.present? && max_seats_used_changed_at.to_date < start_date) new_term? || (max_seats_used_changed_at.present? && max_seats_used_changed_at.to_date < start_date)
end end
def tracked_attributes_changed?
changed.intersection(GitlabSubscriptionHistory::TRACKED_ATTRIBUTES).any?
end
end end
...@@ -596,16 +596,26 @@ ...@@ -596,16 +596,26 @@
) )
end end
it 'logs previous state to gitlab subscription history' do context 'when a tracked attribute is updated' do
gitlab_subscription.update!(max_seats_used: 32) it 'logs previous state to gitlab subscription history' do
gitlab_subscription.update!(max_seats_used: 32)
expect(GitlabSubscriptionHistory.count).to eq(1)
expect(GitlabSubscriptionHistory.last.attributes).to include(
'gitlab_subscription_id' => gitlab_subscription.id,
'change_type' => 'gitlab_subscription_updated',
'max_seats_used' => 42,
'seats' => 13
)
end
end
expect(GitlabSubscriptionHistory.count).to eq(1) context 'when tracked attributes are not updated' do
expect(GitlabSubscriptionHistory.last.attributes).to include( it 'does not log previous state to gitlab subscription history' do
'gitlab_subscription_id' => gitlab_subscription.id, expect do
'change_type' => 'gitlab_subscription_updated', gitlab_subscription.update!(last_seat_refresh_at: Time.current)
'max_seats_used' => 42, end.to not_change(GitlabSubscriptionHistory, :count)
'seats' => 13 end
)
end end
context 'when max_seats_used has changed' do context 'when max_seats_used has changed' do
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册