Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed browsing posts by tag, category and date

  • Loading branch information...
commit 86e7452cf5d863e4e54729d88c6708bef0950edf 1 parent 66f4036
Juan  Alvarez alce authored
4 app/models/blog.rb
View
@@ -25,8 +25,8 @@ def self.default_template
end
def self.posts_finder(finder, options)
- if options[:tags]
- finder = finder.tagged_with(options[:tags])
+ if options[:tag]
+ finder = finder.tagged_with(options[:tag])
end
if options[:exclude_tags]
finder = finder.not_tagged_with(options[:exclude_tags])
5 app/models/blog_observer.rb
View
@@ -111,11 +111,12 @@ def reload_routes
def create_route(page, name, pattern)
route = page.page_routes.build(:name => name, :pattern => pattern, :code => "")
- route.add_condition(:method, "get")
+ route.send(:create_without_callbacks)
+ route.add_condition(:method, "get").save
route.add_requirement(:year, '\d{4,}') if pattern.include?(":year")
route.add_requirement(:month, '\d{2,}') if pattern.include?(":month")
route.add_requirement(:day, '\d{2,}') if pattern.include?(":day")
- route.send(:create_without_callbacks)
+ route.requirements.each(&:save)
end
def create_portlet(page, name, portlet_class)
2  test/blog_test_helper.rb
View
@@ -20,7 +20,7 @@ def create_test_data
@general = Category.create!(:name => "General", :category_type => @category_type)
opts = {:blog => @blog, :publish_on_save => true}
- @first_post = Factory(:blog_post, opts.merge(:category => @general, :published_at => Time.utc(2008, 7, 5, 6)))
+ @first_post = Factory(:blog_post, opts.merge(:category => @general, :published_at => Time.utc(2008, 7, 5, 6), :name => "The first Post"))
@foo_post_1 = Factory(:blog_post, opts.merge(:category => @stuff, :published_at => Time.utc(2008, 7, 5, 12), :tag_list => "foo stuff"))
@foo_post_2 = Factory(:blog_post, opts.merge(:category => @general, :published_at => Time.utc(2008, 7, 21)))
@bar_post_1 = Factory(:blog_post, opts.merge(:category => @stuff, :published_at => Time.utc(2008, 9, 2), :tag_list => "foo stuff"))
55 test/functional/blog_controller_test.rb
View
@@ -37,36 +37,27 @@ def setup
assert_select ".blog_post", 3
end
- # test "tagging" do
- # get :show, :path => ['myblog'], :tag => 'foo'
- # assert_response :success
- # assert_equal 6, PageRoute.count
- # end
- # test "list of blog posts by tag" do
- # get :show, :path => ['myblog'], :tag => 'foo'
- # puts @response.body
- # assert_response :success
- # assert_select ".blog_post", 2
- # end
- #
- # def test_list_of_blog_posts_in_day
- # get :show, :path => ["myblog", "posts_in_day"],
- # :year => 2008, :month => 7, :day => 5
- # assert_response :success
- # assert_select ".blog_post", 2
- # end
- #
- # def test_list_of_blog_posts_in_month
- # get :show, :path => ["blog", "posts_in_month"],
- # :year => 2008, :month => 7
- # assert_response :success
- # assert_select ".blog_post", 3
- # end
- #
- # def test_list_of_blog_posts_in_year
- # get :show, :path => ["blog", "posts_in_year"],
- # :year => 2008
- # assert_response :success
- # assert_select ".blog_post", 4
- # end
+ test "list of blog posts by tag" do
+ get :show, :path => ['myblog'], :tag => 'foo'
+ assert_response :success
+ assert_select ".blog_post", 2
+ end
+
+ test "list_of_blog_posts_in_day" do
+ get :show, :path => ["myblog"], :year => 2008, :month => 7, :day => 5
+ assert_response :success
+ assert_select ".blog_post", 2
+ end
+
+ test "list_of_blog_posts_in_month" do
+ get :show, :path => ["myblog"], :year => 2008, :month => 7
+ assert_response :success
+ assert_select ".blog_post", 3
+ end
+
+ test "list_of_blog_posts_in_year" do
+ get :show, :path => ["myblog"], :year => 2008
+ assert_response :success
+ assert_select ".blog_post", 4
+ end
end
44 test/functional/blog_post_controller_test.rb
View
@@ -2,38 +2,30 @@
class BlogPostControllerTest < ActionController::TestCase
tests Cms::ContentController
-
+
def setup
seed_bcms_data
seed_blog_data
create_test_data
end
- # def test_show_post
- # get :show, :path => ["myblog"],
- # :year => 2008,
- # :month => 07,
- # :day => 05,
- # :slug => @first_post.name.to_slug
- # puts @response.body
- #
- # assert_response :success
- # assert_select "title", @first_post.name
- # # assert_select ".blog_post", 1
- #
- # # assert_select "#blog_post_#{@first_post.id}" do
- # # assert_select "h2 a", @first_post.name
- # # assert_select "p.body", @first_post.body
- # # assert_select "p.meta a", "General"
- # # assert_select "p.meta a", "0 Comments"
- # # end
- # end
-
- def test_non_existent_slug_should_return_404
- get :show, :path => ["myblog"],
- :year => 2005, :month => 6, :day => 14,
- :slug => "not-here"
+ test "show_post" do
+ get :show, :path => ['myblog', 'post'], :year => 2008, :month => 07, :day => 05, :slug => 'the-first-post'
+ assert_response :success
+
+ assert_select "title", @first_post.name
+ assert_select ".blog_post", 1
+
+ assert_select "#blog_post_#{@first_post.id}" do
+ assert_select "h2 a", @first_post.name
+ assert_select "div.body", @first_post.body
+ assert_select "div.meta a", "General"
+ assert_select "div.meta a", "0 Comments"
+ end
+ end
+
+ test "non_existent_post_should_return_404" do
+ get :show, :path => ["myblog"], :year => 2005, :month => 6, :day => 14, :slug => "not-here"
assert_response :not_found
end
-
end
Please sign in to comment.
Something went wrong with that request. Please try again.