Skip to content
Extraits de code Groupes Projets
Valider d3a62c7a rédigé par Sarah Mei's avatar Sarah Mei
Parcourir les fichiers

RegistrationsController#create deals with validation errors. Username, email,...

RegistrationsController#create deals with validation errors. Username, email, password now required on sign-up.
parent 1b672635
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -7,13 +7,14 @@ class RegistrationsController < Devise::RegistrationsController ...@@ -7,13 +7,14 @@ class RegistrationsController < Devise::RegistrationsController
begin begin
user = User.instantiate!(params[:user]) user = User.instantiate!(params[:user])
rescue MongoMapper::DocumentNotValid => e rescue MongoMapper::DocumentNotValid => e
user = nil
flash[:error] = e.message flash[:error] = e.message
redirect_to new_user_registration_path
end end
if user if user.save
flash[:notice] = I18n.t 'registrations.create.success' flash[:notice] = I18n.t 'registrations.create.success'
sign_in_and_redirect(:user, user) sign_in_and_redirect(:user, user)
else else
flash[:error] = user.errors.full_messages.join(', ')
redirect_to new_user_registration_path redirect_to new_user_registration_path
end end
end end
......
...@@ -24,6 +24,7 @@ class User ...@@ -24,6 +24,7 @@ class User
devise :invitable, :database_authenticatable, :registerable, devise :invitable, :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable :recoverable, :rememberable, :trackable, :validatable
key :username, :unique => true key :username, :unique => true
key :serialized_private_key, String key :serialized_private_key, String
...@@ -36,6 +37,8 @@ class User ...@@ -36,6 +37,8 @@ class User
key :visible_post_ids, Array key :visible_post_ids, Array
key :visible_person_ids, Array key :visible_person_ids, Array
validates_presence_of :username
one :person, :class_name => 'Person', :foreign_key => :owner_id one :person, :class_name => 'Person', :foreign_key => :owner_id
many :inviters, :in => :inviter_ids, :class_name => 'User' many :inviters, :in => :inviter_ids, :class_name => 'User'
......
...@@ -35,5 +35,22 @@ describe RegistrationsController do ...@@ -35,5 +35,22 @@ describe RegistrationsController do
response.should redirect_to root_path response.should redirect_to root_path
end end
end end
context "with invalid parameters" do
before do
@valid_params["user"].delete("username")
@invalid_params = @valid_params
end
it "does not create a user" do
lambda { get :create, @invalid_params }.should_not change(User, :count)
end
it "sets the flash error" do
get :create, @invalid_params
flash[:error].should_not be_blank
end
it "goes back to the form" do
get :create, @invalid_params
response.should redirect_to new_user_registration_path
end
end
end end
end end
...@@ -13,6 +13,10 @@ describe User do ...@@ -13,6 +13,10 @@ describe User do
let(:aspect3) { user3.aspect(:name => 'stuff') } let(:aspect3) { user3.aspect(:name => 'stuff') }
describe "validations" do describe "validations" do
it "requires a username" do
user = Factory.build(:user, :username => nil)
user.should_not be_valid
end
it "downcases the username" do it "downcases the username" do
user = Factory.build(:user, :username => "ALLUPPERCASE") user = Factory.build(:user, :username => "ALLUPPERCASE")
user.valid? user.valid?
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter