require 'spec_helper' describe Manage::PostsController do render_views context "administrator" do login_admin before(:each) do @attrs = FactoryGirl.attributes_for(:post) end it "should render new action" do get :new response.should be_success response.should render_template("new") end it "should create new post" do lambda { post :create, :post => @attrs }.should change { Post.count }.by(1) end context "exists default post" do before(:each) do @post = FactoryGirl.create(:post) end it "should render index action" do get :index assigns(:posts).should include(@post) response.should render_template('index') end it "should render edit action" do controller.should_receive :edit get :edit, :id => @post.id end it "should update post" do put :update, :id => @post.id, :post => @attrs assigns(:post).should be_valid response.should redirect_to(manage_posts_path) end it "should destroy post" do lambda { delete :destroy, :id => @post.id }.should change { Post.count }.by(-1) end end end context "anonymous user" do user_logout it "should not render index action" do controller.should_not_receive :index get :index end it "should not render new action" do controller.should_not_receive :new get :new end it "should not render create action" do controller.should_not_receive :create post :create end context "with exists post" do before(:each) do @post = FactoryGirl.create(:post) end it "should not render edit action" do controller.should_not_receive :edit get :edit, :id => @post.id end it "should not render update action" do controller.should_not_receive :update put :update, :id => @post.id end it "should not render destroy action" do controller.should_not_receive :destroy delete :destroy, :id => @post.id end end end end