# This spec was generated by rspec-rails when you ran the scaffold generator. # It demonstrates how one might use RSpec to specify the controller code that # was generated by Rails when you ran the scaffold generator. # # It assumes that the implementation code is generated by the rails scaffold # generator. If you are using any extension libraries to generate different # controller code, this generated spec may or may not pass. # # It only uses APIs available in rails and/or rspec-rails. There are a number # of tools you can use to make these specs even more expressive, but we're # sticking to rails and rspec-rails APIs to keep things simple and stable. # # Compared to earlier versions of this generator, there is very limited use of # stubs and message expectations in this spec. Stubs are only used when there # is no simpler way to get a handle on the object needed for the example. # Message expectations are only used when there is no simpler way to specify # that an instance is receiving a specific message. describe CouchBlog::PostsController do # This should return the minimal set of attributes required to create a valid # CouchBlog::Post. As you add validations to CouchBlog::Post, be sure to # update the return value of this method accordingly. before :each do #sign_in @user @routes = CouchBlog::Engine.routes end describe "GET index" do it "assigns all posts as @posts, ordered descending by date up till today" do post1 = create :post, date: Date.today post2 = create :post, date: Date.today + 3.weeks post3 = create :post, date: Date.today + 2.weeks post4 = create :post, date: Date.today - 4.weeks post5 = create :post, date: Date.today - 2.weeks get :index assigns(:posts).should =~ [post1, post5, post4] end end describe "GET show" do it "assigns the requested post as @post" do post = create :post get :show, :id => post.id assigns(:post).should eq(post) end end describe "GET new" do it "should not allow new action" do ->{get :new}.should raise_error #ActionController::RoutingError end end describe "GET edit" do it "assigns the requested post as @post" do post = create :post ->{get :edit, id: post.id}.should raise_error #ActionController::RoutingError end end describe "POST create" do describe "with valid params" do it "creates a new CouchBlog::Post" do expect { post :create, :post => build(:post).attributes }.to raise_error #ActionController::RoutingError end end end describe "PUT update" do describe "with valid params" do it "should not allow an update request for a post on a non admin base" do post = create :post ->{ put :update, id: post.id, post: post.attributes }.should raise_error #ActionController::RoutingError end end end describe "DELETE destroy" do it "destroys the requested post" do post = create :post expect { delete :destroy, :id => post.id }.to raise_error #ActionController::RoutingError end end end