Topic: Refactoring broke my application

Ive only just started learning ruby and rails which doesnt help. Ive been following the RailsSpace book (building a social networking site in ruby) and have nearly finished the refactoring process.

I have used the same code that is in the book but my app still does not work, so far i have just created abstraction layers to login, logout and check wether i am logged in throughout the site.

After doing all of this 2 of my tests now fail, the 1st that fails says that it was expecting XYZ page title but got nil. And the 2nd test just says that it couldnt login. I have used my browser to go to the app to confirm this and both tests are correct, there isnt a title and i cannot login (try to login but nothing happens after page reload, just same login form)

the 2 tests are:


def test_login_page
get :login
title = assigns(:title)
assert_equal "Log in to Rood N Norty", title
assert_response :success
assert_template "login"
assert_tag "form", :attributes => { :action => "/user/login",
:method => "post" }
assert_tag "input",
:attributes => { :name => "user[screen_name]",
:type => "text",
:size => User::SCREEN_NAME_SIZE,
:maxlength => User::SCREEN_NAME_MAX_LENGTH }
assert_tag "input",
:attributes => { :name => "user[password]",
:type => "password",
:size => User::PASSWORD_SIZE,
:maxlength => User::PASSWORD_MAX_LENGTH }
assert_tag "input", :attributes => { :type => "submit",
:value => "Login!" }
end

def test_login_success
try_to_login @valid_user
assert logged_in?
assert_equal @valid_user.id, session[:user_id]
assert_equal "User #{@valid_user.screen_name} logged in!", flash[:notice]
assert_response :redirect
assert_redirected_to :action => "index"
end


and the top part of the application layout view is:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
    <head>
        <title><%= @title %></title>
        <%= stylesheet_link_tag "site" %>
        <%= javascript_include_tag :defaults %>
    </head>

and the login part of the user controller is:

def login
      @title = "Log in to Rood N Norty"
      if request.post? and params[:user]
          @user = User.new(params[:user])
          user = User.find_by_screen_name_and_password(@user.screen_name,@user.password)
          if user
              user.login!(session)
              flash[:notice] = "User #{user.screen_name} logged in!"
              if (redirect_url = session[:protected_page])
                session[:protected_page] = nil
                redirect_to redirect_url
            else
                redirect_to :action => "index"
            end
          else
              # Dont show the password in the view
              @user.clear_password!
              flash[:notice] = "Invalid screen name/password combination"
          end
      end
  end







Could anybody please help??? Ive been trying for hours but havent come up with anything.

Thanks smile