Skip to content

Commit

Permalink
Ensure login and logout behavior are available
Browse files Browse the repository at this point in the history
Check that a user can log in
Check that a user can log out
  • Loading branch information
Tom Johnson authored and bess committed Jan 2, 2018
1 parent 143570a commit 2a2d000
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
6 changes: 4 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
request.env['warden'].authenticate?
end

# This needs to be firt, but *before* admin and user contrained routes are configured
devise_for :users

constraints admin_constraint do
root to: 'hyrax/dashboard#show'

Expand Down Expand Up @@ -83,6 +86,7 @@
end

constraints authenticated_constraint do
resources :users
# Mount Engines
mount Blacklight::Engine => '/'
mount Hydra::RoleManagement::Engine => '/'
Expand All @@ -109,8 +113,6 @@
end

# Unauthenticated users should only be able to reach the /contribute controller and the log in page
devise_for :users

resources :contribute, as: 'contributions', controller: :contribute, only: [:index, :new, :create, :redirect] do
collection do
get 'license'
Expand Down
36 changes: 36 additions & 0 deletions spec/features/login_out_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require 'rails_helper'
include Warden::Test::Helpers

RSpec.feature 'login and logout', :clean do
let(:admin) { create(:admin) }

context 'logging in' do
scenario 'provide a login and password' do
u = User.create(email: 'admin@example.org', display_name: 'Admin, Example', password: 'password')
u.add_role('admin')
u.save
visit '/dashboard'
expect(current_path).to eq "/contribute"
find('a.btn-primary').click
expect(current_path).to eq "/users/sign_in"
fill_in 'user_email', with: u.user_key
fill_in 'user_password', with: u.password
click_on 'Log in'
expect(current_path).to eq "/dashboard"
end
end

context 'when logged in' do
before { login_as admin }

scenario 'logging out' do
visit '/dashboard'

within '#user_utility_links' do
click_on 'Logout'
end

expect(page).to have_content 'Login'
end
end
end

0 comments on commit 2a2d000

Please sign in to comment.