mirror of
https://github.com/discourse/discourse.git
synced 2025-09-05 08:59:27 +08:00
refactor Category
* move callback bodies to separate methods (easier to test)
This commit is contained in:
parent
35d5c899dd
commit
a1825fece9
2 changed files with 35 additions and 51 deletions
|
@ -3,7 +3,6 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Category do
|
||||
|
||||
it { should validate_presence_of :user_id }
|
||||
it { should validate_presence_of :name }
|
||||
|
||||
|
@ -20,13 +19,11 @@ describe Category do
|
|||
it { should have_many :featured_topics }
|
||||
|
||||
describe "uncategorized name" do
|
||||
|
||||
let(:category) { Fabricate.build(:category, name: SiteSetting.uncategorized_name) }
|
||||
|
||||
it "is invalid to create a category with the reserved name" do
|
||||
category.should_not be_valid
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "short name" do
|
||||
|
@ -39,11 +36,9 @@ describe Category do
|
|||
it 'has one topic' do
|
||||
Topic.where(category_id: category.id).count.should == 1
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'caching' do
|
||||
|
||||
it "invalidates the site cache on creation" do
|
||||
Site.expects(:invalidate_cache).once
|
||||
Fabricate(:category)
|
||||
|
@ -63,17 +58,14 @@ describe Category do
|
|||
end
|
||||
|
||||
describe 'non-english characters' do
|
||||
|
||||
let(:category) { Fabricate(:category, name: "電車男") }
|
||||
|
||||
it "creates a blank slug, this is OK." do
|
||||
category.slug.should be_blank
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'after create' do
|
||||
|
||||
before do
|
||||
@category = Fabricate(:category)
|
||||
@topic = @category.topic
|
||||
|
@ -115,10 +107,7 @@ describe Category do
|
|||
@category.topic_url.should be_present
|
||||
end
|
||||
|
||||
|
||||
|
||||
describe "trying to change the category topic's category" do
|
||||
|
||||
before do
|
||||
@new_cat = Fabricate(:category, name: '2nd Category', user: @category.user)
|
||||
@topic.change_category(@new_cat.name)
|
||||
|
@ -141,7 +130,6 @@ describe Category do
|
|||
end
|
||||
|
||||
describe 'destroy' do
|
||||
|
||||
before do
|
||||
@category = Fabricate(:category)
|
||||
@category_id = @category.id
|
||||
|
@ -156,17 +144,14 @@ describe Category do
|
|||
it 'deletes the forum topic' do
|
||||
Topic.exists?(id: @topic_id).should be_false
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'update_stats' do
|
||||
|
||||
before do
|
||||
@category = Fabricate(:category)
|
||||
end
|
||||
|
||||
context 'with regular topics' do
|
||||
|
||||
before do
|
||||
@category.topics << Fabricate(:topic, user: @category.user)
|
||||
Category.update_stats
|
||||
|
@ -184,11 +169,9 @@ describe Category do
|
|||
it 'updates topics_year' do
|
||||
@category.topics_year.should == 1
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context 'with deleted topics' do
|
||||
|
||||
before do
|
||||
@category.topics << Fabricate(:deleted_topic,
|
||||
user: @category.user)
|
||||
|
@ -207,9 +190,6 @@ describe Category do
|
|||
it 'does not count deleted topics for topics_year' do
|
||||
@category.topics_year.should == 0
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue