Skip to content

Commit

Permalink
Replace deprecated to_s(:format) with to_fs(:format)
Browse files Browse the repository at this point in the history
  • Loading branch information
mayorova committed Nov 21, 2024
1 parent 6ce6fa6 commit d604a53
Show file tree
Hide file tree
Showing 15 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion app/decorators/application_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion app/lib/csv/buyers_exporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions app/lib/month.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion app/lib/stats/aggregation/rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions app/lib/stats/storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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]
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/lib/stats/views/total.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions app/models/backend/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/backend/usage_accumulator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion app/representers/authentication_provider_representer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def self.timestamp(time_object)

class TimeDelegator < SimpleDelegator
def to_s
super(:iso8601)
to_fs(:iso8601)
end
end
end
2 changes: 1 addition & 1 deletion app/views/stats/days/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
2 changes: 1 addition & 1 deletion config/initializers/time_formats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
2 changes: 1 addition & 1 deletion features/step_definitions/stats/provider_response_codes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion test/unit/stats/aggregation/rule_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
10 changes: 5 additions & 5 deletions test/unit/time_formats_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 6 additions & 6 deletions test/workers/billing_worker_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit d604a53

Please sign in to comment.