Skip to content

Instantly share code, notes, and snippets.

@jhchabran
Created September 2, 2009 13:45
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 jhchabran/179720 to your computer and use it in GitHub Desktop.
Save jhchabran/179720 to your computer and use it in GitHub Desktop.
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe BabysittersController do
integrate_views
context "when not authenticated" do
RestfulActions.for(BabysittersController) do |action|
it "should redirect to root path when accessing ##{action.name}" do
send action.method, action.name, action.args
response.should redirect_to(root_path)
end
end
end
context "when authenticated" do
before(:each) do
authenticate_user
end
describe "POST /babysitters/" do
context "when succesfully saved" do
before(:each) do
Babysitter.any_instance.stubs(:valid?).returns(true)
post :create
end
it "should redirect to babysitter_path" do
response.should redirect_to(babysitter_path(@user.babysitter.id))
end
it "should have a notice" do
flash[:notice].should_not be_nil
end
it "should assign a saved record to @babysitter" do
assigns[:babysitter].should_not be_a_new_record
end
end
context "when not succesfully saved" do
before(:each) do
Babysitter.any_instance.stubs(:valid?).returns(false)
post :create
end
it "should re-render new template" do
response.should render_template(:new)
end
it "should have a notice" do
flash[:notice].should_not be_nil
end
it "should assign a new record to @babysitter" do
assigns[:babysitter].should be_a_new_record
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment