From d604a538f4c7778bd8908351cf72ddc879d86705 Mon Sep 17 00:00:00 2001 From: Daria Mayorova Date: Thu, 21 Nov 2024 16:13:05 +0100 Subject: [PATCH] Replace deprecated to_s(:format) with to_fs(:format) --- app/decorators/application_decorator.rb | 2 +- app/lib/csv/buyers_exporter.rb | 2 +- app/lib/month.rb | 6 +++--- app/lib/stats/aggregation/rule.rb | 2 +- app/lib/stats/storage.rb | 10 +++++----- app/lib/stats/views/total.rb | 2 +- app/models/backend/status.rb | 4 ++-- app/models/backend/usage_accumulator.rb | 2 +- .../authentication_provider_representer.rb | 2 +- app/views/stats/days/show.html.erb | 2 +- config/initializers/time_formats.rb | 2 +- .../stats/provider_response_codes.rb | 2 +- test/unit/stats/aggregation/rule_test.rb | 2 +- test/unit/time_formats_test.rb | 10 +++++----- test/workers/billing_worker_test.rb | 12 ++++++------ 15 files changed, 31 insertions(+), 31 deletions(-) diff --git a/app/decorators/application_decorator.rb b/app/decorators/application_decorator.rb index 590007830a..9f4f02101f 100644 --- a/app/decorators/application_decorator.rb +++ b/app/decorators/application_decorator.rb @@ -14,6 +14,6 @@ def self.collection_decorator_class end def updated_at - object.updated_at.to_s :long if object.updated_at? + object.updated_at.to_fs(:long) if object.updated_at? end end diff --git a/app/lib/csv/buyers_exporter.rb b/app/lib/csv/buyers_exporter.rb index a1e2217756..100b29f767 100644 --- a/app/lib/csv/buyers_exporter.rb +++ b/app/lib/csv/buyers_exporter.rb @@ -23,7 +23,7 @@ def values_for_account(account) account.org_name, account.country.try!(:name), account.bought_account_plan.try!(:name), - account.created_at.to_s(:db), + account.created_at.to_fs(:db), account.bought_cinstances.count, account.decorate.admin_user_display_name, user&.email, diff --git a/app/lib/month.rb b/app/lib/month.rb index f4d8183b7e..2e128a9268 100644 --- a/app/lib/month.rb +++ b/app/lib/month.rb @@ -44,17 +44,17 @@ def same_month?(date) end def to_param - self.begin.to_s(:db_month) + self.begin.to_fs(:db_month) end delegate :to_json, :to => :to_param def to_s(format = :long) - begin_formatted = self.begin.to_s(format) + begin_formatted = self.begin.to_fs(format) if format == :db begin_formatted else - "#{begin_formatted} - #{self.end.to_s(format)}" + "#{begin_formatted} - #{self.end.to_fs(format)}" end end diff --git a/app/lib/stats/aggregation/rule.rb b/app/lib/stats/aggregation/rule.rb index 46490f304c..a96c96ae7a 100644 --- a/app/lib/stats/aggregation/rule.rb +++ b/app/lib/stats/aggregation/rule.rb @@ -81,7 +81,7 @@ def granularity_key_component(data) "eternity" else cycle = data[:created_at].beginning_of_cycle(granularity) - key_for(granularity => cycle.to_s(:compact)) + key_for(granularity => cycle.to_fs(:compact)) end end diff --git a/app/lib/stats/storage.rb b/app/lib/stats/storage.rb index b6bb237ed5..8440196577 100644 --- a/app/lib/stats/storage.rb +++ b/app/lib/stats/storage.rb @@ -41,7 +41,7 @@ def ordered_hash(since, period, options) raise InvalidParameterError, "Missing parameter :by" unless options.key?(:by) source_key = key_for(options[:from]) - value_key = key_for(options[:by].push(period => since.to_s(:compact))) + value_key = key_for(options[:by].push(period => since.to_fs(:compact))) value_key_without_period = value_key.match(/(.*)\/.*/)[1] begin @@ -83,10 +83,10 @@ def resum_all_value(range, granularity, prefix) prefix = key_for(prefix) + '/hour:' range.each(g).map do |from| - # day_prefix = from.beginning_of(:day).to_s(:compact) + # day_prefix = from.beginning_of(:day).to_fs(:compact) to = from + (g - 3600) keys = (from..to).to_time_range.each(:hour).map do |time| - prefix + time.to_s(:compact) + prefix + time.to_fs(:compact) end mget(*keys).inject(0) { |sum,v| sum + v.to_i } @@ -189,7 +189,7 @@ def compute_timeshift_deltas(range, shift, granularity, prefix) keys = benchmark :shifted_range, level: :debug do shifted_range.each(granularity_for_iteration).flat_map do |date| - prefix_with_day = prefix + date.beginning_of(:day).to_s(:compact) + prefix_with_day = prefix + date.beginning_of(:day).to_fs(:compact) margin.map do |hour| prefix_with_day + HOURS_STRINGS[hour] @@ -212,7 +212,7 @@ def compute_timeshift_deltas(range, shift, granularity, prefix) def keys_for_range(range, granularity, key_prefix) key = key_for(key_prefix) prefix = key + '/' + granularity.to_s + ':' - transform = ->(time) { prefix + time.to_s(:compact) } + transform = ->(time) { prefix + time.to_fs(:compact) } case granularity when :day diff --git a/app/lib/stats/views/total.rb b/app/lib/stats/views/total.rb index 9d94d69424..d30ac0e1fd 100644 --- a/app/lib/stats/views/total.rb +++ b/app/lib/stats/views/total.rb @@ -59,7 +59,7 @@ def total_hits(options = {}) private def total_in_fixed_period(period, since, metric) - storage.get(key_for(:stats, source_key, metric, period => since.to_s(:compact))).to_i + storage.get(key_for(:stats, source_key, metric, period => since.to_fs(:compact))).to_i end def total_in_eternity(metric) diff --git a/app/models/backend/status.rb b/app/models/backend/status.rb index 6f6037da94..82ccd94097 100644 --- a/app/models/backend/status.rb +++ b/app/models/backend/status.rb @@ -56,8 +56,8 @@ def to_xml(options = {}) records.each do |record| xml.usage(:metric => record.metric_name, :period => record.period) do |xml| - xml.period_start(record.period_as_range.begin.to_s(:db)) unless record.period == :eternity - xml.period_end(record.period_as_range.end.to_s(:db)) unless record.period == :eternity + xml.period_start(record.period_as_range.begin.to_fs(:db)) unless record.period == :eternity + xml.period_end(record.period_as_range.end.to_fs(:db)) unless record.period == :eternity xml.current_value(record.current_value) xml.max_value(record.max_value) end diff --git a/app/models/backend/usage_accumulator.rb b/app/models/backend/usage_accumulator.rb index fd71308a3a..70c0c95a19 100644 --- a/app/models/backend/usage_accumulator.rb +++ b/app/models/backend/usage_accumulator.rb @@ -77,7 +77,7 @@ def storage_key(period, metric_id) key_for(:stats, {:service => cinstance_data[:service_id]}, {:cinstance => cinstance_data[:application_id]}, {:metric => metric_id}, - {period => Time.zone.now.beginning_of(period).to_s(:compact)}) + {period => Time.zone.now.beginning_of(period).to_fs(:compact)}) end def validate_limits!(options) diff --git a/app/representers/authentication_provider_representer.rb b/app/representers/authentication_provider_representer.rb index edc458f889..c5f0df179a 100644 --- a/app/representers/authentication_provider_representer.rb +++ b/app/representers/authentication_provider_representer.rb @@ -47,7 +47,7 @@ def self.timestamp(time_object) class TimeDelegator < SimpleDelegator def to_s - super(:iso8601) + to_fs(:iso8601) end end end diff --git a/app/views/stats/days/show.html.erb b/app/views/stats/days/show.html.erb index 9b62e0258e..1fc621fb9b 100644 --- a/app/views/stats/days/show.html.erb +++ b/app/views/stats/days/show.html.erb @@ -10,6 +10,6 @@ <%= area_line_chart(data, :class => 'small_chart', :line_color => '4477aa', - :x_label_proc => lambda { |time| time.to_s(:time) }, + :x_label_proc => lambda { |time| time.to_fs(:time) }, :x_labels_step => 2, :y_labels_count => 2) %> <% end %> diff --git a/config/initializers/time_formats.rb b/config/initializers/time_formats.rb index ce5fb95b7a..c99f00017b 100644 --- a/config/initializers/time_formats.rb +++ b/config/initializers/time_formats.rb @@ -3,5 +3,5 @@ Date::DATE_FORMATS[:db_month] = '%Y-%m' # This is like the :number, but with trailing zeroes removed. -Time::DATE_FORMATS[:compact] = ->(time) { time.to_s(:number).sub(/0{0,6}$/, '') } +Time::DATE_FORMATS[:compact] = ->(time) { time.to_fs(:number).sub(/0{0,6}$/, '') } Date::DATE_FORMATS[:compact] = Date::DATE_FORMATS[:number] diff --git a/features/step_definitions/stats/provider_response_codes.rb b/features/step_definitions/stats/provider_response_codes.rb index bcab889c3f..3a63a84c3f 100644 --- a/features/step_definitions/stats/provider_response_codes.rb +++ b/features/step_definitions/stats/provider_response_codes.rb @@ -11,7 +11,7 @@ service = @provider.first_service! keys = RESPONSE_CODES.flat_map do |code| - [["stats/{service:#{service.id}}/response_code:#{code}/hour:#{now.at_beginning_of_day.to_s(:compact)}", RESPONSE_CODE_VALUE]] + [["stats/{service:#{service.id}}/response_code:#{code}/hour:#{now.at_beginning_of_day.to_fs(:compact)}", RESPONSE_CODE_VALUE]] end.to_h storage.mapped_mset(keys) diff --git a/test/unit/stats/aggregation/rule_test.rb b/test/unit/stats/aggregation/rule_test.rb index ce0f6b89ca..8a189b1103 100644 --- a/test/unit/stats/aggregation/rule_test.rb +++ b/test/unit/stats/aggregation/rule_test.rb @@ -17,7 +17,7 @@ def setup :created_at => time} rule.aggregate(data) - key = "stats/{service:#{service.backend_id}}/metric:789/day:#{time.beginning_of_cycle(:day).to_s(:compact)}" + key = "stats/{service:#{service.backend_id}}/metric:789/day:#{time.beginning_of_cycle(:day).to_fs(:compact)}" ttl = @storage.ttl(key) diff --git a/test/unit/time_formats_test.rb b/test/unit/time_formats_test.rb index 9a70f6f929..3eb187d1c1 100644 --- a/test/unit/time_formats_test.rb +++ b/test/unit/time_formats_test.rb @@ -2,10 +2,10 @@ class TimeFormatsTest < ActiveSupport::TestCase test 'compact' do - assert_equal '20091103123455', Time.utc(2009, 11, 3, 12, 34, 55).to_s(:compact) - assert_equal '200911031234', Time.utc(2009, 11, 3, 12, 34, 0).to_s(:compact) - assert_equal '2009110312', Time.utc(2009, 11, 3, 12, 0, 0).to_s(:compact) - assert_equal '20091103', Time.utc(2009, 11, 3, 0, 0, 0).to_s(:compact) - assert_equal '20091110', Time.utc(2009, 11, 10, 0, 0, 0).to_s(:compact) + assert_equal '20091103123455', Time.utc(2009, 11, 3, 12, 34, 55).to_fs(:compact) + assert_equal '200911031234', Time.utc(2009, 11, 3, 12, 34, 0).to_fs(:compact) + assert_equal '2009110312', Time.utc(2009, 11, 3, 12, 0, 0).to_fs(:compact) + assert_equal '20091103', Time.utc(2009, 11, 3, 0, 0, 0).to_fs(:compact) + assert_equal '20091110', Time.utc(2009, 11, 10, 0, 0, 0).to_fs(:compact) end end diff --git a/test/workers/billing_worker_test.rb b/test/workers/billing_worker_test.rb index 52333cb73a..770f996745 100644 --- a/test/workers/billing_worker_test.rb +++ b/test/workers/billing_worker_test.rb @@ -19,7 +19,7 @@ class BillingWorkerTest < ActiveSupport::TestCase billing_options = { only: [@provider.id], buyer_ids: [@buyer.id], now: time, skip_notifications: true } Finance::BillingStrategy.expects(:daily).with(billing_options).returns(mock_billing_success(time, @provider)) - assert BillingWorker.new.perform(@buyer.id, @provider.id, time.to_s(:iso8601)) + assert BillingWorker.new.perform(@buyer.id, @provider.id, time.to_fs(:iso8601)) end test 'creates a lock per buyer account' do @@ -30,21 +30,21 @@ class BillingWorkerTest < ActiveSupport::TestCase billing_options_2 = { only: [@provider.id], buyer_ids: [buyer_2.id], now: time, skip_notifications: true } Finance::BillingStrategy.expects(:daily).with(billing_options).returns(mock_billing_success(time, @provider)) - assert BillingWorker.new.perform(@buyer.id, @provider.id, time.to_s(:iso8601)) + assert BillingWorker.new.perform(@buyer.id, @provider.id, time.to_fs(:iso8601)) Finance::BillingStrategy.expects(:daily).with(billing_options_2).returns(mock_billing_success(time, @provider)) - assert BillingWorker.new.perform(buyer_2.id, @provider.id, time.to_s(:iso8601)) + assert BillingWorker.new.perform(buyer_2.id, @provider.id, time.to_fs(:iso8601)) - assert_not BillingWorker.new.perform(@buyer.id, @provider.id, time.to_s(:iso8601)) + assert_not BillingWorker.new.perform(@buyer.id, @provider.id, time.to_fs(:iso8601)) end test 'aborts if buyer is locked' do time = Time.utc(2017, 12, 1, 8, 0) within_thread do - assert BillingWorker.new.perform(@buyer.id, @provider.id, time.to_s(:iso8601)) + assert BillingWorker.new.perform(@buyer.id, @provider.id, time.to_fs(:iso8601)) end - refute BillingWorker.new.perform(@buyer.id, @provider.id, time.to_s(:iso8601)) + refute BillingWorker.new.perform(@buyer.id, @provider.id, time.to_fs(:iso8601)) end test 'callback' do