Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect to previous page after profile edit #272

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions app/controllers/users/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ def create
end

# GET /resource/edit
# def edit
# super
# end
def edit
super
session[:return_to] ||= request.referer
end

# PUT /resource
# def update
# super
# end
def update
super
end

# DELETE /resource
# def destroy
Expand All @@ -61,7 +62,7 @@ def create

# If you have extra params to permit, append them to the sanitizer.
def configure_account_update_params
devise_parameter_sanitizer.permit(:account_update, keys: [ :name, :about, :profile_links, :location, :visibility, :pair_with_projects, :level_of_availability, skill_list: []])
devise_parameter_sanitizer.permit(:account_update, keys: [:name, :about, :profile_links, :location, :visibility, :pair_with_projects, :level_of_availability, skill_list: []])
end

# The path used after sign up.
Expand Down Expand Up @@ -89,4 +90,8 @@ def get_order_param
return 'created_at desc' if params[:sort_by] == 'latest'
return 'created_at asc' if params[:sort_by] == 'earliest'
end

def after_update_path_for(resource)
session.delete(:return_to)
end
end
24 changes: 24 additions & 0 deletions spec/controllers/users/registrations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,28 @@
end
end
end

describe 'PUT #update' do
let!(:user) { create(:user_complete_profile) }
let(:params) { { user: { id: user.id, email: '[email protected]' } } }

before do
sign_in user
session[:return_to] = projects_path
end

it 'we should be on projects path' do
put :update, params: params

user.reload
expect(user.email).to eq('[email protected]')
end

it 'should redirect to return_to cookie path' do
put :update, params: params

expect(response).to redirect_to projects_path
end

end
end
2 changes: 1 addition & 1 deletion spec/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
about { 'About' }
profile_links { 'Profile' }
location { 'location' }
skill_list { ['Analaytics'] }
skill_list { ['Analytics'] }
end

factory :project do
Expand Down