Skip to content

Instantly share code, notes, and snippets.

@jhenry
Created May 20, 2011 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhenry/983383 to your computer and use it in GitHub Desktop.
Save jhenry/983383 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment