Skip to content

Commit

Permalink
Merge pull request #1826 from 3scale/posoni_29
Browse files Browse the repository at this point in the history
Updating pisoni 1.29
  • Loading branch information
hemahg authored Apr 28, 2020
2 parents 3422131 + 4f58480 commit 62f27e8
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 43 deletions.
2 changes: 1 addition & 1 deletion Gemfile.base
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ gem 'bcrypt', '~> 3.1.7'
gem 'i18n'

# Apisonator client
gem 'pisoni', '~> 1.26'
gem 'pisoni', '~> 1.29'

# 3scale fork that allows OPTIONS passthrough
gem 'font_assets', git: 'https://github.com/3scale/font_assets.git', ref: 'da97b8601528ee189795cc94b953ec9a30f47e83', groups: [:production, :preview]
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ GEM
excon
faraday (>= 0.9)
pg (0.21.0)
pisoni (1.27.0)
pisoni (1.29.0)
faraday (>= 0.9.1)
injectedlogger (>= 0.0.13)
json (>= 1.8.1)
Expand Down Expand Up @@ -886,7 +886,7 @@ DEPENDENCIES
paperclip (~> 5.3.0)
percy-capybara (~> 2.5.1)
pg (~> 0.21.0)
pisoni (~> 1.26)
pisoni (~> 1.29)
prawn-core!
prawn-format (= 0.2.1)
prawn-layout (= 0.2.1)
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.prod.lock
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ GEM
addressable
excon
faraday (>= 0.9)
pisoni (1.27.0)
pisoni (1.29.0)
faraday (>= 0.9.1)
injectedlogger (>= 0.0.13)
json (>= 1.8.1)
Expand Down Expand Up @@ -887,7 +887,7 @@ DEPENDENCIES
open_id_authentication
paperclip (~> 5.3.0)
percy-capybara (~> 2.5.1)
pisoni (~> 1.26)
pisoni (~> 1.29)
prawn-core!
prawn-format (= 0.2.1)
prawn-layout (= 0.2.1)
Expand Down
18 changes: 2 additions & 16 deletions app/workers/backend_delete_stats_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,8 @@ class BackendDeleteStatsWorker
include Sidekiq::Worker

def perform(event_id)
@event = EventStore::Repository.find_event!(event_id)
event = EventStore::Repository.find_event!(event_id)

ThreeScale::Core::Service.delete_stats(event.service_id, delete_job)
end

attr_reader :event

def delete_job
service = Service.new({id: event.service_id}, without_protection: true)
deleted_associations = DeletedObject.where(owner: service)
{ deletejobdef: {
applications: deleted_associations.contracts.pluck(:object_id),
metrics: deleted_associations.metrics.pluck(:object_id),
users: [],
from: Time.parse(event.service_created_at).to_i,
to: Time.now.utc.to_i
}}
ThreeScale::Core::Service.delete_stats(event.service_id, {})
end
end
7 changes: 0 additions & 7 deletions test/test_helpers/backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ def mock_core!
[]
end

clear_method ThreeScale::Core::User.singleton_class,
:load, :delete_all_for_service
clear_method ThreeScale::Core::ApplicationKey.singleton_class,
:save, :delete
clear_method ThreeScale::Core::ApplicationReferrerFilter.singleton_class,
Expand All @@ -63,11 +61,6 @@ def mock_core!
ThreeScale::Core::APIClient::Collection.new([], 0)
end

# these are required to return true for some cukes to be happy
on_method ThreeScale::Core::User.singleton_class, :save!, :delete! do |*_|
true
end

clear_method ThreeScale::Core::AlertLimit.singleton_class, :save, :load_all do |*_|
[]
end
Expand Down
17 changes: 2 additions & 15 deletions test/workers/backend_delete_stats_worker_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,11 @@ def setup

test 'perform' do
Timecop.freeze do
ThreeScale::Core::Service.expects(:delete_stats).with do |service_id, delete_job|
service_id == service.id && assert_delete_job_params(delete_job)
ThreeScale::Core::Service.expects(:delete_stats).with do |service_id|
service_id == service.id
end

Sidekiq::Testing.inline! { BackendDeleteStatsWorker.perform_async(event.event_id) }
end
end

private

def assert_delete_job_params(delete_job)
deletejobdef = delete_job[:deletejobdef] || {}
[
-> { (deletejobdef[:applications] || []).sort == applications.map(&:id).sort },
-> { (deletejobdef[:metrics] || []).sort == metrics.map(&:id).sort },
-> { deletejobdef[:users] == [] },
-> { deletejobdef[:from] == service.created_at.utc.to_i },
-> { deletejobdef[:to] == Time.now.utc.to_i }
].all?(&:call)
end
end

0 comments on commit 62f27e8

Please sign in to comment.