Rspec Failing Because Session Is Not Present

bug

#1

Hi,

first of all, let me congrat for the very cool idea Jets is.

After that, I would like to present an issue here that I am facing when trying to test my “hello-jets” app.
I did non want to open an issue on the Github page because I want not sure that was the right place.

I just want to set up a posts#index route:

jets generate controller posts index --no-helper

Then I add the controller spec:

# spec/controllers/posts_controller_spec.rb

describe PostsController, type: :controller do
  it "index returns a success response" do
    get '/posts'
    expect(response.status).to eq 200
  end
end

Then I just run:

bundle exec rspec

Here the error:

1) PostsController index returns a success response
     Failure/Error: <%= csrf_meta_tags %>

     ActionView::Template::Error:
       undefined method `[]=' for nil:NilClass

It turns out that the issue is session beeing nil in the url_helper.rb

#lib/jets/overrides/rails/url_helper.rb:70

def masked_authenticity_token
  @masked_authenticity_token ||= SecureRandom.hex(32)
  # session is nil !!!!
  session[:authenticity_token] = @masked_authenticity_token
end

The nice thing is that when running jets server the issue is not present and the index route renders successfuly.

This makes me thing that the issue is somewhere in how the spec set up the request, response.
Indeed the request is not having any session instantiated.

Can anyone replicate the issue ?


#2

Fixed in #331 Released in v2.0.3


#3

Thanks…

I checked your changes.
To be honest i am not sure i get how they fix the issue, but they fix it !!

:slight_smile: