Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 576781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:05:01+00:00 2026-05-13T14:05:01+00:00

I’m new to testing, and I’m having some difficulties trying to run a functional

  • 0

I’m new to testing, and I’m having some difficulties trying to run a functional test.

I’ve a messages_controller, and a user_controller here.
in the routes, I’ve defined that the users resources has_many message resources.

Now I’m trying to run a simple test in the messages controller:

def test_index
  get :index, { :user_id => 1 }
  assert_template 'index'
end

But get a routing error from rails, that he cant find a route to messages. I don’t want to include a route to messages only because of the tests. How can I tell the test that he must access from the /users/messages url?

the full routes.rb:

ActionController::Routing::Routes.draw do |map|

  map.login  'login',   :controller => :user_sessions, :action => :new
  map.logout 'logout',  :controller => :user_sessions, :action => :destroy
  map.signin 'signin',  :controller => :users,         :action => :new

  map.connect 'search/:action/:word', :controller => :search
  map.connect 'search/:word',         :controller => :search, :action => :index

  map.resources :forums do |forums| 
    forums.resources :forum_posts, :collection => {:preview => :post }, :as => :posts do |post|
      post.resources :forum_posts, :as => :reply
      post.resources :reports
    end
  end

  map.resources :newsitems, :as => :news do |news|
    news.resources :comments do |comment|
      comment.resources :reports
    end
  end

  map.resource :user_sessions
  map.resources :users, 
                :as => :profiles,
                :controller => :profiles,
                :has_many   => [ :messages ]
  map.resource :profiles
  map.resource :me,            
               :controller => :me,
               :has_many   => [ :messages ]


  map.resources :comments, :has_many => [ :reports ]
  map.resources :forum_posts, :has_many => [ :reports ]
  map.resources :reports

  map.home  '/', :controller => :home
  map.root  :controller => :home

  map.namespace :admin do |admin|
    admin.namespace :forum do |forum|
      forum.resources :categories
      forum.resources :posts
      forum.resources :forums
      forum.root      :controller => :home
    end
    admin.resources :notices
    admin.resources :users
    admin.workflow  'workflow/:action', :controller => :workflow
    admin.resources :newsitems
    admin.resources :reports
    admin.resources :comments    
    admin.root :controller => :home
  end

  map.connect ':controller/:action/:id'
  map.connect ':controller/:action/:id.:format'
end

UPDATE

I’ve noticed that every functional test get a routing error. Even the simpliests ones like newsitem. I’ve no idea why.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T14:05:01+00:00Added an answer on May 13, 2026 at 2:05 pm

    I recreated your scenario in a blank rails app with the routing code and and test you specified, and it worked without a problem, as it should. I’ll paste my controller code here since that’s the only part you left out:

    class MessagesController < ApplicationController
      def index
        @messages = User.find(params[:user_id]).messages
      end
    end
    

    If yours is doing basically the same thing, then a routing issue could be caused by a conflict in your routing file, which is what I suspect might be the case. Can you post it? FYI, I wrote an article on testing your routes, and that would be a very good idea because it would catch routing errors early, before they interfere with controllers.

    Anyway, if you can post your routes I can take a look.

    UPDATE: After looking at your routes, there are a couple conflicts. You can have messages as a sub-resource of more than one other resource, but in your messages controller you’re going to have to account for the possibility of either a params[:me_id] or params[:profile_id]. It looks like they’re both really the user model underneath, so it can be as simple as:

    @user = User.find(params[:me_id] || params[:profile_id])
    

    and you’ll probably want to abstract that out into a method you call with before_filter.

    The other issue is that you have two overlapping profiles routes, and I’m not sure why. I don’t think it’s a routing error in the test, because tests bypass the routing engine anyway. I think it’s an error in the index view, because it probably contains links to messages with improperly formatted urls. If you have a link to a message, for instance, and you have a @profile object, then you’ll need to call them like this:

    <%= link_to message.name, profile_message_path(@profile, @message) %>
    

    However, if you’re using non-nested paths like message_path(@message), it will fail because there are no non-nested message routes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.