diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb index 88e20bb79..9d6530017 100644 --- a/app/controllers/users/registrations_controller.rb +++ b/app/controllers/users/registrations_controller.rb @@ -56,6 +56,7 @@ class Users::RegistrationsController < Devise::RegistrationsController private def sign_up_params + params[:user].delete(:redeemable_code) if params[:user].present? && params[:user][:redeemable_code].blank? params.require(:user).permit(:username, :email, :password, :password_confirmation, :captcha, :captcha_key, :terms_of_service, :locale, diff --git a/spec/features/registration_form_spec.rb b/spec/features/registration_form_spec.rb index 875e2b344..6439ac726 100644 --- a/spec/features/registration_form_spec.rb +++ b/spec/features/registration_form_spec.rb @@ -24,4 +24,24 @@ feature 'Registration form' do expect(page).to have_content I18n.t("devise_views.users.registrations.new.username_is_available") end + scenario 'do not save blank redeemable codes' do + visit new_user_registration_path(use_redeemable_code: 'true') + + fill_in 'user_username', with: "NewUserWithCode77" + fill_in 'user_email', with: "new@madrid.es" + fill_in 'user_password', with: "password" + fill_in 'user_password_confirmation', with: "password" + fill_in 'user_redeemable_code', with: " " + fill_in 'user_captcha', with: correct_captcha_text + check 'user_terms_of_service' + + click_button 'Register' + + expect(page).to have_content "Thank you for registering" + + new_user = User.last + expect(new_user.username).to eq("NewUserWithCode77") + expect(new_user.redeemable_code).to be_nil + end + end