require File.dirname(__FILE__) + '/../spec_helper' describe UnstaticSessionsController, "GET /unstatic_sessions/new" do before(:each) do @unstatic_session = mock(UnstaticSession) UnstaticSession.stub!(:new).and_return(@unstatic_session) end def do_get get :new end it "should be successfull" do do_get response.should be_success end it "should initialize a new unstatic_session" do UnstaticSession.should_receive(:new) do_get end it "should assign new unstatic_session for view" do do_get assigns[:unstatic_session].should == @unstatic_session end end describe UnstaticSessionsController, "POST /unstatic_sessions/create" do before(:each) do @unstatic_session = mock(UnstaticSession) @unstatic_session.stub!(:authorized?).and_return(true) UnstaticSession.stub!(:new).and_return(@unstatic_session) end def do_post post :create, :unstatic_session => { :password => "password" } end def post_with_valid_password @unstatic_session.should_receive(:authorized?).and_return(true) do_post end def post_with_invalid_password @unstatic_session.should_receive(:authorized?).and_return(false) do_post end it "should initialize a new unstatic_session with the password from params" do UnstaticSession.should_receive(:new).with("password" => "password").and_return(@unstatic_session) do_post end it "should assign the new unstatic_session for the view" do do_post assigns[:unstatic_session].should == @unstatic_session end it "should validate the submitted password" do post_with_valid_password end it "should set flash message if submitted password is valid" do post_with_valid_password flash[:notice].should_not be_nil flash[:notice].should_not be_empty end it "should save encrypted password to the session if valid" do post_with_valid_password session[:unstatic_password].should == UnstaticPassword.encrypt("password") end it "should redirect to / if submitted password is valid" do post_with_valid_password response.should redirect_to("/") end it "should re-render the 'new' form if password is invalid" do post_with_invalid_password response.should render_template("new") end end describe UnstaticSessionsController, "GET /unstatic_sessions/destroy" do def do_get request.session[:unstatic_password] = "password" get :destroy end it "should remove the password from the session" do do_get session[:unstatic_password].should be_nil end it "should set flash message" do do_get flash[:notice].should_not be_nil flash[:notice].should_not be_empty end it "should redirect to /" do do_get response.should redirect_to("/") end end