Skip to content

Commit

Permalink
pass specs to allow user to update associated positions
Browse files Browse the repository at this point in the history
  • Loading branch information
christinalcole committed Nov 4, 2017
1 parent 323f603 commit 1973ab3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 29 deletions.
10 changes: 10 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,15 @@ def edit
end

def update
if current_user.update(user_params)
redirect_to user_positions_path(current_user)
else
render 'edit'
end
end

private
def user_params
params.require(:user).permit(position_ids: [])
end
end
4 changes: 1 addition & 3 deletions app/views/users/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ users/positions#edit <br></br>
<h2>Update positions on your profile:</h2>

<%= form_for current_user do |f| %>
<%= f.collection_check_boxes :position_ids, Position.all, :id, :name %>


<%= f.collection_check_boxes(:position_ids, Position.all, :id, :name) %>
<%= f.submit "Update Position(s)" %>
<% end %>
37 changes: 24 additions & 13 deletions spec/features/position_features_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
expect(page).to have_link("Manage Positions")
end

scenario 'there is no link to add position(s) if a user profile already has positions'

scenario 'there is a form to update positions associated with user profile' do
user = create(:user)
signin(user.email, user.password)
Expand All @@ -40,19 +38,32 @@
expect(page).to have_content(position2.name)
end

scenario 'the form should display positions already listed in the user profile'
scenario 'the form should indicate which position(s) are already listed in the user profile' do
position1 = create(:position)
position2 = create(:position)
user = create(:user)
user.positions << position1

signin(user.email, user.password)
visit edit_user_path(user.id)

expect(page).to have_field("user_position_ids_#{position1.id}", checked: true)
expect(page).to have_field("user_position_ids_#{position2.id}", checked: false)
end

scenario 'the list of positions for a user should update after the form is submitted' do
# position1 = create(:position)
# position2 = create(:position)
# user = create(:user)
# signin(user.email, user.password)
# visit new_user_position_path(user.id)
#
# page.check(position1.name)
# click_button("Create Position")
#
# expect(user.positions).to include(position1)
position1 = create(:position)
position2 = create(:position)
user = create(:user)
user.positions << position1

signin(user.email, user.password)
visit edit_user_path(user.id)

page.check(position2.name)
click_button("Update Position(s)")

expect(user.positions).to include(position1, position2)
end
end
end
13 changes: 0 additions & 13 deletions spec/features/users/user_features_spec.rb

This file was deleted.

0 comments on commit 1973ab3

Please sign in to comment.