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

Tests fail when Devise Confirmable module is used #13

Closed corroded closed 10 years ago

corroded commented 10 years ago

I tried running the tests and a lot of them failed. Is this expected or is there something wrong with my installation?

Steps to reproduce:

rails new rails-devise-pundit -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb

These are my answers to the interactive wizard (I liberally omitted the parts I think are not important - like the other choices etc)

question  Build a starter application?
          1)  Build a RailsApps example application...
   railsapps  Enter your selection: 1
    question  Starter apps for Rails 4.1. More to come.
          ...
          7)  rails-devise-pundit
          ...
   railsapps  Enter your selection: 7
              Get on the mailing list for Rails Composer news?
   railsapps  Enter your email address: n
      recipe  Running learn_rails recipe...
       setup  Your operating system is darwin11.4.2.
       setup  You are using Ruby version 1.9.3.
       setup  You are using Rails version 4.1.0.
    question  Web server for development?
          ....
          3)  Unicorn
          ....
       setup  Enter your selection: 3
    question  Web server for production?
          3)  Unicorn
       setup  Enter your selection: 3
    question  Database used in development?
          2)  PostgreSQL
       setup  Enter your selection: 2
    question  Template engine?
          2)  Haml
       setup  Enter your selection: 2
    question  Test framework?
          2)  RSpec with Capybara
       setup  Enter your selection: 2
       setup  Adding DatabaseCleaner, FactoryGirl, Faker, Launchy, Selenium
    question  Continuous testing?
          2)  Guard
       setup  Enter your selection: 2
    question  Front-end framework?
          4)  Zurb Foundation 5.0
       setup  Enter your selection: 4
       setup  The Devise 'forgot password' feature requires email.
    question  Add support for sending email?
          2)  Gmail
       setup  Enter your selection: 2
    question  Devise modules?
          2)  Devise with Confirmable module
       setup  Enter your selection: 2
    question  Use a form builder gem?
          2)  SimpleForm
       setup  Enter your selection: 2
      recipe  Running locale recipe...
      extras  Set a robots.txt file to ban spiders? (y/n) y
      extras  Create a GitHub repository? (y/n) n
      extras  Use or create a project-specific rvm gemset? (y/n) n
Your bundle is complete!
Gems in the group production were not installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.
    composer  Updating gem paths.
WARN: Unresolved specs during Gem::Specification.reset:
      json (>= 1.7.7, ~> 1.7)
      tzinfo (~> 1.1)
      minitest (~> 5.1)
      builder (~> 3.1)
      rake (>= 0.8.7)
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.
    composer  Stage Two (running recipe 'stage_two' callbacks).
    composer  importing html2haml conversion tool
       tests  recipe stage two
       tests  recipe installing RSpec
    generate    testing:configure rspec -f
         run  rm -rf test/ from "."
    generate  rspec:install
      create  .rspec
      create  spec
      create  spec/spec_helper.rb
      create  spec/rails_helper.rb
      insert  .rspec
      insert  .rspec
        gsub  .rspec
      insert  config/application.rb
      create  spec/support/capybara.rb
        gsub  spec/rails_helper.rb
      create  spec/support/database_cleaner.rb
      create  spec/support/factory_girl.rb
       tests  recipe initializing Guard
         run    bundle exec guard init from "."
02:32:05 - INFO - Writing new Guardfile to /Users/eumir/Projects/rails-devise-pundit/Guardfile
02:32:05 - INFO - bundler guard added to Guardfile, feel free to edit it
02:32:05 - INFO - rails guard added to Guardfile, feel free to edit it
02:32:05 - INFO - rspec guard added to Guardfile, feel free to edit it
         run    git add -A from "."
         run    git commit -qm "rails_apps_composer: testing framework" from "."
email
       email  recipe stage two
      insert    config/environments/development.rb
      insert    config/environments/production.rb
        gsub    config/environments/production.rb
      insert    config/environments/development.rb
      insert    config/environments/production.rb
         run    git add -A from "."
         run    git commit -qm "rails_apps_composer: set email accounts" from "."
       tests  recipe stage three
    generate    testing:configure devise -f
      create  spec/support/devise.rb
      create  spec/support/helpers/session_helpers.rb
      create  spec/support/helpers.rb
       force  spec/factories/users.rb
       force  spec/models/user_spec.rb
      create  spec/features/users/sign_in_spec.rb
      create  spec/features/users/sign_out_spec.rb
      create  spec/features/users/user_delete_spec.rb
      create  spec/features/users/user_edit_spec.rb
      create  spec/features/users/user_index_spec.rb
      create  spec/features/users/user_show_spec.rb
      create  spec/features/visitors/sign_up_spec.rb
      insert    spec/factories/users.rb
      insert    config/environments/test.rb
        gsub    spec/features/users/user_edit_spec.rb
        gsub    spec/features/visitors/sign_up_spec.rb
    generate    testing:configure pundit -f
       force  spec/factories/users.rb
       force  spec/features/users/user_index_spec.rb
      create  spec/policies/user_policy_spec.rb
      create  spec/support/pundit.rb
