开发者

set session for object in Rspec integration test

开发者 https://www.devze.com 2023-03-17 10:31 出处:网络
I have the following in my controller: def create @board = Board.find(session[:board]) @greeting = @board.Greetings.build(params[:greeting])

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
     NoMe开发者_开发问答thodError:
       undefined method `session' for nil:NilClass

How can I set the session so this test works?


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号