RailsApps / rails-devise-pundit

Rails 5.0 starter app with Devise for authentication and Pundit for authorization.
http://railsapps.github.io/rails-devise-pundit/
483 stars 156 forks source link

include Pundit not included in Application Controller #14

Closed lyonsv closed 10 years ago

lyonsv commented 10 years ago

I'll be looking into this later today, but it seems that you've removed include Pundit from the Application Controller. I noticed this after getting an error on the authorize method.

DanielKehoe commented 10 years ago

I've moved the functionality to the file config/initializers/pundit.rb. It extends the ApplicationController. Some developers like to add the code to the Application controller file. Instead, to segregate our Pundit-specific code, we use an initializer file. There's a detailed explanation in my Pundit Tutorial but let me know if you need more information.

Can you say more about the error you got?

lyonsv commented 10 years ago

I see that you've moved that into an initializer now!

I was getting an error stating authorize is an undefined method on show in the users_controller. However, that was after some editing of of the app that I completed.

I've reverted to my first commit, which was a fresh app composer setup of rails-devise-pundit. On that, I'm getting a lot of errors from Rspec which I've pasted below. When I click through the app, after sign up there's a redirect loop error from the browser. When I type directly into the URL bar after signing up, it will only allow me to access root - /users/{sign_out, 1, 2, etc} all redirect to root.

I'll need to fix this over the next few hours for my own app, but I suspect there's an issue with the composer gem for pundit at the moment...but I might be wrong.


Finished in 1.15 seconds (files took 3.32 seconds to load)
30 examples, 9 failures, 1 pending

Failed examples:

rspec ./spec/features/users/sign_in_spec.rb:11 # Sign in user cannot sign in if not registered
rspec ./spec/features/users/sign_in_spec.rb:21 # Sign in user can sign in with valid credentials
rspec ./spec/features/users/sign_in_spec.rb:32 # Sign in user cannot sign in with wrong email
rspec ./spec/features/users/sign_in_spec.rb:43 # Sign in user cannot sign in with wrong password
rspec ./spec/features/users/sign_out_spec.rb:11 # Sign out user signs out successfully
rspec ./spec/features/users/user_edit_spec.rb:18 # User edit user changes email address
rspec ./spec/features/users/user_show_spec.rb:30 # User profile page user cannot see another user's profile
rspec ./spec/features/visitors/navigation_spec.rb:11 # Navigation links view navigation links
rspec ./spec/features/visitors/sign_up_spec.rb:11 # Sign Up visitor can sign up with valid email address and password

Finished in 1.15 seconds (files took 3.32 seconds to load)
30 examples, 9 failures, 1 pending