Skip to content

Instantly share code, notes, and snippets.

@nmerouze
Created December 3, 2008 23:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nmerouze/31749 to your computer and use it in GitHub Desktop.
Save nmerouze/31749 to your computer and use it in GitHub Desktop.
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe PostsController do
integrate_views
describe 'GET /index' do
before(:each) do
get :index
end
it "should be successful" do
response.should be_success
end
it "should render template 'index'" do
response.should render_template("index")
response.should have_tag("h1")
end
end
describe 'GET /index.xml' do
before(:each) do
request.env["HTTP_ACCEPT"] = "application/xml"
get :index
end
it "should be successful" do
response.should be_success
end
it "should render all posts as xml" do
response.body.should include('<?xml version="1.0" encoding="UTF-8"?>')
end
end
describe "POST /posts" do
describe "with valid parameters" do
before(:each) do
post :create, :post => { :title => 'Cool' }
end
it "should be redirected" do
response.should be_redirect
end
it "should redirect to the created post" do
response.should redirect_to(post_url(1))
end
end
describe "with invalid parameters" do
before(:each) do
post :create, :post => {}
end
it "should not be redirected" do
response.should_not be_redirect
end
it "should render template 'new'" do
response.should render_template("new")
response.should have_tag("h1")
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment