DEV: Compatibility with Ruby 3.2 (#19303)
This commit is contained in:
parent
f58eaf529f
commit
0434de6cee
|
@ -169,7 +169,7 @@ class StaticController < ApplicationController
|
||||||
immutable_for 1.year
|
immutable_for 1.year
|
||||||
response.headers["Expires"] = 1.year.from_now.httpdate
|
response.headers["Expires"] = 1.year.from_now.httpdate
|
||||||
response.headers["Content-Length"] = data.bytesize.to_s
|
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"
|
render body: data, content_type: "image/png"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -48,7 +48,7 @@ class UserAvatarsController < ApplicationController
|
||||||
|
|
||||||
hijack do
|
hijack do
|
||||||
begin
|
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
|
rescue OpenURI::HTTPError
|
||||||
render_blank
|
render_blank
|
||||||
end
|
end
|
||||||
|
@ -190,7 +190,7 @@ class UserAvatarsController < ApplicationController
|
||||||
def render_blank
|
def render_blank
|
||||||
path = Rails.root + "public/images/avatar.png"
|
path = Rails.root + "public/images/avatar.png"
|
||||||
expires_in 10.minutes, public: true
|
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
|
response.headers["Content-Length"] = File.size(path).to_s
|
||||||
send_file path, disposition: nil
|
send_file path, disposition: nil
|
||||||
end
|
end
|
||||||
|
|
|
@ -759,7 +759,7 @@ class Theme < ActiveRecord::Base
|
||||||
attr_accessor :theme_setting_requests_refresh
|
attr_accessor :theme_setting_requests_refresh
|
||||||
|
|
||||||
def to_scss_variable(name, value)
|
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});"
|
"$#{name}: unquote(#{escaped});"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,14 @@ def is_yaml_compatible?(english, translated)
|
||||||
true
|
true
|
||||||
end
|
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
|
RSpec.describe "i18n integrity checks" do
|
||||||
it "has an i18n key for each Site Setting" do
|
it "has an i18n key for each Site Setting" do
|
||||||
SiteSetting.all_settings.each do |s|
|
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|
|
Dir["#{Rails.root}/config/locales/client.*.yml"].each do |path|
|
||||||
it "has valid client YAML for '#{path}'" do
|
it "has valid client YAML for '#{path}'" do
|
||||||
yaml = YAML.load_file(path)
|
yaml = load_yaml(path)
|
||||||
locale = extract_locale(path)
|
locale = extract_locale(path)
|
||||||
|
|
||||||
expect(yaml.keys).to eq([locale])
|
expect(yaml.keys).to eq([locale])
|
||||||
|
@ -62,7 +70,7 @@ RSpec.describe "i18n integrity checks" do
|
||||||
end
|
end
|
||||||
|
|
||||||
Dir["#{Rails.root}/**/locale*/*.en.yml"].each do |english_path|
|
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
|
context(english_path) do
|
||||||
it "has no duplicate keys" do
|
it "has no duplicate keys" do
|
||||||
|
@ -76,7 +84,7 @@ RSpec.describe "i18n integrity checks" do
|
||||||
|
|
||||||
context(path) do
|
context(path) do
|
||||||
locale = extract_locale(path)
|
locale = extract_locale(path)
|
||||||
yaml = YAML.load_file(path)
|
yaml = load_yaml(path)
|
||||||
|
|
||||||
it "has no duplicate keys" do
|
it "has no duplicate keys" do
|
||||||
duplicates = DuplicateKeyFinder.new.find_duplicates(path)
|
duplicates = DuplicateKeyFinder.new.find_duplicates(path)
|
||||||
|
|
|
@ -112,45 +112,45 @@ RSpec.describe ReviewableScore, type: :model do
|
||||||
it "returns the users weighted accuracy bonus" do
|
it "returns the users weighted accuracy bonus" do
|
||||||
user_stat.flags_agreed = 10
|
user_stat.flags_agreed = 10
|
||||||
user_stat.flags_disagreed = 42
|
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_agreed = 2
|
||||||
user_stat.flags_disagreed = 12
|
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_agreed = 1
|
||||||
user_stat.flags_disagreed = 6
|
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_agreed = 2
|
||||||
user_stat.flags_disagreed = 4
|
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_agreed = 7
|
||||||
user_stat.flags_disagreed = 3
|
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_agreed = 14
|
||||||
user_stat.flags_disagreed = 6
|
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
|
# Ignored flags don't count
|
||||||
user_stat.flags_agreed = 121
|
user_stat.flags_agreed = 121
|
||||||
user_stat.flags_disagreed = 44
|
user_stat.flags_disagreed = 44
|
||||||
user_stat.flags_ignored = 4
|
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_agreed = 9
|
||||||
user_stat.flags_disagreed = 2
|
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_agreed = 25
|
||||||
user_stat.flags_disagreed = 4
|
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_agreed = 120
|
||||||
user_stat.flags_disagreed = 12
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -158,7 +158,7 @@ RSpec.describe UserAvatarsController do
|
||||||
expect(response.status).to eq(200)
|
expect(response.status).to eq(200)
|
||||||
|
|
||||||
# this image should be really old so when it is fixed various algorithms pick it up
|
# 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
|
end
|
||||||
|
|
||||||
it 'serves image even if size missing and its in local mode' do
|
it 'serves image even if size missing and its in local mode' do
|
||||||
|
|
Loading…
Reference in New Issue