Topic: 404 in test, but 200 in browser... please explain? Help?

Ok, this is your typical I joined the forum because I can't figure this out post - but I think I might be sticking around here a while.

Anyway - I'm having a problem with testing. I'm pretty new to testing and this one just bewilders me.

All other tests work and most of them are more complicated than this one. But this:

  test "get index" do
    get :index
    assert_response :ok
  end

Returns "Expected response to be a <:ok>, but was <404>"

But... the weird thing is if I go to that page in my browser, all sessions and cookies cleared, or under any other condition, the page succeeds without error. There are no redirects or anything.

What could cause a test to fail with a 404 but the page actually works?

For reference, here is my index action in the controller. I just really want to understand what's going on.

  before_filter :current_objects, :only => :index #needed for views and stuff
  before_filter :find_parameter, :only => [:index,:edit] #this does what it says, simple, works fine
 
  def index
    @options = Survey.options_for("#{@parameter}")
    if(session[:survey_id].present?)
      @current_object = Survey.find_by_id(session[:survey_id]) || Survey.new
    elsif
      if(params[:survey_group_id].present?)
        @current_object = Survey.new
        @current_object.survey_group_id = params[:survey_group_id]
      end
    else
      @current_object = Survey.new
    end

    # defaults: they are viewing charts for the first time and have no demos
    age_group = 1
    @gender = 'Male'

    # if viewing chart first time opt to select their demos first
    if session[:survey_id].present?
      if session[:survey_id][:age_group_id] != 0
        age_group = session[:survey_id][:age_group_id]
      end
      if session[:survey_id][:gender] != 0
        @gender = session[:survey_id][:gender]
      end
    end

    # if viewing chart demographics
    if params[:survey].present?
      if params[:survey][:age_group_id].present?
        age_group = params[:survey][:age_group_id]
      end
      if params[:survey][:age_group_id].present?
        @gender = params[:survey][:gender]
      end
    end

    @age_group = AgeGroup.find(age_group)
    puts @age_group.inspect

    if request.xhr?
      if params[:display] != 'page'
        render :partial => "chart_table_all"
      else
        render :partial => "parameter_results"
      end
    end
  end

Last edited by chriswible (2010-10-05 21:27:35)