From 35ece9d65fa3bfd1be018ced36bac842d8b89d1a Mon Sep 17 00:00:00 2001 From: Jason Robinson Date: Sat, 4 Jan 2014 02:56:13 +0200 Subject: [PATCH] Instead of redirect on signup form validation, render new with submitted data. --- Changelog.md | 1 + app/controllers/registrations_controller.rb | 4 ++-- spec/controllers/registrations_controller_spec.rb | 11 +++++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Changelog.md b/Changelog.md index 82389339f..3caa3ee2e 100644 --- a/Changelog.md +++ b/Changelog.md @@ -64,6 +64,7 @@ For more details see https://wiki.diasporafoundation.org/Updating * Change "Show n more comments"-link, fix [#3119](https://github.com/diaspora/diaspora/issues/3119) * Specify Firefox version for Travis-CI [#4623](https://github.com/diaspora/diaspora/pull/4623) * Remove location when publisher is cleared by user +* On signup form errors, don't empty previous values by user, fix [#4663](https://github.com/diaspora/diaspora/issues/4663) ## Features * Add oEmbed content to the mobile view [#4343](https://github.com/diaspora/diaspora/pull/4353) diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index 57483d287..48c675275 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -6,7 +6,7 @@ class RegistrationsController < Devise::RegistrationsController before_filter :check_registrations_open_or_vaild_invite!, :check_valid_invite! layout ->(c) { request.format == :mobile ? "application" : "with_header" }, :only => [:new] - before_filter -> { @css_framework = :bootstrap }, only: [:new] + before_filter -> { @css_framework = :bootstrap }, only: [:new, :create] def create @user = User.build(user_params) @@ -22,7 +22,7 @@ class RegistrationsController < Devise::RegistrationsController flash[:error] = @user.errors.full_messages.join(" - ") Rails.logger.info("event=registration status=failure errors='#{@user.errors.full_messages.join(', ')}'") - redirect_to :back + render :action => 'new', :layout => 'with_header' end end diff --git a/spec/controllers/registrations_controller_spec.rb b/spec/controllers/registrations_controller_spec.rb index 31d060c3c..055c01ec5 100644 --- a/spec/controllers/registrations_controller_spec.rb +++ b/spec/controllers/registrations_controller_spec.rb @@ -53,6 +53,8 @@ describe RegistrationsController do end describe "#create" do + render_views + context "with valid parameters" do before do AppConfig.settings.enable_registrations = true @@ -107,9 +109,14 @@ describe RegistrationsController do flash[:error].should_not be_blank end - it "redirects back" do + it "renders new" do get :create, @invalid_params - response.should be_redirect + expect(response).to render_template("registrations/new") + end + + it "keeps invalid params in form" do + get :create, @invalid_params + expect(response.body).to match /jdoe@example.com/m end end end