mirror of
https://github.com/discourse/discourse.git
synced 2025-06-04 20:34:50 +08:00
REFACTOR: New spec tests and code improvement
This commit is contained in:
@ -10,14 +10,15 @@ describe Tag do
|
||||
end
|
||||
end
|
||||
|
||||
let(:tag) { Fabricate(:tag) }
|
||||
let(:topic) { Fabricate(:topic, tags: [tag]) }
|
||||
|
||||
before do
|
||||
SiteSetting.tagging_enabled = true
|
||||
SiteSetting.min_trust_level_to_tag_topics = 0
|
||||
end
|
||||
|
||||
it "can delete tags on deleted topics" do
|
||||
tag = Fabricate(:tag)
|
||||
topic = Fabricate(:topic, tags: [tag])
|
||||
topic.trash!
|
||||
expect { tag.destroy }.to change { Tag.count }.by(-1)
|
||||
end
|
||||
@ -94,4 +95,14 @@ describe Tag do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "topic counts" do
|
||||
it "should exclude private message topics" do
|
||||
topic
|
||||
Fabricate(:private_message_topic, tags: [tag])
|
||||
described_class.ensure_consistency!
|
||||
tag.reload
|
||||
expect(tag.topic_count).to eq(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
47
spec/models/topic_tag_spec.rb
Normal file
47
spec/models/topic_tag_spec.rb
Normal file
@ -0,0 +1,47 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe TopicTag do
|
||||
|
||||
let(:topic) { Fabricate(:topic) }
|
||||
let(:tag) { Fabricate(:tag) }
|
||||
let(:topic_tag) { Fabricate(:topic_tag, topic: topic, tag: tag) }
|
||||
|
||||
context '#after_create' do
|
||||
|
||||
it "tag topic_count should be increased" do
|
||||
expect {
|
||||
topic_tag
|
||||
}.to change(tag, :topic_count).by(1)
|
||||
end
|
||||
|
||||
it "tag topic_count should not be increased" do
|
||||
topic.archetype = Archetype.private_message
|
||||
|
||||
expect {
|
||||
topic_tag
|
||||
}.to change(tag, :topic_count).by(0)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context '#after_destroy' do
|
||||
|
||||
it "tag topic_count should be decreased" do
|
||||
topic_tag
|
||||
expect {
|
||||
topic_tag.destroy
|
||||
}.to change(tag, :topic_count).by(-1)
|
||||
end
|
||||
|
||||
it "tag topic_count should not be decreased" do
|
||||
topic.archetype = Archetype.private_message
|
||||
topic_tag
|
||||
|
||||
expect {
|
||||
topic_tag.destroy
|
||||
}.to change(tag, :topic_count).by(0)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
Reference in New Issue
Block a user