Commit 48a235e1

mo k <mo@mokhan.ca>
2012-06-12 13:53:54
add some tests for registration controller. design would have been better if tests were actually done first.
1 parent 00d28d7
Changed files (1)
spec/controllers/registrations_controller_spec.rb
@@ -4,41 +4,56 @@ describe RegistrationsController do
   let(:sut) { RegistrationsController.new }
   let(:user){ fake }
 
-  context "when updating a users profile settings not including their password" do
-    it "should update their website" do
-      sut.stub(:current_user).and_return(user)
-
-      payload = {
-        :current_password => '',
-        :email => 'mo@mokhan.ca',
-        :facebook => 'mo',
-        :name =>'mo',
-        :password => '',
-        :password_confirmation => '',
-        :twitter => 'mocheen',
-        :website => 'http://mokhan.ca/',
+  describe "when updating a users settings not including their password" do
+    before(:each) do
+      @payload = {
+        :user => {
+          :current_password => '',
+          :email => 'mo@mokhan.ca',
+          :facebook => 'mo',
+          :name =>'mo',
+          :password => '',
+          :password_confirmation => '',
+          :twitter => 'mocheen',
+          :website => 'http://mokhan.ca/',
+          :interest_ids => []
+        }
       }
+      sut.stub(:current_user).and_return(user)
+      sut.stub(:params).and_return(@payload)
+      sut.stub(:update_without_password).and_return(true)
+      sut.stub(:render).and_return(true)
 
-      user.should have_received(:update_without_password,payload)
+      sut.update
     end
-
-    it "should not change their password" do
-
+    it "should update their website" do
+      user.should have_received(:update_without_password,@payload[:user])
     end
   end
-  context "when updating a users pasword" do
-    it "should update their password" do
+  describe "when updating a users pasword" do
+    before(:each) do
+      @payload = {
+        :user => {
+          :current_password => '',
+          :email => 'mo@mokhan.ca',
+          :facebook => 'mo',
+          :name =>'mo',
+          :password => 'secret',
+          :password_confirmation => 'secret',
+          :twitter => 'mocheen',
+          :website => 'http://mokhan.ca/',
+          :interest_ids => []
+        }
+      }
+      sut.stub(:current_user).and_return(user)
+      sut.stub(:params).and_return(@payload)
+      sut.stub(:update_with_password).and_return(true)
+      sut.stub(:render).and_return(true)
 
+      sut.update
+    end
+    it "should update their password" do
+      user.should have_received(:update_with_password,@payload[:user])
     end
   end
 end
-
-#HTTP GET /creations/ => creations#index
-#HTTP GET /creations/1 => creations#show
-#HTTP GET /creations/1/edit => creations#edit
-#HTTP PUT /creations/1 => creations#update
-#HTTP POST /creations/ => creations#create
-#HTTP DELETE /creations/1 => creations#destroy
-
-
-