1
0

Add coverage for StatusTrend and PreviewCardTrend models, add locales class method to RankedTrend (#32688)

This commit is contained in:
Matt Jankowski 2024-10-29 11:46:32 -04:00 committed by GitHub
parent df3b954720
commit babee06794
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 64 additions and 4 deletions

View File

@ -4,7 +4,7 @@ class Admin::Trends::LinksController < Admin::BaseController
def index def index
authorize :preview_card, :review? authorize :preview_card, :review?
@locales = PreviewCardTrend.pluck('distinct language') @locales = PreviewCardTrend.locales
@preview_cards = filtered_preview_cards.page(params[:page]) @preview_cards = filtered_preview_cards.page(params[:page])
@form = Trends::PreviewCardBatch.new @form = Trends::PreviewCardBatch.new
end end

View File

@ -4,7 +4,7 @@ class Admin::Trends::StatusesController < Admin::BaseController
def index def index
authorize [:admin, :status], :review? authorize [:admin, :status], :review?
@locales = StatusTrend.pluck('distinct language') @locales = StatusTrend.locales
@statuses = filtered_statuses.page(params[:page]) @statuses = filtered_statuses.page(params[:page])
@form = Trends::StatusBatch.new @form = Trends::StatusBatch.new
end end

View File

@ -9,6 +9,10 @@ module RankedTrend
end end
class_methods do class_methods do
def locales
distinct.pluck(:language)
end
def recalculate_ordered_rank def recalculate_ordered_rank
connection connection
.exec_update(<<~SQL.squish) .exec_update(<<~SQL.squish)

View File

@ -85,7 +85,7 @@ class Trends::Links < Trends::Base
end end
def request_review def request_review
PreviewCardTrend.pluck('distinct language').flat_map do |language| PreviewCardTrend.locales.flat_map do |language|
score_at_threshold = PreviewCardTrend.where(language: language).allowed.by_rank.ranked_below(options[:review_threshold]).first&.score || 0 score_at_threshold = PreviewCardTrend.where(language: language).allowed.by_rank.ranked_below(options[:review_threshold]).first&.score || 0
preview_card_trends = PreviewCardTrend.where(language: language).not_allowed.joins(:preview_card) preview_card_trends = PreviewCardTrend.where(language: language).not_allowed.joins(:preview_card)

View File

@ -78,7 +78,7 @@ class Trends::Statuses < Trends::Base
end end
def request_review def request_review
StatusTrend.pluck('distinct language').flat_map do |language| StatusTrend.locales.flat_map do |language|
score_at_threshold = StatusTrend.where(language: language, allowed: true).by_rank.ranked_below(options[:review_threshold]).first&.score || 0 score_at_threshold = StatusTrend.where(language: language, allowed: true).by_rank.ranked_below(options[:review_threshold]).first&.score || 0
status_trends = StatusTrend.where(language: language, allowed: false).joins(:status).includes(status: :account) status_trends = StatusTrend.where(language: language, allowed: false).joins(:status).includes(status: :account)

View File

@ -0,0 +1,5 @@
# frozen_string_literal: true
Fabricator(:preview_card_trend) do
preview_card
end

View File

@ -0,0 +1,6 @@
# frozen_string_literal: true
Fabricator(:status_trend) do
status
account
end

View File

@ -0,0 +1,22 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe PreviewCardTrend do
describe 'Associations' do
it { is_expected.to belong_to(:preview_card).required }
end
describe '.locales' do
before do
Fabricate :preview_card_trend, language: 'en'
Fabricate :preview_card_trend, language: 'en'
Fabricate :preview_card_trend, language: 'es'
end
it 'returns unique set of languages' do
expect(described_class.locales)
.to eq(['en', 'es'])
end
end
end

View File

@ -0,0 +1,23 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe StatusTrend do
describe 'Associations' do
it { is_expected.to belong_to(:account).required }
it { is_expected.to belong_to(:status).required }
end
describe '.locales' do
before do
Fabricate :status_trend, language: 'en'
Fabricate :status_trend, language: 'en'
Fabricate :status_trend, language: 'es'
end
it 'returns unique set of languages' do
expect(described_class.locales)
.to eq(['en', 'es'])
end
end
end