Add .present? check (#6302)
This commit is contained in:
parent
f05a351906
commit
4e1ccf4a3a
2 changed files with 23 additions and 3 deletions
|
|
@ -550,12 +550,12 @@ class Article < ApplicationRecord
|
|||
|
||||
def remove_tag_adjustments_from_tag_list
|
||||
tags_to_remove = TagAdjustment.where(article_id: id, adjustment_type: "removal", status: "committed").pluck(:tag_name)
|
||||
tag_list.remove(tags_to_remove, parser: ActsAsTaggableOn::TagParser) if tags_to_remove
|
||||
tag_list.remove(tags_to_remove, parser: ActsAsTaggableOn::TagParser) if tags_to_remove.present?
|
||||
end
|
||||
|
||||
def add_tag_adjustments_to_tag_list
|
||||
tags_to_add = TagAdjustment.where(article_id: id, adjustment_type: "addition", status: "committed").pluck(:tag_name)
|
||||
tag_list.add(tags_to_add, parser: ActsAsTaggableOn::TagParser) if tags_to_add
|
||||
tag_list.add(tags_to_add, parser: ActsAsTaggableOn::TagParser) if tags_to_add.present?
|
||||
end
|
||||
|
||||
def validate_video
|
||||
|
|
|
|||
|
|
@ -31,7 +31,9 @@ RSpec.describe Article, type: :model do
|
|||
|
||||
context "when published" do
|
||||
before do
|
||||
allow(subject).to receive(:published?).and_return(true) # rubocop:disable RSpec/NamedSubject
|
||||
# rubocop:disable RSpec/NamedSubject
|
||||
allow(subject).to receive(:published?).and_return(true)
|
||||
# rubocop:enable RSpec/NamedSubject
|
||||
end
|
||||
|
||||
it { is_expected.to validate_presence_of(:slug) }
|
||||
|
|
@ -116,6 +118,24 @@ RSpec.describe Article, type: :model do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "tag validation" do
|
||||
let(:article) { build(:article, user: user) }
|
||||
|
||||
# See https://github.com/thepracticaldev/dev.to/pull/6302
|
||||
# rubocop:disable RSpec/VerifiedDoubles
|
||||
it "does not modify the tag list if there are no adjustments" do
|
||||
allow(TagAdjustment).to receive(:where).and_return(TagAdjustment.none)
|
||||
allow(article).to receive(:tag_list).and_return(spy("tag_list"))
|
||||
|
||||
article.save
|
||||
|
||||
# We expect this to happen once in #evaluate_front_matter
|
||||
expect(article.tag_list).to have_received(:add).once
|
||||
expect(article.tag_list).not_to have_received(:remove)
|
||||
end
|
||||
# rubocop:enable RSpec/VerifiedDoubles
|
||||
end
|
||||
end
|
||||
|
||||
context "when data is extracted from evaluation of the front matter during validation" do
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue