From 82108ea8b50b7cbea3f8446f0755d484024097bd Mon Sep 17 00:00:00 2001 From: Michael Kohl Date: Wed, 25 Nov 2020 21:58:32 +0700 Subject: [PATCH] Remove app/labor/random_gif.rb (#11611) --- app/labor/random_gif.rb | 32 -------------------- app/lib/constants/random_gifs.rb | 24 +++++++++++++++ app/services/notifications/milestone/send.rb | 3 +- spec/labor/random_gif_spec.rb | 22 -------------- 4 files changed, 26 insertions(+), 55 deletions(-) delete mode 100644 app/labor/random_gif.rb create mode 100644 app/lib/constants/random_gifs.rb delete mode 100644 spec/labor/random_gif_spec.rb diff --git a/app/labor/random_gif.rb b/app/labor/random_gif.rb deleted file mode 100644 index 435b6acbb..000000000 --- a/app/labor/random_gif.rb +++ /dev/null @@ -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 diff --git a/app/lib/constants/random_gifs.rb b/app/lib/constants/random_gifs.rb new file mode 100644 index 000000000..1e4032a2e --- /dev/null +++ b/app/lib/constants/random_gifs.rb @@ -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 diff --git a/app/services/notifications/milestone/send.rb b/app/services/notifications/milestone/send.rb index d9806f2ac..b20cb3c3f 100644 --- a/app/services/notifications/milestone/send.rb +++ b/app/services/notifications/milestone/send.rb @@ -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? diff --git a/spec/labor/random_gif_spec.rb b/spec/labor/random_gif_spec.rb deleted file mode 100644 index 94b3c4462..000000000 --- a/spec/labor/random_gif_spec.rb +++ /dev/null @@ -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