From efc12fae1871142bd0cee733f8a7b1d02e519ff2 Mon Sep 17 00:00:00 2001 From: dougbradbury Date: Sun, 16 Jun 2013 12:02:34 -0500 Subject: limit rss feed for some services that have limits (like feedburner) --- app/controllers/refinery/blog/posts_controller.rb | 6 +++++- .../refinery/blog/posts_controller_spec.rb | 24 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 spec/controllers/refinery/blog/posts_controller_spec.rb diff --git a/app/controllers/refinery/blog/posts_controller.rb b/app/controllers/refinery/blog/posts_controller.rb index 999b49a..dbb2af8 100644 --- a/app/controllers/refinery/blog/posts_controller.rb +++ b/app/controllers/refinery/blog/posts_controller.rb @@ -10,7 +10,11 @@ module Refinery def index # Rss feeders are greedy. Let's give them every blog post instead of paginating. - (@posts = Post.live.includes(:comments, :categories)) if request.format.rss? + if request.format.rss? + @posts = Post.live.includes(:comments, :categories) + #limit rss feed for services (like feedburner) who have max size + @posts = Post.recent(params["max_results"]) if params["max_results"].present? + end respond_with (@posts) do |format| format.html format.rss { render :layout => false } diff --git a/spec/controllers/refinery/blog/posts_controller_spec.rb b/spec/controllers/refinery/blog/posts_controller_spec.rb new file mode 100644 index 0000000..ee948a5 --- /dev/null +++ b/spec/controllers/refinery/blog/posts_controller_spec.rb @@ -0,0 +1,24 @@ +require "spec_helper" + +module Refinery + module Blog + describe PostsController do + before do + FactoryGirl.create(:blog_post, :title => "blogpost_one") + FactoryGirl.create(:blog_post, :title => "blogpost_two") + FactoryGirl.create(:blog_post, :title => "blogpost_three") + end + + it "should not limit rss feed" do + get :index, :format => :rss + assigns[:posts].size.should == 3 + end + + it "should limit rss feed" do + get :index, :format => :rss, :max_results => 2 + assigns[:posts].count.should == 2 + end + end + end +end + -- cgit v1.2.3