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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:39:14+00:00 2026-05-24T19:39:14+00:00

I am using signed cookies to maintain my user across pages, pretty much implemented

  • 0

I am using signed cookies to maintain my user across pages, pretty much implemented as here.

I use two methods, sign_in(account) and sign_out to manipulate my cookies, creating or destroying them as you would expect …

module SessionsHelper
  def sign_in account
    cookies.signed[:auth_account] = {
      :expires => 1.week.from_now,
      :value => [account.id, account.hash]
    }
  end

  def sign_out
    cookies.delete(:auth_account)
  end
end

However, when trying to use this method, or the authenticate method that matches it in the ApplicationController from the functional tests, I get a NoMethodError:

NoMethodError: undefined method `signed’ for {}:ActiveSupport::HashWithIndifferentAccess

I realise from this and this that this is an issue with the way cookies are defined differently in the test case, but I can’t get any of these solutions to work. For completeness, an example test that fails with the above error:

require 'test_helper'

class AccountsControllerTest < ActionController::TestCase
  include SessionsHelper

  setup do
    # We need to fake authentication by manually
    # assigning an account to the sign_in process
    sign_in accounts(:ia)

    @account = accounts(:ia)
  end

  test "should 403 on index if unauthenticated" do
    sign_out

    get :index
    assert_response :forbidden
  end

  test "should 200 on index if authenticated" do
    get :index
    assert_response :success
  end
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-24T19:39:15+00:00Added an answer on May 24, 2026 at 7:39 pm

    You can’t set cookies in your test with the cookies variable like you do in your controller.
    The cookies variable in your tests is use for read cookies after doing requests call (get/post…) and not for writing

    In order to spoof login within your tests you should set cookies via @request.cookies[:auth]

    you can put the following method in your test_helper and use it in all your tests

    def signin user
      @request.cookies[:auth] = user.auth
    end
    

    and in your tests

    test "get dashboard if logged in" do
      signin @user
      get :index
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to implement Gmail's stay signed in option ? Is it using cookies ?
I'm using signed cookies in Rails 3 to enable a remember-me feature in an
I signed up for the iPhone Developer Program (now awaiting approval) using a new
When using simple request to post to Twitter the messages are signed with sent
Using C++, an int gets converted from "signed" to "unsigned". Can I convert this
How do I create a self-signed certificate for code signing using the Windows SDK?
Whats the rationale for using signed numbers as indexes in .Net? In Python, you
I am using signed to unsigned byte(int8_t) cast to pack byts. uint32_t(uint8_t(byte)) << n
I'm building a .net web app and using Forms authentication with cookies to remember
Imagine the following scenario. User visits a site A (ASP.NET), authenticates using ADFS and

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.