public
Created

  • Download Gist
article_index.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
class ArticleIndexTest < ActiveSupport::TestCase
def setup
# create a parent page, which will display our index list
page_index = Cms::Page.new(
:slug => "top_page",
:label => "Page Top")
page_index.save!
 
# create Children, so we have something to list
(3.times).each { |i|
children << Cms::Page.new(
:parent => page_index,
:slug => "child_page_#{i}",
:label => "Page #{i}")
}
children.save!
end
 
def test_list_items
# Does the method return something containing our expected data?
assert_select ArticleIndex.list_articles, "child_page_1"
assert_select ArticleIndex.list_articles, 'label', "Page 1"
end
end
 
class ArticleIndex
def list_articles
articles = Articles.find(:parent => page_index)
articles.each { |article|
"<a href='#{article.path}' id='#{article.slug}'>#{article.label}</p>"
}
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.