Your bundle is complete!
Gems in the group production were not installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.
         run  bundle exec spring binstub --all
* bin/rake: spring inserted
* bin/rails: spring inserted

After that, I cd into the directory and run rspec:

WARNING: Nokogiri was built against LibXML version 2.8.0, but has dynamically loaded 2.9.0

Sign in
.  user cannot sign in if not registered
F  user can sign in with valid credentials (FAILED - 1)
.  user cannot sign in with wrong email
.  user cannot sign in with wrong password

Sign out
F  user signs out successfully (FAILED - 2)

User delete
*  user can delete own account (PENDING: skip a slow test)

User edit
F  user changes email address (FAILED - 3)
F  user cannot cannot edit another user's profile (FAILED - 4)

User index page
F  user sees own email address (FAILED - 5)

User profile page
F  user sees own profile (FAILED - 6)
F  user cannot see another user's profile (FAILED - 7)

Home page
.  visit the home page

Navigation links
.  view navigation links

Sign Up
.  visitor can sign up with valid email address and password
.  visitor cannot sign up with invalid email address
.  visitor cannot sign up without password
.  visitor cannot sign up with a short password
.  visitor cannot sign up without password confirmation
.  visitor cannot sign up with mismatched password and confirmation

User
.  should respond to #email
.  #email returns a string

UserPolicy
  index?
.    denies access if not an admin
.    allows access for an admin
  show?
.    prevents other users from seeing your profile
.    allows you to see your own profile
.    allows an admin to see any profile
  update?
.    prevents updates if not an admin
.    allows an admin to make updates
  destroy?
.    prevents deleting yourself
.    allows an admin to delete any user

Pending:
  User delete user can delete own account
    # skip a slow test
    # ./spec/features/users/user_delete_spec.rb:18

Pending:
  User delete user can delete own account
    # skip a slow test
    # ./spec/features/users/user_delete_spec.rb:18

Failures:

  1) Sign in user can sign in with valid credentials
     Failure/Error: expect(page).to have_content 'Signed in successfully.'
       expected to find text "Signed in successfully." in "Home Menu Sign in Sign up You have to confirm your account before continuing. × Sign in Sign up Email Forgot password? Password Remember me"
     # ./spec/features/users/sign_in_spec.rb:24:in `block (2 levels) in <top (required)>'

  2) Sign out user signs out successfully
     Failure/Error: expect(page).to have_content 'Signed in successfully.'
       expected to find text "Signed in successfully." in "Home Menu Sign in Sign up You have to confirm your account before continuing. × Sign in Sign up Email Forgot password? Password Remember me"
     # ./spec/features/users/sign_out_spec.rb:14:in `block (2 levels) in <top (required)>'

  3) User edit user changes email address
     Failure/Error: visit edit_user_registration_path(user)
     ArgumentError:
       uncaught throw :warden
     # ./spec/features/users/user_edit_spec.rb:21:in `block (2 levels) in <top (required)>'

  4) User edit user cannot cannot edit another user's profile
     Failure/Error: visit edit_user_registration_path(other)
     ArgumentError:
       uncaught throw :warden
     # ./spec/features/users/user_edit_spec.rb:36:in `block (2 levels) in <top (required)>'

  5) User index page user sees own email address
     Failure/Error: visit users_path
     ArgumentError:
       uncaught throw :warden
     # ./spec/features/users/user_index_spec.rb:21:in `block (2 levels) in <top (required)>'

  6) User profile page user sees own profile
     Failure/Error: visit user_path(user)
     ArgumentError:
       uncaught throw :warden
     # ./spec/features/users/user_show_spec.rb:21:in `block (2 levels) in <top (required)>'

  7) User profile page user cannot see another user's profile
     Failure/Error: visit user_path(other)
     ArgumentError:
       uncaught throw :warden
     # ./spec/features/users/user_show_spec.rb:35:in `block (2 levels) in <top (required)>'

Failures:

  1) Sign in user can sign in with valid credentials
     Failure/Error: expect(page).to have_content 'Signed in successfully.'
       expected to find text "Signed in successfully." in "Home Menu Sign in Sign up You have to confirm your account before continuing. × Sign in Sign up Email Forgot password? Password Remember me"
     # ./spec/features/users/sign_in_spec.rb:24:in `block (2 levels) in <top (required)>'

  2) Sign out user signs out successfully
     Failure/Error: expect(page).to have_content 'Signed in successfully.'
       expected to find text "Signed in successfully." in "Home Menu Sign in Sign up You have to confirm your account before continuing. × Sign in Sign up Email Forgot password? Password Remember me"
     # ./spec/features/users/sign_out_spec.rb:14:in `block (2 levels) in <top (required)>'

  3) User edit user changes email address
     Failure/Error: visit edit_user_registration_path(user)
     ArgumentError:
       uncaught throw :warden
     # ./spec/features/users/user_edit_spec.rb:21:in `block (2 levels) in <top (required)>'

  4) User edit user cannot cannot edit another user's profile
     Failure/Error: visit edit_user_registration_path(other)
     ArgumentError:
       uncaught throw :warden
     # ./spec/features/users/user_edit_spec.rb:36:in `block (2 levels) in <top (required)>'

  5) User index page user sees own email address
     Failure/Error: visit users_path
     ArgumentError:
       uncaught throw :warden
     # ./spec/features/users/user_index_spec.rb:21:in `block (2 levels) in <top (required)>'

  6) User profile page user sees own profile
     Failure/Error: visit user_path(user)
     ArgumentError:
       uncaught throw :warden
     # ./spec/features/users/user_show_spec.rb:21:in `block (2 levels) in <top (required)>'

  7) User profile page user cannot see another user's profile
     Failure/Error: visit user_path(other)
     ArgumentError:
       uncaught throw :warden
     # ./spec/features/users/user_show_spec.rb:35:in `block (2 levels) in <top (required)>'

