Commit 26d503ea
Changed files (2)
app
controllers
spec
controllers
app/controllers/registrations_controller.rb
@@ -5,12 +5,22 @@ class RegistrationsController < Devise::RegistrationsController
def update
@user = current_user
- if @user.update_without_password(params[:user])
- sign_in @user, :bypass => true
- flash[:notice]= 'Your settings have been updated successfully!'
- redirect_to profiles_mine_path
+ if params[:user][:password].blank?
+ if @user.update_without_password(params[:user])
+ sign_in @user, :bypass => true
+ flash[:notice]= 'Your settings have been updated successfully!'
+ redirect_to profiles_mine_path
+ else
+ render "edit"
+ end
else
- render "edit"
+ if @user.update_with_password(params[:user])
+ sign_in @user, :bypass => true
+ flash[:notice]= 'Your settings have been updated successfully!'
+ redirect_to profiles_mine_path
+ else
+ render "edit"
+ end
end
end
spec/controllers/registrations_controller_spec.rb
@@ -2,7 +2,37 @@
require 'spec_helper'
describe RegistrationsController do
- it "should blah" do
-
+ before (:each) do
+ request.env['warden'] = mock(Warden, :authenticate => user, :authenticate! => user)
+ end
+ let(:user){ FactoryGirl.build(:user) }
+
+ context "when updating a users website" do
+ it "should update their website" do
+ controller = RegistrationsController.new
+ #controller.update
+
+ blah = {
+ :current_password =>'',
+ :email => '',
+ :facebook => '',
+ :name =>'',
+ :password => '',
+ :password_confirmation => '',
+ :twitter => '',
+ :website => '',
+ }
+
+ user.should_receive[:update_without_password].with(blah)
+ put :update, :user => blah
+ end
+ it "should not change their password" do
+
+ end
+ end
+ context "when updating a users pasword" do
+ it "should update their password" do
+
+ end
end
end