railsware / rack_session_access

Rack middleware that provides access to rack.session environment
MIT License
257 stars 29 forks source link

No route matches [GET] "/rack_session/edit" #26

Closed mirkode closed 7 years ago

mirkode commented 7 years ago

Hey folks,

so to begin with, I investigated this issue and I do have

  config.middleware.use RackSessionAccess::Middleware 

in my /environments/test.rb, so this (being the only cause of this error I could find on-line) should not be the problem.

rake RAILS_ENV=test middleware spits out:

...
use Rack::ETag
use Warden::Manager
use RackSessionAccess::Middleware
run XXX::Application.routes

I have a simple login helper which sets the rack session as such: page.set_rack_session('warden.user.user.key' => User.serialize_into_session(user)) I pry'ed in and checked and the user is set. But still this didn't work and I always get the Capybara error:

Capybara::ElementNotFound:
       Unable to find field "data"

So I followed down this rabbit hole and the method where this error occurred is visiting the ::RackSessionAccess.edit_path (rack_session_access-0.1.1/lib/rack_session_access/capybara.rb). There it stops throwing the error mentioned above (No route matches [GET] "/rack_session/edit"). After consulting Google up and down I could not come up with any other solution then to finally address the issue here.

Can one of you guys help me please?

ayanko commented 7 years ago

That's weird. Where do you see this error about unknown routing? Which framework do you use? Rails? Which version?

You may add middleware temporary to config/environments/development.rb and check if page /rack_session/edit loads.

If it works for dev env but does not work for test then I guess you have some specific configuration.

mirkode commented 7 years ago

Hey @ayanko,

thanks for getting back to me so quickly. I am using Rails 5.1.2 and it indeed works when I add the middleware to the development.rb, so it might be something different with my test env.

That is really weird as I don't have a lot of configuring going on. I will update once I have found an answer.

Thanks again!

ayanko commented 7 years ago

Let me know when you detect the issue. I want to have this integration simple and easy. Actually people don't have issues with this gem. But probably I need to improve documentation in someway...

mirkode commented 7 years ago

Hey @ayanko,

so it was indeed my environment. The environment I would let my tests run in was explicitly set to "development". I figured it out after I added the middleware to the development.rb and let the specs run.

The gem itself was in the group :development, :test do.

Digging into the auto-generated rails_helper.rb I saw that it would use this line:

ENV['RAILS_ENV'] ||= 'test'

In my case I simply changed it to

ENV['RAILS_ENV'] = 'test'

to explicitly set my environment to test.

Even though it has nothing to do with the gem, I am adding this insight in case someone else is stumbling upon this issue as well.

Thanks a lot for your help and sorry about the fuzz!

ayanko commented 7 years ago

Happy using this cool gem 😉