Skip to content

Commit

Permalink
Restructuring tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-bernhardt committed May 10, 2021
1 parent 30b1b0a commit d551d08
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 52 deletions.
1 change: 0 additions & 1 deletion app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def transfer_submitter
basic
can :create, Transfer
can :confirm, Transfer
can :read, Transfer, user_id: @user.id
end

# Library staff who process the thesis queue. They should be able to use the
Expand Down
140 changes: 89 additions & 51 deletions test/controllers/transfer_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,81 +1,45 @@
require 'test_helper'

class TransferControllerTest < ActionDispatch::IntegrationTest
test 'new redirects to login' do
test 'new redirects to login if not logged in' do
get '/transfer/new'
assert_response :redirect
assert_redirected_to '/users/auth/saml'
end

test 'transfer submitters can submit a transfer' do
sign_in users(:transfer_submitter)
get '/transfer/new'
assert_response :success
end

test 'thesis admins can submit a transfer' do
sign_in users(:thesis_admin)
get '/transfer/new'
assert_response :success
end

test 'login redirect when anonymous user tries to submit or view a transfer' do
get '/transfer/new'
assert_redirected_to '/users/auth/saml'
get "/transfer/#{transfers(:valid).id}"
assert_redirected_to '/users/auth/saml'
end

test 'basic user cannot submit or view a transfer' do
sign_in users(:basic)
get "/transfer/new"
assert_redirected_to '/'
follow_redirect!
assert_select 'div.alert', text: 'Not authorized.', count: 1

# ~~~~~~~~~~~~~~~~~~~~~~~~~~ new transfer form ~~~~~~~~~~~~~~~~~~~~~
test 'basic user cannot submit a transfer' do
sign_in users(:basic)
get "/transfer/#{transfers(:valid).id}"
assert_redirected_to '/'
follow_redirect!
assert_select 'div.alert', text: 'Not authorized.', count: 1
end

test 'processor cannot submit a transfer' do
sign_in users(:processor)
get "/transfer/new"
assert_redirected_to '/'
follow_redirect!
assert_select 'div.alert', text: 'Not authorized.', count: 1
end

test 'transfer submitter can view their own transfer' do
test 'transfer_submitter can submit a transfer' do
sign_in users(:transfer_submitter)
get "/transfer/#{transfers(:valid).id}"
get '/transfer/new'
assert_response :success
end

test 'transfer submitter cannot view transfers they did not submit' do
sign_in users(:transfer_submitter)
get "/transfer/#{transfers(:alsovalid).id}"
test 'thesis_processor cannot submit a transfer' do
sign_in users(:processor)
get "/transfer/new"
assert_redirected_to '/'
follow_redirect!
assert_select 'div.alert', text: 'Not authorized.', count: 1
end

test 'thesis admin can view any transfer' do
test 'thesis admins can submit a transfer' do
sign_in users(:thesis_admin)
get "/transfer/#{transfers(:valid).id}"
assert_response(:success)
get "/transfer/#{transfers(:alsovalid).id}"
assert_response(:success)
get '/transfer/new'
assert_response :success
end

test 'processor can view any transfer' do
sign_in users(:processor)
get "/transfer/#{transfers(:valid).id}"
assert_response(:success)
get "/transfer/#{transfers(:alsovalid).id}"
assert_response(:success)
test 'admins can submit a transfer' do
sign_in users(:admin)
get '/transfer/new'
assert_response :success
end

test 'redirect after successful submission' do
Expand Down Expand Up @@ -166,4 +130,78 @@ class TransferControllerTest < ActionDispatch::IntegrationTest
assert @response.body.include? transfer_path(t)
end
end

# ~~~~~~~~~~~~~~~~~~~~~~~~~~ transfer processing form ~~~~~~~~~~~~~~~~~~~~~
test 'transfer processing form exists' do
sign_in users(:admin)
get transfer_path(transfers(:valid))
assert_response :success
end

test 'anonymous users are redirected to sign in when loading transfer processing form' do
# Note that nobody signed in.
get transfer_path(transfers(:valid))
assert_response :redirect
assert_redirected_to '/users/auth/saml'
end

test 'basic users cannot see a transfer processing form' do
sign_in users(:basic)
get transfer_path(transfers(:valid))
assert_redirected_to '/'
follow_redirect!
assert_select 'div.alert', text: 'Not authorized.', count: 1
end

test 'transfer_submitter users cannot see any transfer processing form' do
sign_in users(:transfer_submitter)
# transfer_submitter submitted the "valid" transfer fixture.
get transfer_path(transfers(:valid))
assert_redirected_to '/'
follow_redirect!
assert_select 'div.alert', text: 'Not authorized.', count: 1

# another user submitted the "alsovalid" transfer fixture.
get transfer_path(transfers(:alsovalid))
assert_redirected_to '/'
follow_redirect!
assert_select 'div.alert', text: 'Not authorized.', count: 1
end

test 'thesis_processor users can see any transfer processing form' do
sign_in users(:processor)
get transfer_path(transfers(:valid))
assert_response :success
get transfer_path(transfers(:alsovalid))
assert_response :success
end

test 'thesis_admin users can see any transfer processing form' do
sign_in users(:thesis_admin)
get transfer_path(transfers(:valid))
assert_response :success
get transfer_path(transfers(:alsovalid))
assert_response :success
end

test 'admin users can see any transfer processing form' do
sign_in users(:admin)
get transfer_path(transfers(:valid))
assert_response :success
get transfer_path(transfers(:alsovalid))
assert_response :success
end

test 'submitting transfer processing form provides feedback' do
skip("This is not working yet")
sign_in users(:processor)
post transfer_files_path,
params: {
id: transfers(:valid).id,
transfer: {
file_ids: [1, 2]
}
}
assert_response :redirect
end
end

0 comments on commit d551d08

Please sign in to comment.