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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:46:37+00:00 2026-05-25T15:46:37+00:00

I am having problem with rspec testing controller the devise authentication. I have a

  • 0

I am having problem with rspec testing controller the devise authentication.

I have a following setup

I have included

config.include Devise::TestHelpers, :type => :controller

in my spec_helper.rb

In my merchants_controller_spec.rb

describe MerchantsController do
  before :each do
    @user = Factory(:user)
    @merchant = Factory(:merchant, :user_id => @user.id,:is_approved => false, :is_blacklisted => false)
    controller.stub!(:current_user).and_return(@user)
  end
  describe "GET index" do
    it "assigns all merchants as @merchants" do
      merchant = Factory(:merchant,:is_approved => true, :is_blacklisted => false)
      get :index
      assigns(:merchants).should eq([merchant])
    end
  end
end

My merchants_controller.rb

class MerchantsController < ApplicationController

  before_filter :authenticate_user!
  def index
    @merchants = Merchant.approved
    debugger
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @merchants }
    end
  end
end

I have a scope approved in merchant model

scope :approved, where(:is_approved => true, :is_blacklisted => false)

Now my problem is even though i stubbed current_user and returned @user as current_user, My merchants_controller index spec is failing. But if i comment out authenticate_user! then the spec passes,

without authenticate_user! the debugger of index action is caught but with authenticate_user! debugger is not caught.

I think there is problem in subbing current_user and i am not able to figure it out.

Help me out..

  • 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-25T15:46:37+00:00Added an answer on May 25, 2026 at 3:46 pm

    Have you read through the docs on github?:

    Devise includes some tests helpers for functional specs. To use them, you just need to include Devise::TestHelpers in your test class and use the sign_in and sign_out methods. Such methods have the same signature as in controllers:

    sign_in :user, @user   # sign_in(scope, resource)
    sign_in @user          # sign_in(resource)
    
    sign_out :user         # sign_out(scope)
    sign_out @user         # sign_out(resource)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

m having problem in passing parameter to controller action, i have done the following
I'm having problem with global variable in PHP. I have mysqli config file which
I am trying to test a controller with RSpec but am having a problem
I'm having problem in the following line: rd.PrintOptions.PaperSize = PaperSize.PaperFanfoldStdGerman; it throws an exception
We are having problem with the server migration. We have one application that are
I'm having problem when running my Windows Forms program. In the program, I have
I'm having problem with mbstring in my Apache2.2/Win7/PHP5.3 setup, though I think it's correctly
I'm having a problem with one of my tests in RSpec. The test in
I'm writing a rspec tests for my controller and i cannot find solution following
am having problem in Saving some data in my Java code. I have like

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.