Permalink
Browse files

Merge branch 'categories'

  • Loading branch information...
2 parents adc6da6 + ea65828 commit c0af9571abb1ea03a812e994115762e5e4a4769b @ixti committed Sep 3, 2011
Showing with 20 additions and 6 deletions.
  1. +4 −2 lib/toto.rb
  2. +5 −0 test/templates/category.rhtml
  3. +11 −4 test/toto_test.rb
View
@@ -103,6 +103,7 @@ def archives opts = {}
end
if !(category = opts.delete(:category)).nil?
+ opts[:category] = category
entries = entries.select do |article|
!article[:category].nil? && article[:category] =~ /^#{category}/
end
@@ -131,8 +132,9 @@ def go route, env = {}, type = :html
context[article("#{$1}#{$2.tr('/', '-')}"), :article]
elsif 4 > route.size and route.first =~ /\d{4}/
context[archives(:date => route * '-'), :archives]
- elsif 1 < route.size and route.first == 'category'
- context[archives(:category => route.slice(1..-1) * '/'), :archives]
+ elsif route.first == 'category'
+ if 1 < route.size then context[archives(:category => route.slice(1..-1) * '/'), :category]
+ else http 400 end
elsif route.first == 'tag'
if 2 == route.size then context[archives(:tag => route.last), :tag]
else http 400 end
@@ -0,0 +1,5 @@
+<h1><%= @category %></h1>
+<% for entry in archives %>
+ <li class="entry"><%= entry.title %></li>
+<% end %>
+
View
@@ -86,6 +86,17 @@
should("includes the year & month") { topic.body }.includes_html("h1" => /2009\/12/)
end
+ context "through /archive" do
+ setup { @toto.get('/archive') }
+ end
+ end
+
+ context "GET category archive" do
+ context "without category specified" do
+ setup { @toto.get('/category/') }
+ asserts("returns a 400") { topic.status }.equals 400
+ end
+
context "through a category (with subcategories)" do
setup { @toto.get('/category/cat') }
asserts("returns a 200") { topic.status }.equals 200
@@ -97,10 +108,6 @@
asserts("returns a 200") { topic.status }.equals 200
should("includes the entries of this category only") { topic.body }.includes_elements("li.entry", 1)
end
-
- context "through /archive" do
- setup { @toto.get('/archive') }
- end
end
context "GET to an unknown route with a custom error" do

0 comments on commit c0af957

Please sign in to comment.