Remove app/labor/random_gif.rb (#11611)

This commit is contained in:
Michael Kohl 2020-11-25 21:58:32 +07:00 committed by GitHub
parent 845e00797b
commit 82108ea8b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 55 deletions

View file

@ -1,32 +0,0 @@
class RandomGif
RANDOM_GIFS = {
"xjZtu4qi1biIo" => { aspect_ratio: 1.000 },
"12P29BwtrvsbbW" => { aspect_ratio: 0.760 },
"9PyhoXey73EpW" => { aspect_ratio: 0.753 },
"OcZp0maz6ALok" => { aspect_ratio: 1.000 },
"Is1O1TWV0LEJi" => { aspect_ratio: 0.565 },
"lz24Z42jLcTa8" => { aspect_ratio: 0.776 },
"g9582DNuQppxC" => { aspect_ratio: 0.562 },
"l4HodBpDmoMA5p9bG" => { aspect_ratio: 1.000 },
"3oxOCfV7z28QtXXAtO" => { aspect_ratio: 0.750 },
"y8Mz1yj13s3kI" => { aspect_ratio: 0.750 },
"111ebonMs90YLu" => { aspect_ratio: 0.750 },
"Sk5uipPXyBjfW" => { aspect_ratio: 0.422 },
"l0K48FkLfeSCzRA4M" => { aspect_ratio: 0.573 },
"3o7qDRd1DlF7P2TP3O" => { aspect_ratio: 0.517 },
"26h0qt6UOumsbJkyI" => { aspect_ratio: 0.442 },
"l0K4glBiv82lZ0Zuo" => { aspect_ratio: 0.563 },
"Gf3fU0qPtI6uk" => { aspect_ratio: 0.750 },
"5GoVLqeAOo6PK" => { aspect_ratio: 0.780 }
}.freeze
DEFAULT_RATIO = 1.000
def self.random_id
RANDOM_GIFS.keys.sample
end
def self.get_aspect_ratio(id)
RANDOM_GIFS.dig(id, :aspect_ratio) || DEFAULT_RATIO
end
end

View file

@ -0,0 +1,24 @@
module Constants
module RandomGifs
IDS = %w[
xjZtu4qi1biIo
12P29BwtrvsbbW
9PyhoXey73EpW
OcZp0maz6ALok
Is1O1TWV0LEJi
lz24Z42jLcTa8
g9582DNuQppxC
l4HodBpDmoMA5p9bG
3oxOCfV7z28QtXXAtO
y8Mz1yj13s3kI
111ebonMs90YLu
Sk5uipPXyBjfW
l0K48FkLfeSCzRA4M
3o7qDRd1DlF7P2TP3O
26h0qt6UOumsbJkyI
l0K4glBiv82lZ0Zuo
Gf3fU0qPtI6uk
5GoVLqeAOo6PK
].freeze
end
end

View file

@ -38,7 +38,8 @@ module Notifications
end
def json_data
{ article: Notifications.article_data(article), gif_id: RandomGif.random_id }
gif_id = Constants::RandomGifs::IDS.sample
{ article: Notifications.article_data(article), gif_id: gif_id }
end
def article_published_behind_time?

View file

@ -1,22 +0,0 @@
require "rails_helper"
RSpec.describe RandomGif, type: :labor do
describe "#random_id" do
it "returns a random gif ID from RANDOM_GIFS" do
id_options = described_class::RANDOM_GIFS.keys
expect(id_options).to include(described_class.random_id)
end
end
describe "#get_aspect_ratio" do
it "returns aspect ratio for given ID" do
gif_id = described_class.random_id
aspect_ratio = described_class::RANDOM_GIFS.dig(gif_id, :aspect_ratio)
expect(described_class.get_aspect_ratio(gif_id)).to eq(aspect_ratio)
end
it "returns default 1.00 when gif ID is not present" do
expect(described_class.get_aspect_ratio("not_there")).to eq(described_class::DEFAULT_RATIO)
end
end
end