Skip to content

Commit

Permalink
More user tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mbeckman committed Aug 1, 2014
1 parent 5df7fd3 commit bace2f5
Show file tree
Hide file tree
Showing 2 changed files with 147 additions and 55 deletions.
201 changes: 146 additions & 55 deletions spec/features/users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,89 +3,180 @@
describe 'Users' do
# subject { page }

# All users must sign in
# All users must sign in -- a user isn't a user until s/he signs in
# When a worker signs in, what does he see, what can he do? dashboard, what links?
# When a project administrator signs in, what does he see, what can do?
# When an administrator signs in, what does he see, what can he do?
# # When an admin creates new user, how does he initialize user password?


describe 'GET /users' do # this is users/index page? Only signed in admins can see it
context 'when administrator' do
# new start

describe 'when user is signed in' do # before user signs in, s/he is on /signin page
context 'when user is worker' do # worker tests valid for project admin and admin
before {
sign_in_administrator
visit users_path
sign_in_user
visit root_path
}
it 'should list users' do
expect(page).to have_selector('h1', text: 'Users')

it 'should have information and links' do
expect(page).to have_content("#{@user.email}")
expect(page).to have_link('Administration')
expect(page).to have_link('Account')
expect(page).to have_link('Sign out')
end
end

context 'when not an administrator' do # how would a non administrator get to this page?
before { sign_in_administrator }
it 'should redirect to dashboard and provide a notice'
end
end
context 'in order to edit self' do
before {
visit user_path(@user)
# click_link 'Account'
}

it 'should have information and links' do
expect(page).to have_css('h1', @user.id)
expect(page).to have_link('Edit account')
end

describe 'GET /users/:id' do # this is user show
context 'editing self' do
before {
# visit edit_user_path(@user)
click_link 'Edit account'
}

it 'should have information and links' do
# How to say what path this is edit_users_path(@user)?
# URI.parse(current_url).should == "users/#{@user}/edit"
# expect(current_url).to eq "/users/#{@user}/edit"

expect(page).to have_css('h1', 'Editing user')
expect(page).to have_selector('label', 'Password confirmation')
expect(page).to have_button('Update User') # where is submit button "Update User"?
end

it 'should let user edit their account information' do
fill_in 'Email', with: 'edit_user_modified@example.com'
fill_in 'Password', with: '1234ZZZ!'
fill_in 'Password confirmation', with: '1234ZZZ!'
click_button 'Update User'

expect(page).to have_css('p.alert.alert--success', 'Changes to your account information have been saved.')
end
end
end
end

context 'when logged in on dashboard' do
context 'when user is project administrator' do
before {
sign_in_user
visit user_path(@user)
sign_in_project_administrator
visit root_path
}

it 'should have information and actions' do
end
end

context 'when user is administrator' do
before {
sign_in_administrator # not a member of a project
visit root_path # Dashboard
}

# it 'should show my basic attributes' do
# expect(page).to have_link("Edit user information", href: user_information_path)
# expect(page).to have_link("View my statistics", href: user_statistics_path)
# # what projects I belong, currently logged into projects,
# end
it 'should have information and actions' do
expect(page).to have_link('Administration')
expect(page).to have_css('h1', 'Dashboard')
# expect(page).to have_css('h2', 'Projects')
# expect(page).to have_link('My Project')
end


context 'when editing self' do # this is either edit oneself or an admin editing someone else
before {
sign_in_user
visit edit_user_path(@user)
visit users_path # users index
}

it 'should let user edit their account information' do
txt = "Edit user #{@user.id}"
expect(page).to have_selector('h1', txt)
expect(page).to have_title("#{txt} | TaxonWorks")
fill_in 'Email', with: 'edit_user_modified@example.com'
fill_in 'Password', with: '1234ZZZ!'
fill_in 'Password confirmation', with: '1234ZZZ!'
click_button 'Update User'

expect(page).to have_css('p.alert.alert--success', 'Changes to your account information have been saved.')
it 'should list users' do
expect(page).to have_selector('h1', text: 'Users')
end


end
end

context 'when editing someone else' do
context 'and logged in as administrator' do
before {
sign_in_administrator
visit edit_user_path(@user)
}
it 'should render' do
end
end

context 'and not logged in as administrator' do
it 'should redirect to dashboard and provide a notice'
end
# describe 'GET /users' do # this is users/index page? Only signed in admins can see it
# # context 'when administrator' do
# # before {
# # sign_in_administrator
# # visit users_path
# # }
# # it 'should list users' do
# # expect(page).to have_selector('h1', text: 'Users')
# # expect(page).to have_content("#{@user.email}")
# # expect(page).to have_link('Administration')
# # end
# # end
#
# context 'when not an administrator' do # how would a non administrator get to this page?
# before { sign_in_administrator }
# it 'should redirect to dashboard and provide a notice'
# end
# end

context 'and logged in as a project_administrator' do
before {
}
it 'should redirect to dashboard and provide a notice'
end
end
# describe 'GET /users/:id' do # this is user show
#
# context 'when logged in on dashboard' do
# before {
# sign_in_user
# visit user_path(@user)
# }
#
# end
#
#
# # it 'should show my basic attributes' do
# # expect(page).to have_link("Edit user information", href: user_information_path)
# # expect(page).to have_link("View my statistics", href: user_statistics_path)
# # # what projects I belong, currently logged into projects,
# # end
#
#
# # context 'when editing self' do # this is either edit oneself or an admin editing someone else
# # before {
# # sign_in_user
# # visit edit_user_path(@user)
# # }
# #
# # it 'should let user edit their account information' do
# # txt = "Edit user #{@user.id}"
# # expect(page).to have_selector('h1', txt)
# # expect(page).to have_title("#{txt} | TaxonWorks")
# # fill_in 'Email', with: 'edit_user_modified@example.com'
# # fill_in 'Password', with: '1234ZZZ!'
# # fill_in 'Password confirmation', with: '1234ZZZ!'
# # click_button 'Update User'
# #
# # expect(page).to have_css('p.alert.alert--success', 'Changes to your account information have been saved.')
# #
# #
# # end
# end

# context 'when editing someone else' do
# context 'and logged in as administrator' do
# before {
# sign_in_administrator
# visit edit_user_path(@user)
# }
# it 'should render' do
# end
# end
#
# context 'and not logged in as administrator' do # where is this prompt?
# it 'should redirect to dashboard and provide a notice'
# end
#
# context 'and logged in as a project_administrator' do # where is this prompt?
# before {
# }
# it 'should redirect to dashboard and provide a notice'
# end
# end
end
end
1 change: 1 addition & 0 deletions spec/support/features/authentication_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
module Features
module AuthenticationHelpers

# Likely not used anywhere anymore
def sign_up_with(email, password, password_confirmation)
visit signup_path
fill_in 'Email', with: email
Expand Down

0 comments on commit bace2f5

Please sign in to comment.