DEV: Compatibility with Ruby 3.2 (#19303)

This commit is contained in:
Rafael dos Santos Silva 2022-12-13 16:03:53 -03:00 committed by GitHub
parent f58eaf529f
commit 0434de6cee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 26 additions and 18 deletions

View File

@ -169,7 +169,7 @@ class StaticController < ApplicationController
immutable_for 1.year
response.headers["Expires"] = 1.year.from_now.httpdate
response.headers["Content-Length"] = data.bytesize.to_s
response.headers["Last-Modified"] = Time.new('2000-01-01').httpdate
response.headers["Last-Modified"] = Time.new(2000, 01, 01).httpdate
render body: data, content_type: "image/png"
end
end

View File

@ -48,7 +48,7 @@ class UserAvatarsController < ApplicationController
hijack do
begin
proxy_avatar("https://avatars.discourse-cdn.com/#{params[:version]}/letter/#{params[:letter]}/#{params[:color]}/#{params[:size]}.png", Time.new('1990-01-01'))
proxy_avatar("https://avatars.discourse-cdn.com/#{params[:version]}/letter/#{params[:letter]}/#{params[:color]}/#{params[:size]}.png", Time.new(1990, 01, 01))
rescue OpenURI::HTTPError
render_blank
end
@ -190,7 +190,7 @@ class UserAvatarsController < ApplicationController
def render_blank
path = Rails.root + "public/images/avatar.png"
expires_in 10.minutes, public: true
response.headers["Last-Modified"] = Time.new('1990-01-01').httpdate
response.headers["Last-Modified"] = Time.new(1990, 01, 01).httpdate
response.headers["Content-Length"] = File.size(path).to_s
send_file path, disposition: nil
end

View File

@ -759,7 +759,7 @@ class Theme < ActiveRecord::Base
attr_accessor :theme_setting_requests_refresh
def to_scss_variable(name, value)
escaped = SassC::Script::Value::String.quote(value, sass: true)
escaped = SassC::Script::Value::String.quote(value.to_s, sass: true)
"$#{name}: unquote(#{escaped});"
end

View File

@ -20,6 +20,14 @@ def is_yaml_compatible?(english, translated)
true
end
def load_yaml(path)
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.1.0")
YAML.load_file(path, aliases: true)
else
YAML.load_file(path)
end
end
RSpec.describe "i18n integrity checks" do
it "has an i18n key for each Site Setting" do
SiteSetting.all_settings.each do |s|
@ -47,7 +55,7 @@ RSpec.describe "i18n integrity checks" do
Dir["#{Rails.root}/config/locales/client.*.yml"].each do |path|
it "has valid client YAML for '#{path}'" do
yaml = YAML.load_file(path)
yaml = load_yaml(path)
locale = extract_locale(path)
expect(yaml.keys).to eq([locale])
@ -62,7 +70,7 @@ RSpec.describe "i18n integrity checks" do
end
Dir["#{Rails.root}/**/locale*/*.en.yml"].each do |english_path|
english_yaml = YAML.load_file(english_path)["en"]
english_yaml = load_yaml(english_path)["en"]
context(english_path) do
it "has no duplicate keys" do
@ -76,7 +84,7 @@ RSpec.describe "i18n integrity checks" do
context(path) do
locale = extract_locale(path)
yaml = YAML.load_file(path)
yaml = load_yaml(path)
it "has no duplicate keys" do
duplicates = DuplicateKeyFinder.new.find_duplicates(path)

View File

@ -112,45 +112,45 @@ RSpec.describe ReviewableScore, type: :model do
it "returns the users weighted accuracy bonus" do
user_stat.flags_agreed = 10
user_stat.flags_disagreed = 42
expect(ReviewableScore.user_accuracy_bonus(user).floor(2)).to eq(-10.34)
expect(ReviewableScore.user_accuracy_bonus(user)).to be_within(0.1).of(-10.34)
user_stat.flags_agreed = 2
user_stat.flags_disagreed = 12
expect(ReviewableScore.user_accuracy_bonus(user).floor(2)).to eq(-7.58)
expect(ReviewableScore.user_accuracy_bonus(user)).to be_within(0.1).of(-7.58)
user_stat.flags_agreed = 1
user_stat.flags_disagreed = 6
expect(ReviewableScore.user_accuracy_bonus(user).floor(2)).to eq(-5.59)
expect(ReviewableScore.user_accuracy_bonus(user)).to be_within(0.1).of(-5.59)
user_stat.flags_agreed = 2
user_stat.flags_disagreed = 4
expect(ReviewableScore.user_accuracy_bonus(user).floor(2)).to eq(-3.39)
expect(ReviewableScore.user_accuracy_bonus(user)).to be_within(0.1).of(-3.39)
user_stat.flags_agreed = 7
user_stat.flags_disagreed = 3
expect(ReviewableScore.user_accuracy_bonus(user).floor(2)).to eq(0)
expect(ReviewableScore.user_accuracy_bonus(user)).to be_within(0.1).of(0)
user_stat.flags_agreed = 14
user_stat.flags_disagreed = 6
expect(ReviewableScore.user_accuracy_bonus(user).floor(2)).to eq(0)
expect(ReviewableScore.user_accuracy_bonus(user)).to be_within(0.1).of(0)
# Ignored flags don't count
user_stat.flags_agreed = 121
user_stat.flags_disagreed = 44
user_stat.flags_ignored = 4
expect(ReviewableScore.user_accuracy_bonus(user).floor(2)).to eq(2.04)
expect(ReviewableScore.user_accuracy_bonus(user)).to be_within(0.1).of(2.05)
user_stat.flags_agreed = 9
user_stat.flags_disagreed = 2
expect(ReviewableScore.user_accuracy_bonus(user).floor(2)).to eq(3.41)
expect(ReviewableScore.user_accuracy_bonus(user)).to be_within(0.1).of(3.41)
user_stat.flags_agreed = 25
user_stat.flags_disagreed = 4
expect(ReviewableScore.user_accuracy_bonus(user).floor(2)).to eq(6.56)
expect(ReviewableScore.user_accuracy_bonus(user)).to be_within(0.1).of(6.56)
user_stat.flags_agreed = 120
user_stat.flags_disagreed = 12
expect(ReviewableScore.user_accuracy_bonus(user).floor(2)).to eq(12.27)
expect(ReviewableScore.user_accuracy_bonus(user)).to be_within(0.1).of(12.27)
end
end

View File

@ -158,7 +158,7 @@ RSpec.describe UserAvatarsController do
expect(response.status).to eq(200)
# this image should be really old so when it is fixed various algorithms pick it up
expect(response.headers["Last-Modified"]).to eq(Time.new('1990-01-01').httpdate)
expect(response.headers["Last-Modified"]).to eq(Time.new(1990, 01, 01).httpdate)
end
it 'serves image even if size missing and its in local mode' do