Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
marcmrf committed Oct 8, 2024
1 parent 0c48fb3 commit f34afc5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def update_last_used(client_id)

module ApiKeyExtensions
def update_last_used!(now = nil)
return if last_used_at && (last_used_at == Time.zone.now.beginning_of_day)
#return if last_used_at && (last_used_at == Time.zone.now.beginning_of_day)

super(Time.zone.now.beginning_of_day)
end
Expand Down
19 changes: 13 additions & 6 deletions spec/plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@
it 'does not update last_used_at if already set to beginning of the day' do
user_api_key.update!(last_used_at: Time.zone.now.beginning_of_day)

expect(user_api_key).not_to receive(:update_column)
expect(user_api_key).not_to receive(:update_columns)
allow(user_api_key).to receive(:update_column)
allow(user_api_key).to receive(:update_columns)

expect {
user_api_key.update_last_used("client_id_1")
}.not_to change { user_api_key.reload.last_used_at }


expect(user_api_key).not_to receive(:update_column)
expect(user_api_key).not_to receive(:update_columns)
end

it 'updates client_id and destroys other keys with same client_id and user_id' do
Expand All @@ -48,12 +52,15 @@
end

it 'does not perform any database write if last_used_at is already set to the beginning of the day' do
api_key.update!(last_used_at: Time.zone.now.beginning_of_day)
api_key.update!(last_used_at: Time.zone.now.beginning_of_day)

expect(api_key).not_to receive(:update_column)
expect(api_key).not_to receive(:update_columns)
allow(api_key).to receive(:update_column)
allow(api_key).to receive(:update_columns)

api_key.update_last_used!
api_key.update_last_used!

expect(api_key).not_to have_received(:update_column)
expect(api_key).not_to have_received(:update_columns)
end
end
end

0 comments on commit f34afc5

Please sign in to comment.