From 3d76539d2ff554dc23824e71b3475c1356eea5f1 Mon Sep 17 00:00:00 2001 From: Rodrigo Souto Date: Tue, 23 Feb 2010 10:15:41 -0300 Subject: [PATCH] Raising 'not found' page while accessing an unexistent topic in a section --- app/models/doc_section.rb | 7 ++++++- test/unit/doc_section_test.rb | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/models/doc_section.rb b/app/models/doc_section.rb index 68b8f82..03269d9 100644 --- a/app/models/doc_section.rb +++ b/app/models/doc_section.rb @@ -5,7 +5,12 @@ class DocSection < DocItem end def find(id) - items.find {|item| item.id == id } + topic = items.find {|item| item.id == id } + if topic + topic + else + raise DocItem::NotFound + end end def self.all(language = 'en', force = false) diff --git a/test/unit/doc_section_test.rb b/test/unit/doc_section_test.rb index 8912f31..d9074b4 100644 --- a/test/unit/doc_section_test.rb +++ b/test/unit/doc_section_test.rb @@ -97,4 +97,12 @@ class DocSectionTest < ActiveSupport::TestCase end end + should 'raise DocTopic::NotFound when trying to find an unexisting topic inside a section' do + section = DocSection.all.first + assert_raise DocItem::NotFound do + section.find('unexisting') + end + end + + end -- libgit2 0.21.2