require 'spec_helper' describe PostsController, :type => :controller do before(:each) do activate_authlogic end describe :index do it "should display a list of posts" do 2.times { |i| FactoryGirl.create(:spud_post) } get :index, {:blog_key => 'blog'} assigns(:posts).count.should be > 1 end it "should not display any posts" do Spud::Blog.config.query_for_user = ->(user){ if user.blank? '1=0' else {} end } get :index, {:blog_key => 'blog'} assigns(:posts).count.should be 0 Spud::Blog.config.query_for_user = nil end end describe :create_comment do it "should create a comment" do @post = FactoryGirl.create(:spud_post) post :create_comment, :blog_key => 'blog', :id => @post.url_name, :spud_post_comment => {:author => "Test User", :content => "Lorem Ipsum"} @post.comments.length.should be > 0 end it "should approve a comment by default if default_comment_approval is true" do Spud::Blog.configure do |config| config.default_comment_approval = true end @post = FactoryGirl.create(:spud_post) post :create_comment, :blog_key => 'blog', :id => @post.url_name, :spud_post_comment => {:author => "Test User", :content => "Lorem Ipsum"} @post.comments.first.approved.should be_true end it "should not approve a comment by default if default_comment_approval is false" do Spud::Blog.configure do |config| config.default_comment_approval = false end @post = FactoryGirl.create(:spud_post) post :create_comment, :blog_key => 'blog', :id => @post.url_name, :spud_post_comment => {:author => "Test User", :content => "Lorem Ipsum"} @post.comments.first.approved.should be_false end end end