Fix a case where a random topic with null slug will be rendered instead of 404

This commit is contained in:
Neil Lalonde
2013-06-07 14:17:12 -04:00
parent 668a4a3042
commit 169125e96d
3 changed files with 19 additions and 1 deletions

View File

@ -383,6 +383,23 @@ describe TopicsController do
expect(response.status).to eq(404)
end
it 'returns a 404 when slug and topic id do not match a topic' do
xhr :get, :show, topic_id: 123123, slug: 'topic-that-is-made-up'
expect(response.status).to eq(404)
end
context 'a topic with nil slug exists' do
before do
@nil_slug_topic = Fabricate(:topic)
Topic.connection.execute("update topics set slug=null where id = #{@nil_slug_topic.id}") # can't find a way to set slug column to null using the model
end
it 'returns a 404 when slug and topic id do not match a topic' do
xhr :get, :show, topic_id: 123123, slug: 'topic-that-is-made-up'
expect(response.status).to eq(404)
end
end
it 'records a view' do
lambda { xhr :get, :show, topic_id: topic.id, slug: topic.slug }.should change(View, :count).by(1)
end