diff --git a/app/assets/javascripts/discourse/models/topic.js.coffee b/app/assets/javascripts/discourse/models/topic.js.coffee index 30705f4a0..dd95bd26b 100644 --- a/app/assets/javascripts/discourse/models/topic.js.coffee +++ b/app/assets/javascripts/discourse/models/topic.js.coffee @@ -25,7 +25,9 @@ Discourse.Topic = Discourse.Model.extend Discourse.Presence, ).property('categoryName', 'categories') url: (-> - "/t/#{@get('slug')}/#{@get('id')}" + slug = @get('slug') + slug = "topic" if slug.isBlank() + "/t/#{slug}/#{@get('id')}" ).property('id', 'slug') # Helper to build a Url with a post number diff --git a/app/models/topic.rb b/app/models/topic.rb index 8bd8813d4..8c26deca3 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -129,7 +129,6 @@ class Topic < ActiveRecord::Base end end - def new_version_required? return true if title_changed? return true if category_id_changed? @@ -497,7 +496,9 @@ class Topic < ActiveRecord::Base end def slug - Slug.for(title) + result = Slug.for(title) + return "topic" if result.blank? + result end def last_post_url diff --git a/spec/controllers/list_controller_spec.rb b/spec/controllers/list_controller_spec.rb index 6605e738b..6827c0390 100644 --- a/spec/controllers/list_controller_spec.rb +++ b/spec/controllers/list_controller_spec.rb @@ -37,7 +37,7 @@ describe ListController do context 'with a link that includes an id' do before do - xhr :get, :category, category: "#{category.slug}-#{category.id}" + xhr :get, :category, category: "#{category.id}-#{category.slug}" end it { should respond_with(:success) } diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index 65f57f0e4..ecb1f3bc7 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -49,6 +49,22 @@ describe Topic do end + context 'slug' do + + let(:title) { "hello world topic" } + let(:slug) { "hello-world-slug" } + + it "returns a Slug for a title" do + Slug.expects(:for).with(title).returns(slug) + Fabricate.build(:topic, title: title).slug.should == slug + end + + it "returns 'topic' when the slug is empty (say, non-english chars)" do + Slug.expects(:for).with(title).returns("") + Fabricate.build(:topic, title: title).slug.should == "topic" + end + + end context 'topic title uniqueness' do