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

  • Home
  • SEARCH
  • 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 5978013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:27:12+00:00 2026-05-22T21:27:12+00:00

I have a controller which makes a test: @first_login = (@user.sign_in_count == 1) And

  • 0

I have a controller which makes a test:

@first_login = (@user.sign_in_count == 1)

And I need to set it up with devise in the rspec spec:

I have tried the four ideas: In all of them user is created like: user = Factory(:member) [see below for factory]

  user.stubs(:sign_in_count).returns(1)
  sign_in user
  get 'index'

  user.sign_in_count = 1 
  sign_in user # here user.sign_in_count == 1
  get 'index'  # here user.sign_in_count == 1

  sign_in user
  sign_in user
  get 'index'

  sign_in user
  user.sign_in_count = 1 
  get 'index'

But every time in the controller, the devise specific user properties are zeroed/nil-ed out.

reset_password_token: nil, reset_password_sent_at: nil, 
remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, 
last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil

Any ideas why?

[specs/factories.rb – factory_girl]

Factory.define :member, :class => User do |c|
  c.password "a123456h"
  c.first_name "Jack"
  c.last_name "Lee"
  c.email "jxxxx@example.com"
  c.address_street "123 Main"
  c.address_city "Anytown"
  c.address_state "NV"
  c.address_zip "40455"
  c.address_country "USA"
  c.when_account_created 2.days.ago
  c.change_password_count 3
  c.forgot_password_count 2
  c.created_at 2.days.ago
  c.updated_at 10.hours.ago
end
  • 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-22T21:27:13+00:00Added an answer on May 22, 2026 at 9:27 pm

    Save the user.

    Seems like I have solved the problem with this in the spec:

      user = Factory(:customer)
      sign_in user
      user.sign_in_count = 1 
      user.save!
      get 'index'
    

    Not sure if this is intended in the way devise/warden’s current_user helper method is supposed to be used in the controller, but it works.

    I’ll leave it open if someone else has a better explanation.

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

Sidebar

Related Questions

I have a controller which has a method called history class UsersController < ApplicationController
I have a controller action which I would like to call another controller action.
I have a simple controller which returns images: public class ImageController : Controller {
I have a navigation controller which also has a table view. I want to
In my IB I have a navigation controller which has in it a view
in my MVC application I have a controller (ProjectController) which has an action (create).
I'm struggling here with a problem: I have a controller questions which has action
I have a table view controller which doesn't let me manually scroll to the
At the moment I have a jQuery do a POST to a Controller which
I have a controller called articles , which creates the articles model which gets

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.