Add Reviewable model concern (#31152)

This commit is contained in:
Matt Jankowski 2024-09-03 11:37:45 -04:00 committed by GitHub
commit 7c26e5e4a1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 85 additions and 48 deletions

View file

@ -3,6 +3,8 @@
require 'rails_helper'
RSpec.describe Account do
include_examples 'Reviewable'
context 'with an account record' do
subject { Fabricate(:account) }

View file

@ -3,6 +3,8 @@
require 'rails_helper'
describe PreviewCardProvider do
include_examples 'Reviewable'
describe 'scopes' do
let(:trendable_and_reviewed) { Fabricate(:preview_card_provider, trendable: true, reviewed_at: 5.days.ago) }
let(:not_trendable_and_not_reviewed) { Fabricate(:preview_card_provider, trendable: false, reviewed_at: nil) }

View file

@ -3,6 +3,8 @@
require 'rails_helper'
RSpec.describe Tag do
include_examples 'Reviewable'
describe 'validations' do
it 'invalid with #' do
expect(described_class.new(name: '#hello_world')).to_not be_valid

View file

@ -0,0 +1,54 @@
# frozen_string_literal: true
shared_examples 'Reviewable' do
subject { described_class.new(reviewed_at: reviewed_at, requested_review_at: requested_review_at) }
let(:reviewed_at) { nil }
let(:requested_review_at) { nil }
describe '#requires_review?' do
it { is_expected.to be_requires_review }
context 'when reviewed_at is not null' do
let(:reviewed_at) { 5.days.ago }
it { is_expected.to_not be_requires_review }
end
end
describe '#reviewed?' do
it { is_expected.to_not be_reviewed }
context 'when reviewed_at is not null' do
let(:reviewed_at) { 5.days.ago }
it { is_expected.to be_reviewed }
end
end
describe '#requested_review?' do
it { is_expected.to_not be_requested_review }
context 'when requested_reviewed_at is not null' do
let(:requested_review_at) { 5.days.ago }
it { is_expected.to be_requested_review }
end
end
describe '#requires_review_notification?' do
it { is_expected.to be_requires_review_notification }
context 'when reviewed_at is not null' do
let(:reviewed_at) { 5.days.ago }
it { is_expected.to_not be_requires_review_notification }
end
context 'when requested_reviewed_at is not null' do
let(:requested_review_at) { 5.days.ago }
it { is_expected.to_not be_requires_review_notification }
end
end
end