Support non-english topic titles

This commit is contained in:
Robin Ward 2013-02-14 17:13:03 -05:00
parent 5d4efa9100
commit 37b0c168bf
4 changed files with 23 additions and 4 deletions

View file

@ -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

View file

@ -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

View file

@ -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) }

View file

@ -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