chell
chell

Reputation: 7866

set session for object in Rspec integration test

I have the following in my controller:

def create
    @board = Board.find(session[:board])
    @greeting = @board.Greetings.build(params[:greeting])
    respond_to do |format|
      if @greeting.save
         format.js   { render :action => "success" }
      else
        format.js    { render :action => "failure" }
      end
    end
  end

In my rspec selenium test I want to set the session for the board. But it seems I can't

  describe "greeting creation" do

     before(:each) do
        @board = Factory(:board)
        session[:board] = @board.id
      end

THis gives the following error:

  Failure/Error: session[:board] = @board.id
     NoMethodError:
       undefined method `session' for nil:NilClass

How can I set the session so this test works?

Upvotes: 6

Views: 1531

Answers (2)

Ed Jones
Ed Jones

Reputation: 653

I had this issue and 'solved' it by using ApplicationController.session[:key].

But now I get the error TypeError: can't convert Symbol into Integer level_spec.rb:7:in[]='`

Upvotes: 1

Slick23
Slick23

Reputation: 5897

Are you sure the fixture is being called correctly? They're usually plural, like factories(:board).

You could try just setting it explicitly in the test to see if you can even set the session, instead of trying to load from a fixture. If that works, then you know the problem is in loading the fixture.

Upvotes: 0

Related Questions