Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 245
chell Avatar asked Jul 06 '11 11:07

chell


1 Answers

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[]='`

like image 159
Ed Jones Avatar answered Oct 26 '22 05:10

Ed Jones