Deprecation Warnings:

Filtering by an `:example_group` subhash is deprecated. Use the subhash to filter directly instead. Called from /Users/eumir/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/pundit-0.2.3/lib/pundit/rspec.rb:49:in `block in <top (required)>'.

`failure_message_for_should_not` is deprecated. Use `failure_message_when_negated` instead. Called from /Users/eumir/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/pundit-0.2.3/lib/pundit/rspec.rb:19:in `block in <module:Matchers>'.

`failure_message_for_should` is deprecated. Use `failure_message` instead. Called from /Users/eumir/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/pundit-0.2.3/lib/pundit/rspec.rb:15:in `block in <module:Matchers>'.

`match_for_should_not` is deprecated. Use `match_when_negated` instead. Called from /Users/eumir/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/pundit-0.2.3/lib/pundit/rspec.rb:11:in `block in <module:Matchers>'.

`match_for_should` is deprecated. Use `match` instead. Called from /Users/eumir/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/pundit-0.2.3/lib/pundit/rspec.rb:7:in `block in <module:Matchers>'.

If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.

5 deprecation warnings total

Finished in 23.68 seconds (files took 16.75 seconds to load)
30 examples, 7 failures, 1 pending

Failed examples:

rspec ./spec/features/users/sign_in_spec.rb:21 # Sign in user can sign in with valid credentials
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_edit_spec.rb:32 # User edit user cannot cannot edit another user's profile
rspec ./spec/features/users/user_index_spec.rb:18 # User index page user sees own email address
rspec ./spec/features/users/user_show_spec.rb:18 # User profile page user sees own profile
rspec ./spec/features/users/user_show_spec.rb:30 # User profile page user cannot see another user's profile

Finished in 23.68 seconds (files took 16.75 seconds to load)
30 examples, 7 failures, 1 pending

Failed examples:

rspec ./spec/features/users/sign_in_spec.rb:21 # Sign in user can sign in with valid credentials
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_edit_spec.rb:32 # User edit user cannot cannot edit another user's profile
rspec ./spec/features/users/user_index_spec.rb:18 # User index page user sees own email address
rspec ./spec/features/users/user_show_spec.rb:18 # User profile page user sees own profile
rspec ./spec/features/users/user_show_spec.rb:30 # User profile page user cannot see another user's profile
DanielKehoe commented 10 years ago

You've selected the Devise Confirmable module. The tests were written for Devise with default modules.

It'd be great if you could provide the code for tests with the Confirmable module so we can avoid this problem in the future.

lyonsv commented 10 years ago

As per the issue I created at the below link, I'm having the same test failures with the default modules.

https://github.com/RailsApps/rails-devise-pundit/issues/14

robwise commented 10 years ago

With the confirmable module option chosen using RailsComposer, I'm not getting these errors. Are you guys sure you are using a completely fresh version of RailsComposer? Those specs aren't using documentation formatting, which I know the RailsComposer puts into the .rspec file by default.

Anyway, besides the deprecation warnings, which I think are being solved over at the Pundit repo, all I'm getting is a single error regarding the edit user spec due to a simple matching inconsistency. The test reads "Your account has been updated successfully," but should be "You updated your account successfully,"

I have forked the RailsAppsComposer and made what I believe is the proper fix, but I'm a beginner and am not really sure how to make this into a gem and regression test it to make sure I made the right change. I have made the above change, of course, in my generated example app's spec file manually and confirmed that it passes the test.

robwise commented 10 years ago

Confirmed that updating Gemfile to switch gem pundit to: gem 'pundit', :git => 'https://github.com/elabs/pundit.git' fixes the deprecation warnings. Obviously this is pulling the latest commits off of the pundit repo, and therefore is not necessarily a very stable thing to do, but hopefully they will push a new release soon.

DanielKehoe commented 10 years ago

@noelrappin fixed the RSpec deprecation warnings for Pundit with https://github.com/elabs/pundit/pull/156. It'd be nice to see a release of the updated Pundit (hey guys!).

robwise commented 10 years ago

The 'user can delete own account' example also needs to be changed to: expect(page).to have_content 'Bye! Your account has been successfully cancelled. We hope to see you again soon.'

DanielKehoe commented 10 years ago

@robwise I've made the fix to the tests per your suggestion. Thanks!