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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:01:59+00:00 2026-05-26T11:01:59+00:00

There is a session variable used in controller for create. How to set the

  • 0

There is a session variable used in controller for create. How to set the session variable for rspec test?

Here is the method create in controller w/ session[eng_dh] :

  def create
    if session[:eng_dh] 

      @category = Category.new(params[:category], :as => :roles_new)    

      if @category.save

        redirect_to categories_path, :notice => 'Category was successfully created.'         
      else
        render :action => "new" 
      end
    else
      redirect_to categories_path, :notice =>"NO access to create category!"
    end
  end 

Here is the failing rspec code:

require 'spec_helper'

describe CategoriesController do
  before(:each) do
    #the following recognizes that there is a before filter without execution of it.
    controller.should_receive(:require_signin)
    controller.should_receive(:require_employee)
  end

  render_views

  describe "Post 'create'" do
    describe "success" do
      before(:each) do
        @category = Factory(:category)
        session[:eng_dh] = true  #THIS LINE CAUSED ERROR ( undefined method `stringify_keys' for "1":String) IN RSPEC TEST!!!
      end

      it "should create a category" do
        lambda do
          post :create, :category => @category
        end.should change(Category, :count).by(1)
      end

      it "should redirect to the category index page" do
        post :create, :category => @category
        response.should redirect_to(categories_path)
      end
    end

  end
end

Any solutions? Thanks.

  • 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-26T11:02:00+00:00Added an answer on May 26, 2026 at 11:02 am

    You should be able to set a session variable using that syntax.

    The undefined method 'stringify_keys' is not due to your setting of the session variable, rather it’s in the construction of the POST parameters from your @category object. The @category object has already been saved; post expects a hash.

    Properly sending the post params will fix it:

    @category = Factory.attributes_for(:category)
    

    Your test began to fail when you added the session line because your controller will only try to save when that session var is in place. Without the session var, create does nothing, but your Factory line has already saved the row. That’s a false “pass”.

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

Sidebar

Related Questions

If I set a session variable in Django, like: request.session[name] = name Is there
Is there a built-in way to know if a given session variable is a
IN PHP: Is there a way for the user to fake a session variable?
I have several pages in my application. I have used a session variable called
I am fairly new to web programming, I have mainly used java to create
Is there something like SESSION in Windows application? I want to store a few
Without routing, HttpContext.Current.Session is there so I know that the StateServer is working. When
Is there a way to get session management or security programatically in Jersey, e.g.
Is there any relationship between anonymous session ( where random identifier is generated for
There are two options when setting up your JBPM session. You can put your

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.