Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rspec controller tests #64

Closed
caulfield opened this issue Oct 29, 2013 · 3 comments
Closed

Rspec controller tests #64

caulfield opened this issue Oct 29, 2013 · 3 comments

Comments

@caulfield
Copy link

Hi.
I'm using pundit(0.2.1) with rspec-rails(~2.14) in my rails 4 projects

It's great to use it with policy and view specs. But I confuse with controller and feature(capybara 2) types

When running tests I got errors:
undefined method 'authorize' for #<ArticlesController:0xb9b39fc>
# ./app/controllers/articles_controller.rb:6:in 'show'
# ./spec/features/authentication_spec.rb:6:in 'block (3 levels) in <top (required)>'
The same thing with my capybara feature.

But it works in development mode.

I found interesting hook that fixes controller group problem only. But I don't like it

# spec_helper.rb
config.before do
  if defined?(controller)
    controller.extend Pundit
  end
end

Thanks for any help and ideas

@thomasklemm
Copy link
Collaborator

Could you by chance have missed the include Pundit the Readme suggests to place in your ApplicationController?

class ApplicationController < ActionController::Base
  include Pundit
end

@caulfield
Copy link
Author

I included the module of course.

Main idea that all works good in development mode(when clicking).

@jnicklas
Copy link
Collaborator

I can't think of any reason Pundit would be included in your dev environment, and not in test, aside from maybe weird load-order/autoloading stuff? We don't really do anything fancy with module in Pundit, just plain old Ruby, so I don't think there is anything we can or should do about this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants