Remove app/labor/color_from_image.rb (#11825)
* Remove app/labor/color_from_image.rb * Remove miro gem * Delete TODO
This commit is contained in:
parent
02f0a9ca1d
commit
59e2f5a025
7 changed files with 1 additions and 109 deletions
1
Gemfile
1
Gemfile
|
|
@ -57,7 +57,6 @@ gem "kaminari", "~> 1.2" # A Scope & Engine based, clean, powerful, customizable
|
|||
gem "katex", "~> 0.6.0" # This rubygem enables you to render TeX math to HTML using KaTeX. It uses ExecJS under the hood
|
||||
gem "liquid", "~> 4.0" # A secure, non-evaling end user template engine with aesthetic markup
|
||||
gem "mini_racer", "~> 0.3.1" # Minimal embedded v8
|
||||
# gem "miro", "~> 0.4" # Extract colors from image
|
||||
gem "nokogiri", "~> 1.10" # HTML, XML, SAX, and Reader parser
|
||||
gem "octokit", "~> 4.19" # Simple wrapper for the GitHub API
|
||||
gem "oj", "~> 3.10" # JSON parser and object serializer
|
||||
|
|
|
|||
|
|
@ -1,17 +0,0 @@
|
|||
class ColorFromImage
|
||||
def initialize(url)
|
||||
@url = url
|
||||
end
|
||||
|
||||
def main
|
||||
"#dddddd"
|
||||
# get_hex
|
||||
rescue StandardError
|
||||
"#dddddd"
|
||||
end
|
||||
|
||||
def get_hex
|
||||
# colors = Miro::DominantColors.new @url
|
||||
HexComparer.new(colors.to_hex).biggest # Always take the biggest hex (aka lightest color)
|
||||
end
|
||||
end
|
||||
|
|
@ -100,7 +100,7 @@ class Article < ApplicationRecord
|
|||
after_update_commit :update_notifications, if: proc { |article|
|
||||
article.notifications.any? && !article.saved_changes.empty?
|
||||
}
|
||||
after_commit :async_score_calc, :update_main_image_background_hex, :touch_collection, on: %i[create update]
|
||||
after_commit :async_score_calc, :touch_collection, on: %i[create update]
|
||||
after_commit :index_to_elasticsearch, on: %i[create update]
|
||||
after_commit :remove_from_elasticsearch, on: [:destroy]
|
||||
|
||||
|
|
@ -436,13 +436,6 @@ class Article < ApplicationRecord
|
|||
self.tag_list = tag_list.map { |tag| Tag.find_preferred_alias_for(tag) }
|
||||
end
|
||||
|
||||
def update_main_image_background_hex
|
||||
return unless saved_changes.key?("main_image")
|
||||
return if main_image.blank? || main_image_background_hex_color != "#dddddd"
|
||||
|
||||
Articles::UpdateMainImageBackgroundHexWorker.perform_async(id)
|
||||
end
|
||||
|
||||
def detect_human_language
|
||||
return if language.present?
|
||||
|
||||
|
|
|
|||
|
|
@ -1,15 +0,0 @@
|
|||
module Articles
|
||||
class UpdateMainImageBackgroundHexWorker
|
||||
include Sidekiq::Worker
|
||||
|
||||
sidekiq_options queue: :high_priority, retry: 10, lock: :until_executing
|
||||
|
||||
def perform(article_id)
|
||||
article = Article.find_by(id: article_id)
|
||||
|
||||
return unless article
|
||||
|
||||
article.update_column(:main_image_background_hex_color, ColorFromImage.new(article.main_image).main)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe ColorFromImage, type: :labor do
|
||||
it "returns a color" do
|
||||
color = described_class.new(File.expand_path("spec/fixtures/files/image_gps_data.jpg")).main
|
||||
|
||||
expected_regexp = /\A#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})\z/
|
||||
expect(color).to match(expected_regexp)
|
||||
end
|
||||
end
|
||||
|
|
@ -759,37 +759,6 @@ RSpec.describe Article, type: :model do
|
|||
end
|
||||
end
|
||||
|
||||
describe "main image background color" do
|
||||
let(:article) { build(:article, user: user) }
|
||||
|
||||
it "enqueues a job to update the main image background if #dddddd" do
|
||||
article.main_image_background_hex_color = "#dddddd"
|
||||
allow(article).to receive(:update_main_image_background_hex).and_call_original
|
||||
sidekiq_assert_enqueued_with(job: Articles::UpdateMainImageBackgroundHexWorker) do
|
||||
article.save
|
||||
end
|
||||
expect(article).to have_received(:update_main_image_background_hex)
|
||||
end
|
||||
|
||||
it "does not enqueue a job to update the main image background if not #dddddd" do
|
||||
article.main_image_background_hex_color = "#fff000"
|
||||
allow(article).to receive(:update_main_image_background_hex).and_call_original
|
||||
sidekiq_assert_no_enqueued_jobs(only: Articles::UpdateMainImageBackgroundHexWorker) do
|
||||
article.save
|
||||
end
|
||||
expect(article).to have_received(:update_main_image_background_hex)
|
||||
end
|
||||
|
||||
it "does not enqueue a job if main_image has not changed" do
|
||||
article.save
|
||||
allow(article).to receive(:update_main_image_background_hex).and_call_original
|
||||
sidekiq_assert_no_enqueued_jobs(only: Articles::UpdateMainImageBackgroundHexWorker) do
|
||||
article.save
|
||||
end
|
||||
expect(article).to have_received(:update_main_image_background_hex)
|
||||
end
|
||||
end
|
||||
|
||||
describe "spam" do
|
||||
before do
|
||||
allow(SiteConfig).to receive(:mascot_user_id).and_return(user.id)
|
||||
|
|
|
|||
|
|
@ -1,27 +0,0 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe Articles::UpdateMainImageBackgroundHexWorker, type: :job do
|
||||
subject(:worker) { described_class.new }
|
||||
|
||||
describe "#perform" do
|
||||
context "with article" do
|
||||
let(:article) { create(:article) }
|
||||
|
||||
it "updates articles main image background hex" do
|
||||
color_from_image = double
|
||||
allow(color_from_image).to receive(:main).and_return("#eee")
|
||||
allow(ColorFromImage).to receive(:new).and_return(color_from_image)
|
||||
|
||||
worker.perform(article.id)
|
||||
|
||||
expect(article.reload.main_image_background_hex_color).to eql("#eee")
|
||||
end
|
||||
end
|
||||
|
||||
context "without article" do
|
||||
it "does not error" do
|
||||
expect { worker.perform(nil) }.not_to raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Reference in a new issue