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 6009101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:55:22+00:00 2026-05-23T01:55:22+00:00

How do I unit test a controller method that is called via a custom

  • 0

How do I unit test a controller method that is called via a custom route?

The relevant route is:

/auth/:provider/callback(.:format) {:controller=>"sessions", :action=>"create"}

On the spec for the SessionsController I can’t just use get :create since that route doesn’t exist. If I also use get /auth/facebook/callback/ it’ll tell me that No route matches {:controller=>"sessions", :action=>"/auth/facebook/callback"}.

It also seems like I can’t just use controller.create since #create accesses some keys from the request hash and it also redirects to another path, even if I set request.env[‘something’] in the spec file.

  • 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-23T01:55:22+00:00Added an answer on May 23, 2026 at 1:55 am

    A functional test should test the function of each action
    (given a set of parameters)

    Crucially, you should keep your functional tests decoupled from your routes.
    (else what’s the point in the routing abstraction anyway)

    In test::unit a functional test looks something like this

    test "#{action_name} - does something" do
      #{http_verb} :#{action_name}, :params => {:their => "values"}
      assert_response :#{expected_response}
    end
    

    Note, we don’t mention routing anywhere.

    So a real example for your create

    test "create - creates a session" do
      get :create, :provider => "your provider"
      assert_response :success
    end
    

    Rails will choke if it can’t match a route to this request.

    If this doesn’t work I suggest you check two things

    1. “get” is the correct http verb
    2. there are no other required parameters in your route (I can see :provider is one)

    If I’m doing anything wacky with routing,
    I normally add a separate test.

    test "create - routing" do
      assert_recognizes({
        :controller => "sessions",
        :action => "create",
        :provider => "yourProvider"
        }, "/auth/yourProvider/callback")
    end
    

    As long as this matches up with your action test
    all should be well.

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

Sidebar

Related Questions

I am trying to unit test a controller action that uses UpdateModel but I
What would a simple unit test look like to confirm that a certain controller
So I'm trying to unit-test a controller method. I'm using MSTest in VS 2010,
I would like to unit test the Initialize method of a Controller object. The
I'm trying to unit-test my controller (Yii framework). /** * @dataProvider provider */ public
I am running on Castle's trunk, and trying to unit-test a controller-action where validation
I'm using Test::Unit with shoulda to test a controller. Since I'm just testing the
I am trying to write a unit test for my one controller to verify
If unit-test names can become outdated over time and if you consider that the
I'm checking ModelState.IsValid in my controller action method that creates an Employee like this:

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.